com php-src: Converting from reference to regular value: Zend/zend_compile.c Zend/zend_objects.c Zend/zend _variables.c Zend/zend_variables.h
| From: | Dmitry Stogov | Date: | Fri, 28 Feb 2014 07:03:05 +0000 |
| Subject: | com php-src: Converting from reference to regular value: Zend/zend_compile.c Zend/zend_objects.c Zend/zend _variables.c Zend/zend_variables.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-77874@lists.php.net to get a copy of this message | ||
Commit: 54095e8c564e1a5ddb4457cfa47874523e6eda6e
Author: Dmitry Stogov <dmitry@zend.com> Fri, 28 Feb 2014 11:03:05 +0400
Parents: 855a030b7b49db58cc203f2ecdc6bdfadf3ed539
Branches: phpng
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=54095e8c564e1a5ddb4457cfa47874523e6eda6e
Log:
Converting from reference to regular value
Changed paths:
M Zend/zend_compile.c
M Zend/zend_objects.c
M Zend/zend_variables.c
M Zend/zend_variables.h
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index c370a05..435ab51 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -3076,7 +3076,7 @@ ZEND_API void function_add_ref(zend_function *function) /* {{{ */
ALLOC_HASHTABLE(op_array->static_variables);
zend_hash_init(op_array->static_variables, zend_hash_num_elements(static_variables), NULL,
ZVAL_PTR_DTOR, 0);
- zend_hash_copy(op_array->static_variables, static_variables, zval_add_ref);
+ zend_hash_copy(op_array->static_variables, static_variables, zval_add_ref_unref);
}
op_array->run_time_cache = NULL;
}
diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c
index 5b6bd5e..6ac237a 100644
--- a/Zend/zend_objects.c
+++ b/Zend/zend_objects.c
@@ -150,7 +150,7 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object *o
ALLOC_HASHTABLE(new_object->properties);
zend_hash_init(new_object->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
}
- zend_hash_copy(new_object->properties, old_object->properties, zval_add_ref);
+ zend_hash_copy(new_object->properties, old_object->properties, zval_add_ref_unref);
if (old_object->properties_table) {
HashPosition pos;
zval *prop;
diff --git a/Zend/zend_variables.c b/Zend/zend_variables.c
index a3d768d..5292cf9 100644
--- a/Zend/zend_variables.c
+++ b/Zend/zend_variables.c
@@ -187,11 +187,26 @@ ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC)
ZEND_API void zval_add_ref(zval *p)
{
- if (Z_REFCOUNTED_P(p)) {
+ if (Z_REFCOUNTED_P(p)) {
Z_ADDREF_P(p);
}
}
+ZEND_API void zval_add_ref_unref(zval *p)
+{
+ if (Z_REFCOUNTED_P(p)) {
+ if (Z_ISREF_P(p)) {
+ if (Z_REFCOUNT_P(p) == 1) {
+ zval *q = Z_REFVAL_P(p);
+ ZVAL_DUP(p, q);
+ } else {
+ Z_ADDREF_P(p);
+ }
+ } else {
+ Z_ADDREF_P(p);
+ }
+ }
+}
ZEND_API void _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
{
diff --git a/Zend/zend_variables.h b/Zend/zend_variables.h
index ab5c5b3..2e2b183 100644
--- a/Zend/zend_variables.h
+++ b/Zend/zend_variables.h
@@ -78,6 +78,8 @@ ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zvalue);
#endif
ZEND_API void zval_add_ref(zval *p);
+//??? previously references become regular values when refcount became 1
+ZEND_API void zval_add_ref_unref(zval *p);
END_EXTERN_C()