tony2001                Mon Mar 24 16:28:08 2008 UTC

  Modified files:              
    /php-src/main/streams       streams.c 
  Log:
  Change streams to not use mmap() when reading files (aka copying to memory).
  
  There are two problems with mmap() in this case:
  1) there is no performance gain since we allocate the memory anyways;
  2) memcpy() may crash if somebody truncates this file at the same moment
  (see http://dev.daylessday.org/diff/mmap.phps for example);
  
  It seems to work fine with fpassthru(), though why it is so should be 
investigated.
  
  Thanks to Andrey Vasilishin for the report and Anight for pressing this 
through =)
  
  
http://cvs.php.net/viewvc.cgi/php-src/main/streams/streams.c?r1=1.159&r2=1.160&diff_format=u
Index: php-src/main/streams/streams.c
diff -u php-src/main/streams/streams.c:1.159 
php-src/main/streams/streams.c:1.160
--- php-src/main/streams/streams.c:1.159        Sun Jan 13 22:55:02 2008
+++ php-src/main/streams/streams.c      Mon Mar 24 16:28:08 2008
@@ -19,7 +19,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: streams.c,v 1.159 2008/01/13 22:55:02 cellog Exp $ */
+/* $Id: streams.c,v 1.160 2008/03/24 16:28:08 tony2001 Exp $ */
 
 #define _GNU_SOURCE
 #include "php.h"
@@ -1648,27 +1648,6 @@
                maxlen = 0;
        }
 
-       if (php_stream_mmap_possible(src)) {
-               /* guarantees src->readbuf_type == IS_STRING */
-               char *p;
-               size_t mapped;
-
-               p = php_stream_mmap_range(src, php_stream_tell(src), maxlen, 
PHP_STREAM_MAP_MODE_SHARED_READONLY, &mapped);
-
-               if (p && mapped) {
-                       *buf = pemalloc_rel_orig(mapped + 1, persistent);
-
-                       if (*buf) {
-                               memcpy(*buf, p, mapped);
-                               ((char*)(*buf))[mapped] = 0;
-                       }
-
-                       php_stream_mmap_unmap(src);
-
-                       return mapped;
-               }
-       }
-
        if (maxlen > 0) {
                if (rettype == IS_UNICODE) {
                        ptr.u = *buf = pemalloc_rel_orig(UBYTES(maxlen + 1), 
persistent);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to