iliaa           Wed Jan 10 18:14:38 2007 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/spl/tests      bug40091.phpt 

  Modified files:              
    /php-src    NEWS 
    /php-src/ext/spl    php_spl.c 
  Log:
  
  Fixed bug #40091 (spl_autoload_register with 2 instances of the same class).
  
  
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.488&r2=1.2027.2.547.2.489&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.488 php-src/NEWS:1.2027.2.547.2.489
--- php-src/NEWS:1.2027.2.547.2.488     Wed Jan 10 16:14:34 2007
+++ php-src/NEWS        Wed Jan 10 18:14:37 2007
@@ -4,6 +4,8 @@
 - Added CURLOPT_TCP_NODELAY constant to Curl extension. (Sara)
 - Improved proc_open(). Now on Windows it can run external commands not through
   CMD.EXE. (Dmitry)
+- Fixed bug #40091 (spl_autoload_register with 2 instances of the same
+  class). (Ilia)
 - Fixed bug #40083 (milter SAPI functions always return false/null). (Tony)
 - Fixed bug #40079 (php_get_current_user() not thread safe). (Ilia, wharmby
   at uk dot ibm dot com)
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/php_spl.c?r1=1.52.2.28.2.13&r2=1.52.2.28.2.14&diff_format=u
Index: php-src/ext/spl/php_spl.c
diff -u php-src/ext/spl/php_spl.c:1.52.2.28.2.13 
php-src/ext/spl/php_spl.c:1.52.2.28.2.14
--- php-src/ext/spl/php_spl.c:1.52.2.28.2.13    Mon Jan  8 04:27:29 2007
+++ php-src/ext/spl/php_spl.c   Wed Jan 10 18:14:37 2007
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_spl.c,v 1.52.2.28.2.13 2007/01/08 04:27:29 iliaa Exp $ */
+/* $Id: php_spl.c,v 1.52.2.28.2.14 2007/01/10 18:14:37 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
        #include "config.h"
@@ -444,10 +444,19 @@
                        }
                }
        
-               lc_name = do_alloca(func_name_len + 1);
+               lc_name = safe_emalloc(func_name_len, 1, sizeof(long) + 1);
                zend_str_tolower_copy(lc_name, func_name, func_name_len);
                efree(func_name);
+
+               if (SPL_G(autoload_functions) && 
zend_hash_exists(SPL_G(autoload_functions), (char*)lc_name, func_name_len+1)) {
+                       goto skip;                      
+               }
+
                if (obj_ptr && !(alfi.func_ptr->common.fn_flags & 
ZEND_ACC_STATIC)) {
+                       /* add object id to the hash to ensure uniqueness, for 
more reference look at bug #40091 */
+                       memcpy(lc_name + func_name_len, obj_ptr, sizeof(long));
+                       func_name_len += sizeof(long);
+                       lc_name[func_name_len] = '\0';
                        alfi.obj = *obj_ptr;
                        alfi.obj->refcount++;
                } else {
@@ -471,8 +480,8 @@
                }
 
                zend_hash_add(SPL_G(autoload_functions), lc_name, 
func_name_len+1, &alfi.func_ptr, sizeof(autoload_func_info), NULL);
-
-               free_alloca(lc_name);
+skip:
+               efree(lc_name);
        }
 
        if (SPL_G(autoload_functions)) {
@@ -492,12 +501,13 @@
        zval *zcallable;
        int success = FAILURE;
        zend_function *spl_func_ptr;
+       zval **obj_ptr;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcallable) 
== FAILURE) {
                return;
        }
 
-       if (!zend_is_callable_ex(zcallable, IS_CALLABLE_CHECK_SYNTAX_ONLY, 
&func_name, &func_name_len, NULL, NULL, NULL TSRMLS_CC)) {
+       if (!zend_is_callable_ex(zcallable, IS_CALLABLE_CHECK_SYNTAX_ONLY, 
&func_name, &func_name_len, NULL, NULL, &obj_ptr TSRMLS_CC)) {
                if (func_name) {
                        efree(func_name);
                }
@@ -517,6 +527,13 @@
                } else {
                        /* remove specific */
                        success = zend_hash_del(SPL_G(autoload_functions), 
func_name, func_name_len+1);
+                       if (success != SUCCESS && obj_ptr) {
+                               func_name = erealloc(func_name, func_name_len + 
1 + sizeof(long));
+                               memcpy(func_name + func_name_len, obj_ptr, 
sizeof(long));
+                               func_name_len += sizeof(long);
+                               func_name[func_name_len] = '\0';
+                               success = 
zend_hash_del(SPL_G(autoload_functions), func_name, func_name_len+1);
+                       }
                }
        } else if (func_name_len == sizeof("spl_autoload")-1 && 
!strcmp(func_name, "spl_autoload")) {
                /* register single spl_autoload() */

http://cvs.php.net/viewvc.cgi/php-src/ext/spl/tests/bug40091.phpt?view=markup&rev=1.1
Index: php-src/ext/spl/tests/bug40091.phpt
+++ php-src/ext/spl/tests/bug40091.phpt


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

Reply via email to