sas                                      Thu, 12 Aug 2010 17:27:16 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=302150

Log:
separate properties of internal classes in ZTS mode fully,
otherwise multiple threads will modify the zvals' contents
without any synchronisation.

Changed paths:
    U   php/php-src/branches/PHP_5_2/Zend/zend_API.c
    U   php/php-src/branches/PHP_5_2/Zend/zend_compile.c
    U   php/php-src/branches/PHP_5_2/Zend/zend_exceptions.c
    U   php/php-src/branches/PHP_5_2/Zend/zend_objects.c
    U   php/php-src/branches/PHP_5_2/Zend/zend_variables.c
    U   php/php-src/branches/PHP_5_2/Zend/zend_variables.h

Modified: php/php-src/branches/PHP_5_2/Zend/zend_API.c
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_API.c        2010-08-12 16:00:19 UTC 
(rev 302149)
+++ php/php-src/branches/PHP_5_2/Zend/zend_API.c        2010-08-12 17:27:16 UTC 
(rev 302150)
@@ -952,7 +952,7 @@
                } else {
                        ALLOC_HASHTABLE_REL(object->properties);
                        zend_hash_init(object->properties, 
zend_hash_num_elements(&class_type->default_properties), NULL, ZVAL_PTR_DTOR, 
0);
-                       zend_hash_copy(object->properties, 
&class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) 
&tmp, sizeof(zval *));
+                       zend_hash_copy(object->properties, 
&class_type->default_properties, zval_copy_property_ctor(class_type), (void *) 
&tmp, sizeof(zval *));
                }
        } else {
                Z_OBJVAL_P(arg) = class_type->create_object(class_type 
TSRMLS_CC);

Modified: php/php-src/branches/PHP_5_2/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_compile.c    2010-08-12 16:00:19 UTC 
(rev 302149)
+++ php/php-src/branches/PHP_5_2/Zend/zend_compile.c    2010-08-12 17:27:16 UTC 
(rev 302150)
@@ -2298,25 +2298,9 @@
        return ZEND_HASH_APPLY_KEEP;
 }

-#ifdef ZTS
-static void zval_internal_ctor(zval **p)
-{
-       zval *orig_ptr = *p;
+#define zval_property_ctor(parent_ce, ce) \
+       ((copy_ctor_func_t) (((parent_ce)->type != (ce)->type) ? 
zval_shared_property_ctor : zval_add_ref))

-       ALLOC_ZVAL(*p);
-       **p = *orig_ptr;
-       zval_copy_ctor(*p);
-       (*p)->refcount = 1;
-       (*p)->is_ref = 0;
-}
-
-# define zval_property_ctor(parent_ce, ce) \
-       ((void (*)(void *)) (((parent_ce)->type != (ce)->type) ? 
zval_internal_ctor : zval_add_ref))
-#else
-# define zval_property_ctor(parent_ce, ce) \
-       ((void (*)(void *)) zval_add_ref)
-#endif
-
 ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry 
*parent_ce TSRMLS_DC)
 {
        if ((ce->ce_flags & ZEND_ACC_INTERFACE)

Modified: php/php-src/branches/PHP_5_2/Zend/zend_exceptions.c
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_exceptions.c 2010-08-12 16:00:19 UTC 
(rev 302149)
+++ php/php-src/branches/PHP_5_2/Zend/zend_exceptions.c 2010-08-12 17:27:16 UTC 
(rev 302150)
@@ -84,7 +84,7 @@

        ALLOC_HASHTABLE(object->properties);
        zend_hash_init(object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
-       zend_hash_copy(object->properties, &class_type->default_properties, 
(copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+       zend_hash_copy(object->properties, &class_type->default_properties, 
zval_copy_property_ctor(class_type), (void *) &tmp, sizeof(zval *));

        ALLOC_ZVAL(trace);
        trace->is_ref = 0;

Modified: php/php-src/branches/PHP_5_2/Zend/zend_objects.c
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_objects.c    2010-08-12 16:00:19 UTC 
(rev 302149)
+++ php/php-src/branches/PHP_5_2/Zend/zend_objects.c    2010-08-12 17:27:16 UTC 
(rev 302150)
@@ -156,7 +156,7 @@
                        (*p)->value.obj = Z_OBJ_HT_PP(p)->clone_obj(orig 
TSRMLS_CC);
                }
        } else {
-               (*p)->refcount++;
+               zval_shared_property_ctor(p);
        }
 }

@@ -165,7 +165,7 @@
        if (EG(ze1_compatibility_mode)) {
                zend_hash_copy(new_object->properties, old_object->properties, 
(copy_ctor_func_t) zval_add_ref_or_clone, (void *) NULL /* Not used anymore */, 
sizeof(zval *));
        } else {
-               zend_hash_copy(new_object->properties, old_object->properties, 
(copy_ctor_func_t) zval_add_ref, (void *) NULL /* Not used anymore */, 
sizeof(zval *));
+               zend_hash_copy(new_object->properties, old_object->properties, 
zval_copy_property_ctor(old_object->ce), (void *) NULL /* Not used anymore */, 
sizeof(zval *));
        }
        if (old_object->ce->clone) {
                zval *new_obj;

Modified: php/php-src/branches/PHP_5_2/Zend/zend_variables.c
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_variables.c  2010-08-12 16:00:19 UTC 
(rev 302149)
+++ php/php-src/branches/PHP_5_2/Zend/zend_variables.c  2010-08-12 17:27:16 UTC 
(rev 302150)
@@ -150,6 +150,18 @@
 }
 /* }}} */

+ZEND_API void zval_property_ctor(zval **p) /* {{{ */
+{
+       zval *orig_ptr = *p;
+
+       ALLOC_ZVAL(*p);
+       **p = *orig_ptr;
+       zval_copy_ctor(*p);
+       (*p)->refcount = 1;
+       (*p)->is_ref   = 0;
+}
+/* }}} */
+
 #if ZEND_DEBUG
 ZEND_API void _zval_copy_ctor_wrapper(zval *zvalue) /* {{{ */
 {

Modified: php/php-src/branches/PHP_5_2/Zend/zend_variables.h
===================================================================
--- php/php-src/branches/PHP_5_2/Zend/zend_variables.h  2010-08-12 16:00:19 UTC 
(rev 302149)
+++ php/php-src/branches/PHP_5_2/Zend/zend_variables.h  2010-08-12 17:27:16 UTC 
(rev 302150)
@@ -77,6 +77,17 @@

 ZEND_API void zval_add_ref(zval **p);

+ZEND_API void zval_property_ctor(zval **);
+
+#ifdef ZTS
+# define zval_shared_property_ctor zval_property_ctor
+#else
+# define zval_shared_property_ctor zval_add_ref
+#endif
+
+#define zval_copy_property_ctor(ce) ((copy_ctor_func_t) (((ce)->type == 
ZEND_INTERNAL_CLASS) ? zval_shared_property_ctor : zval_add_ref))
+
+
 END_EXTERN_C()

 #define ZVAL_DESTRUCTOR (void (*)(void *)) zval_dtor_wrapper

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

Reply via email to