lbarnaud                Sun May 17 14:59:24 2009 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/standard/tests/streams bug48309.phpt 

  Modified files:              
    /php-src    NEWS 
    /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/NEWS?r1=1.2027.2.547.2.1512&r2=1.2027.2.547.2.1513&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1512 php-src/NEWS:1.2027.2.547.2.1513
--- php-src/NEWS:1.2027.2.547.2.1512    Sat May 16 20:24:01 2009
+++ php-src/NEWS        Sun May 17 14:59:24 2009
@@ -16,6 +16,8 @@
 - Fixed segfault on invalid session.save_path. (Hannes)
 - Fixed leaks in imap when a mail_criteria is used. (Pierre)
 
+- Fixed bug #48309 (stream_copy_to_stream() and fpasstru() do not update stream
+  position of plain files). (Arnaud)
 - Fixed bug #48307 (stream_copy_to_stream() copies 0 bytes when $source is a 
   socket). (Arnaud)
 - Fixed bug #48256 (Crash due to double-linking of history.o).
http://cvs.php.net/viewvc.cgi/php-src/main/streams/mmap.c?r1=1.8.2.1.2.3&r2=1.8.2.1.2.4&diff_format=u
Index: php-src/main/streams/mmap.c
diff -u php-src/main/streams/mmap.c:1.8.2.1.2.3 
php-src/main/streams/mmap.c:1.8.2.1.2.4
--- php-src/main/streams/mmap.c:1.8.2.1.2.3     Wed Dec 31 11:17:48 2008
+++ php-src/main/streams/mmap.c Sun May 17 14:59:24 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: mmap.c,v 1.8.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: mmap.c,v 1.8.2.1.2.4 2009/05/17 14:59:24 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.3&r2=1.5.2.1.2.4&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.3 
php-src/main/streams/php_stream_mmap.h:1.5.2.1.2.4
--- php-src/main/streams/php_stream_mmap.h:1.5.2.1.2.3  Wed Dec 31 11:17:48 2008
+++ php-src/main/streams/php_stream_mmap.h      Sun May 17 14:59:24 2009
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_stream_mmap.h,v 1.5.2.1.2.3 2008/12/31 11:17:48 sebastian Exp $ */
+/* $Id: php_stream_mmap.h,v 1.5.2.1.2.4 2009/05/17 14:59:24 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.37&r2=1.82.2.6.2.38&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.82.2.6.2.37 
php-src/main/streams/streams.c:1.82.2.6.2.38
--- php-src/main/streams/streams.c:1.82.2.6.2.37        Sat May 16 20:24:01 2009
+++ php-src/main/streams/streams.c      Sun May 17 14:59:24 2009
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.82.2.6.2.37 2009/05/16 20:24:01 lbarnaud Exp $ */
+/* $Id: streams.c,v 1.82.2.6.2.38 2009/05/17 14:59:24 lbarnaud Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -1206,12 +1206,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;
                }
@@ -1331,7 +1331,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