lbarnaud Sun May 17 14:58:10 2009 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard/tests/streams bug48309.phpt
Modified files: /php-src/main/streams mmap.c php_stream_mmap.h streams.c Log: MFH: Fixed bug #48309 (stream_copy_to_stream() and fpasstru() do not update stream position of plain files) http://cvs.php.net/viewvc.cgi/php-src/main/streams/mmap.c?r1=1.8.2.1.2.1.2.5&r2=1.8.2.1.2.1.2.6&diff_format=u Index: php-src/main/streams/mmap.c diff -u php-src/main/streams/mmap.c:1.8.2.1.2.1.2.5 php-src/main/streams/mmap.c:1.8.2.1.2.1.2.6 --- php-src/main/streams/mmap.c:1.8.2.1.2.1.2.5 Wed Dec 31 11:15:48 2008 +++ php-src/main/streams/mmap.c Sun May 17 14:58:10 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mmap.c,v 1.8.2.1.2.1.2.5 2008/12/31 11:15:48 sebastian Exp $ */ +/* $Id: mmap.c,v 1.8.2.1.2.1.2.6 2009/05/17 14:58:10 lbarnaud Exp $ */ /* Memory Mapping interface for streams */ #include "php.h" @@ -51,6 +51,20 @@ return php_stream_set_option(stream, PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_UNMAP, NULL) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0; } +PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC) +{ + int ret = 1; + + if (php_stream_seek(stream, readden, SEEK_CUR) != 0) { + ret = 0; + } + if (php_stream_mmap_unmap(stream) == 0) { + ret = 0; + } + + return ret; +} + /* * Local variables: * tab-width: 4 http://cvs.php.net/viewvc.cgi/php-src/main/streams/php_stream_mmap.h?r1=1.5.2.1.2.1.2.2&r2=1.5.2.1.2.1.2.3&diff_format=u Index: php-src/main/streams/php_stream_mmap.h diff -u php-src/main/streams/php_stream_mmap.h:1.5.2.1.2.1.2.2 php-src/main/streams/php_stream_mmap.h:1.5.2.1.2.1.2.3 --- php-src/main/streams/php_stream_mmap.h:1.5.2.1.2.1.2.2 Wed Dec 31 11:15:48 2008 +++ php-src/main/streams/php_stream_mmap.h Sun May 17 14:58:10 2009 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_stream_mmap.h,v 1.5.2.1.2.1.2.2 2008/12/31 11:15:48 sebastian Exp $ */ +/* $Id: php_stream_mmap.h,v 1.5.2.1.2.1.2.3 2009/05/17 14:58:10 lbarnaud Exp $ */ /* Memory Mapping interface for streams. * The intention is to provide a uniform interface over the most common @@ -58,6 +58,8 @@ } php_stream_mmap_range; +#define PHP_STREAM_MMAP_ALL 0 + #define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL TSRMLS_CC) == 0 ? 1 : 0) /* Returns 1 if the stream in its current state can be memory mapped, @@ -71,6 +73,9 @@ /* un-maps the last mapped range */ PHPAPI int _php_stream_mmap_unmap(php_stream *stream TSRMLS_DC); #define php_stream_mmap_unmap(stream) _php_stream_mmap_unmap((stream) TSRMLS_CC) + +PHPAPI int _php_stream_mmap_unmap_ex(php_stream *stream, off_t readden TSRMLS_DC); +#define php_stream_mmap_unmap_ex(stream, readden) _php_stream_mmap_unmap_ex((stream), (readden) TSRMLS_CC) END_EXTERN_C() /* http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.82.2.6.2.18.2.27&r2=1.82.2.6.2.18.2.28&diff_format=u Index: php-src/main/streams/streams.c diff -u php-src/main/streams/streams.c:1.82.2.6.2.18.2.27 php-src/main/streams/streams.c:1.82.2.6.2.18.2.28 --- php-src/main/streams/streams.c:1.82.2.6.2.18.2.27 Sat May 16 20:23:06 2009 +++ php-src/main/streams/streams.c Sun May 17 14:58:10 2009 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: streams.c,v 1.82.2.6.2.18.2.27 2009/05/16 20:23:06 lbarnaud Exp $ */ +/* $Id: streams.c,v 1.82.2.6.2.18.2.28 2009/05/17 14:58:10 lbarnaud Exp $ */ #define _GNU_SOURCE #include "php.h" @@ -1215,12 +1215,12 @@ char *p; size_t mapped; - p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_COPY_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); + p = php_stream_mmap_range(stream, php_stream_tell(stream), PHP_STREAM_MMAP_ALL, PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped); if (p) { PHPWRITE(p, mapped); - php_stream_mmap_unmap(stream); + php_stream_mmap_unmap_ex(stream, mapped); return mapped; } @@ -1340,7 +1340,7 @@ if (p) { mapped = php_stream_write(dest, p, mapped); - php_stream_mmap_unmap(src); + php_stream_mmap_unmap_ex(src, mapped); *len = mapped; http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/streams/bug48309.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/streams/bug48309.phpt +++ php-src/ext/standard/tests/streams/bug48309.phpt --TEST-- Bug #48309 (stream_copy_to_stream() and fpasstru() do not update stream position) --FILE-- <?php $tmp = tmpfile(); fwrite($tmp, b'test'); fseek($tmp, 0, SEEK_SET); echo "-- stream_copy_to_stream() --\n"; fseek($tmp, 0, SEEK_SET); stream_copy_to_stream($tmp, STDOUT, 2); echo "\n"; var_dump(stream_get_contents($tmp)); echo "-- fpassthru() --\n"; fseek($tmp, 0, SEEK_SET); fpassthru($tmp); echo "\n"; var_dump(stream_get_contents($tmp)); ?> --EXPECTF-- -- stream_copy_to_stream() -- te string(2) "st" -- fpassthru() -- test string(0) "" -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php