svn: /php/php-src/ branches/PHP_5_2/Zend/zend_compile.c branches/PHP_5_3/Zend/zend_compile.c trunk/Zend/zend_compile.c
| From: | Dmitry Stogov | Date: | Wed, 11 Aug 2010 09:38:41 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_2/Zend/zend_compile.c branches/PHP_5_3/Zend/zend_compile.c trunk/Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-63263@lists.php.net to get a copy of this message | ||
dmitry Wed, 11 Aug 2010 09:38:41 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=302104
Log:
In ZTS mode default properties and constants of internal classes can't be modified in place and
have to be separated
Changed paths:
U php/php-src/branches/PHP_5_2/Zend/zend_compile.c
U php/php-src/branches/PHP_5_3/Zend/zend_compile.c
U php/php-src/trunk/Zend/zend_compile.c
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-11 08:57:34 UTC (rev 302103)
+++ php/php-src/branches/PHP_5_2/Zend/zend_compile.c 2010-08-11 09:38:41 UTC (rev 302104)
@@ -2298,6 +2298,25 @@
return ZEND_HASH_APPLY_KEEP;
}
+#ifdef ZTS
+static void zval_internal_ctor(zval **p)
+{
+ zval *orig_ptr = *p;
+
+ 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)
@@ -2313,7 +2332,7 @@
zend_do_inherit_interfaces(ce, parent_ce TSRMLS_CC);
/* Inherit properties */
- zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, (void
(*)(void *)) zval_add_ref, NULL, sizeof(zval *), 0);
+ zend_hash_merge(&ce->default_properties, &parent_ce->default_properties,
zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
if (parent_ce->type != ce->type) {
/* User class extends internal class */
zend_update_class_constants(parent_ce TSRMLS_CC);
@@ -2323,7 +2342,7 @@
}
zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info,
(copy_ctor_func_t) (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal :
zend_duplicate_property_info), sizeof(zend_property_info), (merge_checker_func_t)
do_inherit_property_access_check, ce);
- zend_hash_merge(&ce->constants_table, &parent_ce->constants_table, (void (*)(void
*)) zval_add_ref, NULL, sizeof(zval *), 0);
+ zend_hash_merge(&ce->constants_table, &parent_ce->constants_table,
zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
zend_hash_merge_ex(&ce->function_table, &parent_ce->function_table,
(copy_ctor_func_t) do_inherit_method, sizeof(zend_function), (merge_checker_func_t)
do_inherit_method_check, ce);
do_inherit_parent_constructor(ce);
Modified: php/php-src/branches/PHP_5_3/Zend/zend_compile.c
===================================================================
--- php/php-src/branches/PHP_5_3/Zend/zend_compile.c 2010-08-11 08:57:34 UTC (rev 302103)
+++ php/php-src/branches/PHP_5_3/Zend/zend_compile.c 2010-08-11 09:38:41 UTC (rev 302104)
@@ -2817,6 +2817,26 @@
}
/* }}} */
+#ifdef ZTS
+static void zval_internal_ctor(zval **p) /* {{{ */
+{
+ zval *orig_ptr = *p;
+
+ ALLOC_ZVAL(*p);
+ **p = *orig_ptr;
+ zval_copy_ctor(*p);
+ Z_SET_REFCOUNT_PP(p, 1);
+ Z_UNSET_ISREF_PP(p);
+}
+/* }}} */
+
+# 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)
@@ -2840,7 +2860,7 @@
zend_do_inherit_interfaces(ce, parent_ce TSRMLS_CC);
/* Inherit properties */
- zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, (void
(*)(void *)) zval_add_ref, NULL, sizeof(zval *), 0);
+ zend_hash_merge(&ce->default_properties, &parent_ce->default_properties,
zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
if (parent_ce->type != ce->type) {
/* User class extends internal class */
zend_update_class_constants(parent_ce TSRMLS_CC);
@@ -2850,7 +2870,7 @@
}
zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info,
(copy_ctor_func_t) (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal :
zend_duplicate_property_info), sizeof(zend_property_info), (merge_checker_func_t)
do_inherit_property_access_check, ce);
- zend_hash_merge(&ce->constants_table, &parent_ce->constants_table, (void (*)(void
*)) zval_add_ref, NULL, sizeof(zval *), 0);
+ zend_hash_merge(&ce->constants_table, &parent_ce->constants_table,
zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
zend_hash_merge_ex(&ce->function_table, &parent_ce->function_table,
(copy_ctor_func_t) do_inherit_method, sizeof(zend_function), (merge_checker_func_t)
do_inherit_method_check, ce);
do_inherit_parent_constructor(ce);
Modified: php/php-src/trunk/Zend/zend_compile.c
===================================================================
--- php/php-src/trunk/Zend/zend_compile.c 2010-08-11 08:57:34 UTC (rev 302103)
+++ php/php-src/trunk/Zend/zend_compile.c 2010-08-11 09:38:41 UTC (rev 302104)
@@ -3150,20 +3150,23 @@
}
/* }}} */
-static int inherit_static_prop(zval **p TSRMLS_DC, int num_args, va_list args, const zend_hash_key
*key) /* {{{ */
+#ifdef ZTS
+static void zval_internal_ctor(zval **p) /* {{{ */
{
- HashTable *target = va_arg(args, HashTable*);
+ zval *orig_ptr = *p;
- if (!zend_hash_quick_exists(target, key->arKey, key->nKeyLength, key->h)) {
- SEPARATE_ZVAL_TO_MAKE_IS_REF(p);
- if (zend_hash_quick_add(target, key->arKey, key->nKeyLength, key->h, p, sizeof(zval*),
NULL) == SUCCESS) {
- Z_ADDREF_PP(p);
- }
- }
- return ZEND_HASH_APPLY_KEEP;
+ ALLOC_ZVAL(*p);
+ MAKE_COPY_ZVAL(&orig_ptr, *p);
}
/* }}} */
+# 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) /*
{{{ */
{
zend_property_info *property_info;
@@ -3201,7 +3204,19 @@
for (i = 0; i < parent_ce->default_properties_count; i++) {
ce->default_properties_table[i] = parent_ce->default_properties_table[i];
if (ce->default_properties_table[i]) {
+#ifdef ZTS
+ if (parent_ce->type != ce->type) {
+ zval *p;
+
+ ALLOC_ZVAL(p);
+ MAKE_COPY_ZVAL(&ce->default_properties_table[i], p);
+ ce->default_properties_table[i] = p;
+ } else {
+ Z_ADDREF_P(ce->default_properties_table[i]);
+ }
+#else
Z_ADDREF_P(ce->default_properties_table[i]);
+#endif
}
}
ce->default_properties_count += parent_ce->default_properties_count;
@@ -3263,7 +3278,7 @@
zend_hash_merge_ex(&ce->properties_info, &parent_ce->properties_info,
(copy_ctor_func_t) (ce->type & ZEND_INTERNAL_CLASS ? zend_duplicate_property_info_internal :
zend_duplicate_property_info), sizeof(zend_property_info), (merge_checker_func_t)
do_inherit_property_access_check, ce);
- zend_hash_merge(&ce->constants_table, &parent_ce->constants_table, (void (*)(void
*)) zval_add_ref, NULL, sizeof(zval *), 0);
+ zend_hash_merge(&ce->constants_table, &parent_ce->constants_table,
zval_property_ctor(parent_ce, ce), NULL, sizeof(zval *), 0);
zend_hash_merge_ex(&ce->function_table, &parent_ce->function_table,
(copy_ctor_func_t) do_inherit_method, sizeof(zend_function), (merge_checker_func_t)
do_inherit_method_check, ce);
do_inherit_parent_constructor(ce);