jani Tue, 19 Jan 2010 12:03:07 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=293724
Log: - WS + CS fixes Changed paths: U php/php-src/branches/PHP_5_2/main/streams/cast.c U php/php-src/branches/PHP_5_3/main/streams/cast.c U php/php-src/trunk/main/streams/cast.c
Modified: php/php-src/branches/PHP_5_2/main/streams/cast.c =================================================================== --- php/php-src/branches/PHP_5_2/main/streams/cast.c 2010-01-19 11:44:43 UTC (rev 293723) +++ php/php-src/branches/PHP_5_2/main/streams/cast.c 2010-01-19 12:03:07 UTC (rev 293724) @@ -55,6 +55,7 @@ { int ret; TSRMLS_FETCH(); + ret = php_stream_read((php_stream*)cookie, buffer, size); return ret; } @@ -62,12 +63,14 @@ static int stream_cookie_writer(void *cookie, const char *buffer, int size) { TSRMLS_FETCH(); + return php_stream_write((php_stream *)cookie, (char *)buffer, size); } static fpos_t stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return (fpos_t)php_stream_seek((php_stream *)cookie, position, whence); } @@ -86,6 +89,7 @@ { ssize_t ret; TSRMLS_FETCH(); + ret = php_stream_read(((php_stream *)cookie), buffer, size); return ret; } @@ -93,6 +97,7 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t size) { TSRMLS_FETCH(); + return php_stream_write(((php_stream *)cookie), (char *)buffer, size); } @@ -103,14 +108,16 @@ *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); - if (*position == -1) + if (*position == -1) { return -1; + } return 0; } #else static int stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return php_stream_seek((php_stream *)cookie, position, whence); } #endif @@ -153,9 +160,9 @@ stream->readpos = stream->writepos = 0; } } - + /* filtered streams can only be cast as stdio, and only when fopencookie is present */ - + if (castas == PHP_STREAM_AS_STDIO) { if (stream->stdiocast) { if (ret) { @@ -167,31 +174,33 @@ /* if the stream is a stdio stream let's give it a chance to respond * first, to avoid doubling up the layers of stdio with an fopencookie */ if (php_stream_is(stream, PHP_STREAM_IS_STDIO) && - stream->ops->cast && - !php_stream_is_filtered(stream) && - stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) - { + stream->ops->cast && + !php_stream_is_filtered(stream) && + stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS + ) { goto exit_success; } - + #if HAVE_FOPENCOOKIE /* if just checking, say yes we can be a FILE*, but don't actually create it yet */ - if (ret == NULL) + if (ret == NULL) { goto exit_success; + } *(FILE**)ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS); if (*ret != NULL) { off_t pos; - + stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; /* If the stream position is not at the start, we need to force * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); - if (pos > 0) + if (pos > 0) { fseek(*ret, pos, SEEK_SET); - + } + goto exit_success; } @@ -221,9 +230,10 @@ } else { int retcode = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); - if (retcode == SUCCESS) + if (retcode == SUCCESS) { rewind(*(FILE**)ret); - + } + /* do some specialized cleanup */ if ((flags & PHP_STREAM_CAST_RELEASE)) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); @@ -245,13 +255,13 @@ if (show_err) { /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */ static const char *cast_names[4] = { - "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor" + "STDIO FILE*", + "File Descriptor", + "Socket Descriptor", + "select()able descriptor" }; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", - stream->ops->label, - cast_names[castas] - ); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]); } return FAILURE; @@ -259,20 +269,20 @@ exit_success: if ((stream->writepos - stream->readpos) > 0 && - stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && - (flags & PHP_STREAM_CAST_INTERNAL) == 0) { + stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && + (flags & PHP_STREAM_CAST_INTERNAL) == 0 + ) { /* the data we have buffered will be lost to the third party library that * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ - - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%ld bytes of buffered data lost during stream conversion!", - (long)(stream->writepos - stream->readpos)); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos)); } - - if (castas == PHP_STREAM_AS_STDIO && ret) + + if (castas == PHP_STREAM_AS_STDIO && ret) { stream->stdiocast = *(FILE**)ret; - + } + if (flags & PHP_STREAM_CAST_RELEASE) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } @@ -290,15 +300,15 @@ stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, opened_path); - if (stream == NULL) + if (stream == NULL) { return NULL; - - if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, - (void**)&fp, REPORT_ERRORS) == FAILURE) - { + } + + if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&fp, REPORT_ERRORS) == FAILURE) { php_stream_close(stream); - if (opened_path && *opened_path) + if (opened_path && *opened_path) { efree(*opened_path); + } return NULL; } return fp; @@ -311,21 +321,23 @@ assert(newstream != NULL); *newstream = NULL; - + if (((flags & PHP_STREAM_FORCE_CONVERSION) == 0) && origstream->ops->seek != NULL) { *newstream = origstream; return PHP_STREAM_UNCHANGED; } - + /* Use a tmpfile and copy the old streams contents into it */ - if (flags & PHP_STREAM_PREFER_STDIO) + if (flags & PHP_STREAM_PREFER_STDIO) { *newstream = php_stream_fopen_tmpfile(); - else + } else { *newstream = php_stream_temp_new(); + } - if (*newstream == NULL) + if (*newstream == NULL) { return PHP_STREAM_FAILED; + } if (php_stream_copy_to_stream_ex(origstream, *newstream, PHP_STREAM_COPY_ALL, NULL) != SUCCESS) { php_stream_close(*newstream); @@ -335,7 +347,7 @@ php_stream_close(origstream); php_stream_seek(*newstream, 0, SEEK_SET); - + return PHP_STREAM_RELEASED; } /* }}} */ Modified: php/php-src/branches/PHP_5_3/main/streams/cast.c =================================================================== --- php/php-src/branches/PHP_5_3/main/streams/cast.c 2010-01-19 11:44:43 UTC (rev 293723) +++ php/php-src/branches/PHP_5_3/main/streams/cast.c 2010-01-19 12:03:07 UTC (rev 293724) @@ -55,6 +55,7 @@ { int ret; TSRMLS_FETCH(); + ret = php_stream_read((php_stream*)cookie, buffer, size); return ret; } @@ -62,12 +63,14 @@ static int stream_cookie_writer(void *cookie, const char *buffer, int size) { TSRMLS_FETCH(); + return php_stream_write((php_stream *)cookie, (char *)buffer, size); } static fpos_t stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return (fpos_t)php_stream_seek((php_stream *)cookie, position, whence); } @@ -86,6 +89,7 @@ { ssize_t ret; TSRMLS_FETCH(); + ret = php_stream_read(((php_stream *)cookie), buffer, size); return ret; } @@ -93,6 +97,7 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t size) { TSRMLS_FETCH(); + return php_stream_write(((php_stream *)cookie), (char *)buffer, size); } @@ -103,14 +108,16 @@ *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); - if (*position == -1) + if (*position == -1) { return -1; + } return 0; } #else static int stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return php_stream_seek((php_stream *)cookie, position, whence); } #endif @@ -153,9 +160,9 @@ stream->readpos = stream->writepos = 0; } } - + /* filtered streams can only be cast as stdio, and only when fopencookie is present */ - + if (castas == PHP_STREAM_AS_STDIO) { if (stream->stdiocast) { if (ret) { @@ -167,31 +174,33 @@ /* if the stream is a stdio stream let's give it a chance to respond * first, to avoid doubling up the layers of stdio with an fopencookie */ if (php_stream_is(stream, PHP_STREAM_IS_STDIO) && - stream->ops->cast && - !php_stream_is_filtered(stream) && - stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) - { + stream->ops->cast && + !php_stream_is_filtered(stream) && + stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS + ) { goto exit_success; } - + #if HAVE_FOPENCOOKIE /* if just checking, say yes we can be a FILE*, but don't actually create it yet */ - if (ret == NULL) + if (ret == NULL) { goto exit_success; + } *(FILE**)ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS); if (*ret != NULL) { off_t pos; - + stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; /* If the stream position is not at the start, we need to force * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); - if (pos > 0) + if (pos > 0) { fseek(*ret, pos, SEEK_SET); - + } + goto exit_success; } @@ -219,11 +228,12 @@ if (ret != SUCCESS) { php_stream_close(newstream); } else { - int retcode = php_stream_cast(newstream, castas | flags, (void**)ret, show_err); + int retcode = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); - if (retcode == SUCCESS) + if (retcode == SUCCESS) { rewind(*(FILE**)ret); - + } + /* do some specialized cleanup */ if ((flags & PHP_STREAM_CAST_RELEASE)) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); @@ -245,13 +255,13 @@ if (show_err) { /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */ static const char *cast_names[4] = { - "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor" + "STDIO FILE*", + "File Descriptor", + "Socket Descriptor", + "select()able descriptor" }; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", - stream->ops->label, - cast_names[castas] - ); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]); } return FAILURE; @@ -259,20 +269,20 @@ exit_success: if ((stream->writepos - stream->readpos) > 0 && - stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && - (flags & PHP_STREAM_CAST_INTERNAL) == 0) { + stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && + (flags & PHP_STREAM_CAST_INTERNAL) == 0 + ) { /* the data we have buffered will be lost to the third party library that * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ - - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%ld bytes of buffered data lost during stream conversion!", - (long)(stream->writepos - stream->readpos)); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos)); } - - if (castas == PHP_STREAM_AS_STDIO && ret) + + if (castas == PHP_STREAM_AS_STDIO && ret) { stream->stdiocast = *(FILE**)ret; - + } + if (flags & PHP_STREAM_CAST_RELEASE) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } @@ -290,15 +300,15 @@ stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, opened_path); - if (stream == NULL) + if (stream == NULL) { return NULL; - - if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, - (void**)&fp, REPORT_ERRORS) == FAILURE) - { + } + + if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&fp, REPORT_ERRORS) == FAILURE) { php_stream_close(stream); - if (opened_path && *opened_path) + if (opened_path && *opened_path) { efree(*opened_path); + } return NULL; } return fp; @@ -311,21 +321,23 @@ assert(newstream != NULL); *newstream = NULL; - + if (((flags & PHP_STREAM_FORCE_CONVERSION) == 0) && origstream->ops->seek != NULL) { *newstream = origstream; return PHP_STREAM_UNCHANGED; } - + /* Use a tmpfile and copy the old streams contents into it */ - if (flags & PHP_STREAM_PREFER_STDIO) + if (flags & PHP_STREAM_PREFER_STDIO) { *newstream = php_stream_fopen_tmpfile(); - else + } else { *newstream = php_stream_temp_new(); + } - if (*newstream == NULL) + if (*newstream == NULL) { return PHP_STREAM_FAILED; + } #if ZEND_DEBUG (*newstream)->open_filename = origstream->open_filename; @@ -340,7 +352,7 @@ php_stream_close(origstream); php_stream_seek(*newstream, 0, SEEK_SET); - + return PHP_STREAM_RELEASED; } /* }}} */ Modified: php/php-src/trunk/main/streams/cast.c =================================================================== --- php/php-src/trunk/main/streams/cast.c 2010-01-19 11:44:43 UTC (rev 293723) +++ php/php-src/trunk/main/streams/cast.c 2010-01-19 12:03:07 UTC (rev 293724) @@ -55,6 +55,7 @@ { int ret; TSRMLS_FETCH(); + ret = php_stream_read((php_stream*)cookie, buffer, size); return ret; } @@ -62,12 +63,14 @@ static int stream_cookie_writer(void *cookie, const char *buffer, int size) { TSRMLS_FETCH(); + return php_stream_write((php_stream *)cookie, (char *)buffer, size); } static fpos_t stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return (fpos_t)php_stream_seek((php_stream *)cookie, position, whence); } @@ -86,6 +89,7 @@ { ssize_t ret; TSRMLS_FETCH(); + ret = php_stream_read(((php_stream *)cookie), buffer, size); return ret; } @@ -93,6 +97,7 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t size) { TSRMLS_FETCH(); + return php_stream_write(((php_stream *)cookie), (char *)buffer, size); } @@ -103,14 +108,16 @@ *position = php_stream_seek((php_stream *)cookie, (off_t)*position, whence); - if (*position == -1) + if (*position == -1) { return -1; + } return 0; } #else static int stream_cookie_seeker(void *cookie, off_t position, int whence) { TSRMLS_FETCH(); + return php_stream_seek((php_stream *)cookie, position, whence); } #endif @@ -153,9 +160,9 @@ stream->readpos = stream->writepos = 0; } } - + /* filtered streams can only be cast as stdio, and only when fopencookie is present */ - + if (castas == PHP_STREAM_AS_STDIO) { if (stream->stdiocast) { if (ret) { @@ -167,31 +174,33 @@ /* if the stream is a stdio stream let's give it a chance to respond * first, to avoid doubling up the layers of stdio with an fopencookie */ if (php_stream_is(stream, PHP_STREAM_IS_STDIO) && - stream->ops->cast && - !php_stream_is_filtered(stream) && - stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS) - { + stream->ops->cast && + !php_stream_is_filtered(stream) && + stream->ops->cast(stream, castas, ret TSRMLS_CC) == SUCCESS + ) { goto exit_success; } - + #if HAVE_FOPENCOOKIE /* if just checking, say yes we can be a FILE*, but don't actually create it yet */ - if (ret == NULL) + if (ret == NULL) { goto exit_success; + } *(FILE**)ret = fopencookie(stream, stream->mode, PHP_STREAM_COOKIE_FUNCTIONS); if (*ret != NULL) { off_t pos; - + stream->fclose_stdiocast = PHP_STREAM_FCLOSE_FOPENCOOKIE; /* If the stream position is not at the start, we need to force * the stdio layer to believe it's real location. */ pos = php_stream_tell(stream); - if (pos > 0) + if (pos > 0) { fseek(*ret, pos, SEEK_SET); - + } + goto exit_success; } @@ -219,11 +228,12 @@ if (ret != SUCCESS) { php_stream_close(newstream); } else { - int retcode = php_stream_cast(newstream, castas | flags, (void**)ret, show_err); + int retcode = php_stream_cast(newstream, castas | flags, (void **)ret, show_err); - if (retcode == SUCCESS) + if (retcode == SUCCESS) { rewind(*(FILE**)ret); - + } + /* do some specialized cleanup */ if ((flags & PHP_STREAM_CAST_RELEASE)) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); @@ -245,13 +255,13 @@ if (show_err) { /* these names depend on the values of the PHP_STREAM_AS_XXX defines in php_streams.h */ static const char *cast_names[4] = { - "STDIO FILE*", "File Descriptor", "Socket Descriptor", "select()able descriptor" + "STDIO FILE*", + "File Descriptor", + "Socket Descriptor", + "select()able descriptor" }; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", - stream->ops->label, - cast_names[castas] - ); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot represent a stream of type %s as a %s", stream->ops->label, cast_names[castas]); } return FAILURE; @@ -259,20 +269,20 @@ exit_success: if ((stream->writepos - stream->readpos) > 0 && - stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && - (flags & PHP_STREAM_CAST_INTERNAL) == 0) { + stream->fclose_stdiocast != PHP_STREAM_FCLOSE_FOPENCOOKIE && + (flags & PHP_STREAM_CAST_INTERNAL) == 0 + ) { /* the data we have buffered will be lost to the third party library that * will be accessing the stream. Emit a warning so that the end-user will * know that they should try something else */ - - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "%ld bytes of buffered data lost during stream conversion!", - (long)(stream->writepos - stream->readpos)); + + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%ld bytes of buffered data lost during stream conversion!", (long)(stream->writepos - stream->readpos)); } - - if (castas == PHP_STREAM_AS_STDIO && ret) + + if (castas == PHP_STREAM_AS_STDIO && ret) { stream->stdiocast = *(FILE**)ret; - + } + if (flags & PHP_STREAM_CAST_RELEASE) { php_stream_free(stream, PHP_STREAM_FREE_CLOSE_CASTED); } @@ -290,15 +300,15 @@ stream = php_stream_open_wrapper_rel(path, mode, options|STREAM_WILL_CAST, opened_path); - if (stream == NULL) + if (stream == NULL) { return NULL; - - if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, - (void**)&fp, REPORT_ERRORS) == FAILURE) - { + } + + if (php_stream_cast(stream, PHP_STREAM_AS_STDIO|PHP_STREAM_CAST_TRY_HARD|PHP_STREAM_CAST_RELEASE, (void**)&fp, REPORT_ERRORS) == FAILURE) { php_stream_close(stream); - if (opened_path && *opened_path) + if (opened_path && *opened_path) { efree(*opened_path); + } return NULL; } return fp; @@ -311,21 +321,23 @@ assert(newstream != NULL); *newstream = NULL; - + if (((flags & PHP_STREAM_FORCE_CONVERSION) == 0) && origstream->ops->seek != NULL) { *newstream = origstream; return PHP_STREAM_UNCHANGED; } - + /* Use a tmpfile and copy the old streams contents into it */ - if (flags & PHP_STREAM_PREFER_STDIO) + if (flags & PHP_STREAM_PREFER_STDIO) { *newstream = php_stream_fopen_tmpfile(); - else + } else { *newstream = php_stream_temp_new(); + } - if (*newstream == NULL) + if (*newstream == NULL) { return PHP_STREAM_FAILED; + } #if ZEND_DEBUG (*newstream)->open_filename = origstream->open_filename; @@ -340,7 +352,7 @@ php_stream_close(origstream); php_stream_seek(*newstream, 0, SEEK_SET); - + return PHP_STREAM_RELEASED; } /* }}} */
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php