com php-src: Add zend_update_static_property_ex API : Zend/zend_API.c Zend/zend_API.h ext/reflectio n/php_reflection.c

From: Date: Fri, 29 Jun 2018 20:56:59 +0000
Subject: com php-src: Add zend_update_static_property_ex API : Zend/zend_API.c Zend/zend_API.h ext/reflectio n/php_reflection.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-102330@lists.php.net to get a copy of this message
Commit: 7ac06d66d4e19dc68b0440aff27f2a405354e5d6 Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 29 Jun 2018 22:56:47 +0200 Parents: 813b6fc95050b32409014877e7dc9849c16717ee Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7ac06d66d4e19dc68b0440aff27f2a405354e5d6 Log: Add zend_update_static_property_ex API And cleanup the implementation to perform a normal by-value assignment. Changed paths: M Zend/zend_API.c M Zend/zend_API.h M ext/reflection/php_reflection.c Diff: diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 98312b3..7e440ee 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -4049,42 +4049,37 @@ ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object } /* }}} */ -ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value) /* {{{ */ +ZEND_API int zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value) /* {{{ */ { zval *property; zend_class_entry *old_scope = EG(fake_scope); - zend_string *key = zend_string_init(name, name_length, 0); EG(fake_scope) = scope; - property = zend_std_get_static_property(scope, key, 0); + property = zend_std_get_static_property(scope, name, 0); EG(fake_scope) = old_scope; - zend_string_efree(key); + if (!property) { return FAILURE; - } else { - if (property != value) { - if (Z_ISREF_P(property)) { - zval_dtor(property); - ZVAL_COPY_VALUE(property, value); - if (Z_REFCOUNTED_P(value) && Z_REFCOUNT_P(value) > 0) { - zval_opt_copy_ctor(property); - } - } else { - zval garbage; + } - ZVAL_COPY_VALUE(&garbage, property); - if (Z_REFCOUNTED_P(value)) { - Z_ADDREF_P(value); - if (Z_ISREF_P(value)) { - SEPARATE_ZVAL(value); - } - } - ZVAL_COPY_VALUE(property, value); - zval_ptr_dtor(&garbage); - } - } - return SUCCESS; + if (property != value) { + zval garbage; + ZVAL_DEREF(property); + ZVAL_DEREF(value); + ZVAL_COPY_VALUE(&garbage, property); + ZVAL_COPY(property, value); + zval_ptr_dtor(&garbage); } + return SUCCESS; +} +/* }}} */ + +ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value) /* {{{ */ +{ + zend_string *key = zend_string_init(name, name_length, 0); + int retval = zend_update_static_property_ex(scope, key, value); + zend_string_efree(key); + return retval; } /* }}} */ diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 64a6bde..63c82a4 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -345,6 +345,7 @@ ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value, size_t value_length); ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length); +ZEND_API int zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value); ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value); ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length); ZEND_API int zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value); diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e7bfb27..4f46bd1 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -5533,7 +5533,6 @@ ZEND_METHOD(reflection_property, setValue) { reflection_object *intern; property_reference *ref; - zval *variable_ptr; zval *object, *name; zval *value; zval *tmp; @@ -5549,26 +5548,13 @@ ZEND_METHOD(reflection_property, setValue) } if (ref->prop.flags & ZEND_ACC_STATIC) { - zend_class_entry *old_scope; - zval garbage; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "z", &value) == FAILURE) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &tmp, &value) == FAILURE) { return; } } - old_scope = EG(fake_scope); - EG(fake_scope) = ref->ce; - variable_ptr = zend_std_get_static_property(ref->ce, ref->unmangled_name, 0); - EG(fake_scope) = old_scope; - - ZVAL_DEREF(variable_ptr); - ZVAL_DEREF(value); - - ZVAL_COPY_VALUE(&garbage, variable_ptr); - ZVAL_COPY(variable_ptr, value); - zval_ptr_dtor(&garbage); + zend_update_static_property_ex(ref->ce, ref->unmangled_name, value); } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "oz", &object, &value) == FAILURE) { return;

« previous php.cvs (#102330) next »