Converting from reference to regular value

This commit is contained in:
Dmitry Stogov 2014-02-28 11:03:05 +04:00
parent 855a030b7b
commit 54095e8c56
4 changed files with 20 additions and 3 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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)
{

View File

@ -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()