lbarnaud                Sun May 17 14:57:05 2009 UTC

  Added files:                 
    /php-src/ext/standard/tests/streams bug48309.phpt 

  Modified files:              
    /php-src/main/streams       mmap.c php_stream_mmap.h streams.c 
  Log:
  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.16&r2=1.17&diff_format=u
Index: php-src/main/streams/mmap.c
diff -u php-src/main/streams/mmap.c:1.16 php-src/main/streams/mmap.c:1.17
--- php-src/main/streams/mmap.c:1.16    Tue Mar 10 23:40:01 2009
+++ php-src/main/streams/mmap.c Sun May 17 14:57:05 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mmap.c,v 1.16 2009/03/10 23:40:01 helly Exp $ */
+/* $Id: mmap.c,v 1.17 2009/05/17 14:57:05 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.10&r2=1.11&diff_format=u
Index: php-src/main/streams/php_stream_mmap.h
diff -u php-src/main/streams/php_stream_mmap.h:1.10 
php-src/main/streams/php_stream_mmap.h:1.11
--- php-src/main/streams/php_stream_mmap.h:1.10 Tue Mar 10 23:40:01 2009
+++ php-src/main/streams/php_stream_mmap.h      Sun May 17 14:57:05 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_stream_mmap.h,v 1.10 2009/03/10 23:40:01 helly Exp $ */
+/* $Id: php_stream_mmap.h,v 1.11 2009/05/17 14:57:05 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.184&r2=1.185&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.184 
php-src/main/streams/streams.c:1.185
--- php-src/main/streams/streams.c:1.184        Sat May 16 20:22:29 2009
+++ php-src/main/streams/streams.c      Sun May 17 14:57:05 2009
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.184 2009/05/16 20:22:29 lbarnaud Exp $ */
+/* $Id: streams.c,v 1.185 2009/05/17 14:57:05 lbarnaud Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -1603,12 +1603,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;
                }
@@ -1916,7 +1916,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

Reply via email to