Skip to content

Commit

Permalink
Add zend_update_static_property_ex API
Browse files Browse the repository at this point in the history
And cleanup the implementation to perform a normal by-value
assignment.
  • Loading branch information
nikic committed Jun 29, 2018
1 parent 813b6fc commit 7ac06d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 41 deletions.
47 changes: 21 additions & 26 deletions Zend/zend_API.c
Expand Up @@ -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;
}
/* }}} */

Expand Down
1 change: 1 addition & 0 deletions Zend/zend_API.h
Expand Up @@ -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);
Expand Down
16 changes: 1 addition & 15 deletions ext/reflection/php_reflection.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 7ac06d6

Please sign in to comment.