lbarnaud                Wed Nov 26 04:20:42 2008 UTC

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

  Modified files:              
    /php-src/ext/standard       file.c flock_compat.h 
    /php-src/main/streams       userspace.c 
    /php-src    NEWS 
  Log:
  MFH: Fixed bug #46673 (stream_lock call with wrong paramater)
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.36&r2=1.409.2.6.2.37&diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.36 
php-src/ext/standard/file.c:1.409.2.6.2.37
--- php-src/ext/standard/file.c:1.409.2.6.2.36  Sat Nov  1 22:39:14 2008
+++ php-src/ext/standard/file.c Wed Nov 26 04:20:41 2008
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: file.c,v 1.409.2.6.2.36 2008/11/01 22:39:14 jani Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.37 2008/11/26 04:20:41 lbarnaud Exp $ */
 
 /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
 
@@ -195,10 +195,10 @@
        REGISTER_LONG_CONSTANT("SEEK_SET", SEEK_SET, CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SEEK_CUR", SEEK_CUR, CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("SEEK_END", SEEK_END, CONST_CS | 
CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("LOCK_SH", 1, CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("LOCK_EX", 2, CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("LOCK_UN", 3, CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("LOCK_NB", 4, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("LOCK_SH", PHP_LOCK_SH, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("LOCK_EX", PHP_LOCK_EX, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("LOCK_UN", PHP_LOCK_UN, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("LOCK_NB", PHP_LOCK_NB, CONST_CS | 
CONST_PERSISTENT);
 
        REGISTER_LONG_CONSTANT("STREAM_NOTIFY_CONNECT",                 
PHP_STREAM_NOTIFY_CONNECT,                      CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_REQUIRED",   
PHP_STREAM_NOTIFY_AUTH_REQUIRED,        CONST_CS | CONST_PERSISTENT);
@@ -347,7 +347,7 @@
        }
 
        /* flock_values contains all possible actions if (operation & 4) we 
won't block on the lock */
-       act = flock_values[act - 1] | (operation & 4 ? LOCK_NB : 0);
+       act = flock_values[act - 1] | (operation & PHP_LOCK_NB ? LOCK_NB : 0);
        if (php_stream_lock(stream, act)) {
                if (operation && errno == EWOULDBLOCK && arg3 && 
PZVAL_IS_REF(arg3)) {
                        Z_LVAL_P(arg3) = 1;
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/flock_compat.h?r1=1.20.2.1.2.2&r2=1.20.2.1.2.3&diff_format=u
Index: php-src/ext/standard/flock_compat.h
diff -u php-src/ext/standard/flock_compat.h:1.20.2.1.2.2 
php-src/ext/standard/flock_compat.h:1.20.2.1.2.3
--- php-src/ext/standard/flock_compat.h:1.20.2.1.2.2    Mon Dec 31 07:20:12 2007
+++ php-src/ext/standard/flock_compat.h Wed Nov 26 04:20:41 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: flock_compat.h,v 1.20.2.1.2.2 2007/12/31 07:20:12 sebastian Exp $ */
+/* $Id: flock_compat.h,v 1.20.2.1.2.3 2008/11/26 04:20:41 lbarnaud Exp $ */
 
 #ifndef FLOCK_COMPAT_H
 #define FLOCK_COMPAT_H
@@ -35,6 +35,12 @@
 PHPAPI int flock(int fd, int operation);
 #endif
 
+/* Userland LOCK_* constants */
+#define PHP_LOCK_SH 1
+#define PHP_LOCK_EX 2
+#define PHP_LOCK_UN 3
+#define PHP_LOCK_NB 4
+
 #ifdef PHP_WIN32
 #define EWOULDBLOCK WSAEWOULDBLOCK
 #      define fsync _commit
http://cvs.php.net/viewvc.cgi/php-src/main/streams/userspace.c?r1=1.31.2.3.2.8&r2=1.31.2.3.2.9&diff_format=u
Index: php-src/main/streams/userspace.c
diff -u php-src/main/streams/userspace.c:1.31.2.3.2.8 
php-src/main/streams/userspace.c:1.31.2.3.2.9
--- php-src/main/streams/userspace.c:1.31.2.3.2.8       Mon Dec 31 07:20:15 2007
+++ php-src/main/streams/userspace.c    Wed Nov 26 04:20:41 2008
@@ -17,11 +17,15 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: userspace.c,v 1.31.2.3.2.8 2007/12/31 07:20:15 sebastian Exp $ */
+/* $Id: userspace.c,v 1.31.2.3.2.9 2008/11/26 04:20:41 lbarnaud Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
 #include "ext/standard/file.h"
+#include "ext/standard/flock_compat.h"
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
 
 static int le_protocols;
 
@@ -908,7 +912,23 @@
 
        case PHP_STREAM_OPTION_LOCKING:
                MAKE_STD_ZVAL(zvalue);
-               ZVAL_LONG(zvalue, value);
+               ZVAL_LONG(zvalue, 0);
+
+               if (value & LOCK_NB) {
+                       Z_LVAL_P(zvalue) |= PHP_LOCK_NB;
+               }
+               switch(value & ~LOCK_NB) {
+               case LOCK_SH:
+                       Z_LVAL_P(zvalue) |= PHP_LOCK_SH;
+                       break;
+               case LOCK_EX:
+                       Z_LVAL_P(zvalue) |= PHP_LOCK_EX;
+                       break;
+               case LOCK_UN:
+                       Z_LVAL_P(zvalue) |= PHP_LOCK_UN;
+                       break;
+               }
+
                args[0] = &zvalue;
                
                /* TODO wouldblock */
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.1331&r2=1.2027.2.547.2.1332&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.1331 php-src/NEWS:1.2027.2.547.2.1332
--- php-src/NEWS:1.2027.2.547.2.1331    Wed Nov 26 01:21:10 2008
+++ php-src/NEWS        Wed Nov 26 04:20:41 2008
@@ -4,6 +4,7 @@
 - Upgraded PCRE to version 7.8 (Ilia)
 
 - Fixed memory leak inside readline_callback_handler_remove() function. 
(Felipe)
+- Fixed bug #46673 (stream_lock call with wrong paramater). (Arnaud)
 - Fixed bug #46649 (Setting array element with that same array produces 
   inconsistent results). (Arnaud)
 - Fixed bug #46626 (mb_convert_case does not handle apostrophe correctly).

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/userstreams_004.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/file/userstreams_004.phpt
+++ php-src/ext/standard/tests/file/userstreams_004.phpt
--TEST--
User-space streams: stream_lock()
--FILE--
<?php
class test_wrapper_base {
        public $mode;
        function stream_open($path, $mode, $openedpath) {
                return true;
        }
        function stream_eof() {
                return false;
        }
}
class test_wrapper extends test_wrapper_base {
        function stream_lock($mode) {
                $this->mode = $mode;
        }
}
function test($name, $fd, $mode) {
        echo "------ $name: -------\n";
        flock($fd, $mode);
        $data = stream_get_meta_data($fd);
        var_dump($data['wrapper_data']->mode === $mode);
}

var_dump(stream_wrapper_register('test', 'test_wrapper'));
var_dump(stream_wrapper_register('test2', 'test_wrapper_base'));

$fd = fopen("test://foo","r");
$fd2 = fopen("test2://foo","r");

test("stream_lock not implemented", $fd2, LOCK_EX);

foreach(array("LOCK_SH","LOCK_EX","LOCK_UN") as $mode) {
        test("fclock($mode)", $fd, constant($mode));
        test("fclock($mode|LOCK_NB)", $fd, constant($mode)|LOCK_NB);
}

?>
--EXPECTF--
bool(true)
bool(true)
------ stream_lock not implemented: -------

Warning: flock(): test_wrapper_base::stream_lock is not implemented! in %s
bool(false)
------ fclock(LOCK_SH): -------
bool(true)
------ fclock(LOCK_SH|LOCK_NB): -------
bool(true)
------ fclock(LOCK_EX): -------
bool(true)
------ fclock(LOCK_EX|LOCK_NB): -------
bool(true)
------ fclock(LOCK_UN): -------
bool(true)
------ fclock(LOCK_UN|LOCK_NB): -------
bool(true)



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

Reply via email to