Skip to content

Commit 1631e22

Browse files
committed
Add _ex() variants for zend_*_property_*() functions taking the name as a Zend string
Also fix type for bool version and add missing zend_string value for static properties.
1 parent 071bf46 commit 1631e22

File tree

2 files changed

+163
-14
lines changed

2 files changed

+163
-14
lines changed

Zend/zend_API.c

Lines changed: 145 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4697,6 +4697,30 @@ ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const cha
46974697
}
46984698
/* }}} */
46994699

4700+
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */
4701+
{
4702+
zend_string *property;
4703+
zend_class_entry *old_scope = EG(fake_scope);
4704+
4705+
EG(fake_scope) = scope;
4706+
4707+
property = zend_string_init(name, name_length, 0);
4708+
object->handlers->unset_property(object, property, 0);
4709+
zend_string_release_ex(property, 0);
4710+
4711+
EG(fake_scope) = old_scope;
4712+
}
4713+
/* }}} */
4714+
4715+
ZEND_API void zend_unset_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name)
4716+
{
4717+
zend_class_entry *old_scope = EG(fake_scope);
4718+
4719+
EG(fake_scope) = scope;
4720+
object->handlers->unset_property(object, name, 0);
4721+
EG(fake_scope) = old_scope;
4722+
}
4723+
47004724
ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value) /* {{{ */
47014725
{
47024726
zend_class_entry *old_scope = EG(fake_scope);
@@ -4733,29 +4757,30 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *ob
47334757
}
47344758
/* }}} */
47354759

4736-
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */
4760+
ZEND_API void zend_update_property_null_ex(zend_class_entry *scope, zend_object *object, zend_string *name)
47374761
{
4738-
zend_string *property;
4739-
zend_class_entry *old_scope = EG(fake_scope);
4762+
zval tmp;
47404763

4741-
EG(fake_scope) = scope;
4764+
ZVAL_NULL(&tmp);
4765+
zend_update_property_ex(scope, object, name, &tmp);
4766+
}
47424767

4743-
property = zend_string_init(name, name_length, 0);
4744-
object->handlers->unset_property(object, property, 0);
4745-
zend_string_release_ex(property, 0);
4768+
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool value) /* {{{ */
4769+
{
4770+
zval tmp;
47464771

4747-
EG(fake_scope) = old_scope;
4772+
ZVAL_BOOL(&tmp, value);
4773+
zend_update_property(scope, object, name, name_length, &tmp);
47484774
}
47494775
/* }}} */
47504776

4751-
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value) /* {{{ */
4777+
ZEND_API void zend_update_property_bool_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool value)
47524778
{
47534779
zval tmp;
47544780

47554781
ZVAL_BOOL(&tmp, value);
4756-
zend_update_property(scope, object, name, name_length, &tmp);
4782+
zend_update_property_ex(scope, object, name, &tmp);
47574783
}
4758-
/* }}} */
47594784

47604785
ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value) /* {{{ */
47614786
{
@@ -4766,6 +4791,14 @@ ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *ob
47664791
}
47674792
/* }}} */
47684793

4794+
ZEND_API void zend_update_property_long_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_long value)
4795+
{
4796+
zval tmp;
4797+
4798+
ZVAL_LONG(&tmp, value);
4799+
zend_update_property_ex(scope, object, name, &tmp);
4800+
}
4801+
47694802
ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value) /* {{{ */
47704803
{
47714804
zval tmp;
@@ -4775,6 +4808,14 @@ ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *
47754808
}
47764809
/* }}} */
47774810

4811+
ZEND_API void zend_update_property_double_ex(zend_class_entry *scope, zend_object *object, zend_string *name, double value)
4812+
{
4813+
zval tmp;
4814+
4815+
ZVAL_DOUBLE(&tmp, value);
4816+
zend_update_property_ex(scope, object, name, &tmp);
4817+
}
4818+
47784819
ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value) /* {{{ */
47794820
{
47804821
zval tmp;
@@ -4784,6 +4825,14 @@ ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *obj
47844825
}
47854826
/* }}} */
47864827

4828+
ZEND_API void zend_update_property_str_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_string *value)
4829+
{
4830+
zval tmp;
4831+
4832+
ZVAL_STR(&tmp, value);
4833+
zend_update_property_ex(scope, object, name, &tmp);
4834+
}
4835+
47874836
ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value) /* {{{ */
47884837
{
47894838
zval tmp;
@@ -4794,6 +4843,15 @@ ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *
47944843
}
47954844
/* }}} */
47964845

4846+
ZEND_API void zend_update_property_string_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value)
4847+
{
4848+
zval tmp;
4849+
4850+
ZVAL_STRING(&tmp, value);
4851+
Z_SET_REFCOUNT(tmp, 0);
4852+
zend_update_property_ex(scope, object, name, &tmp);
4853+
}
4854+
47974855
ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */
47984856
{
47994857
zval tmp;
@@ -4804,6 +4862,15 @@ ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object
48044862
}
48054863
/* }}} */
48064864

4865+
ZEND_API void zend_update_property_stringl_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value, size_t value_len)
4866+
{
4867+
zval tmp;
4868+
4869+
ZVAL_STRINGL(&tmp, value, value_len);
4870+
Z_SET_REFCOUNT(tmp, 0);
4871+
zend_update_property_ex(scope, object, name, &tmp);
4872+
}
4873+
48074874
ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value) /* {{{ */
48084875
{
48094876
zval *property, tmp;
@@ -4858,7 +4925,15 @@ ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, c
48584925
}
48594926
/* }}} */
48604927

4861-
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */
4928+
ZEND_API zend_result zend_update_static_property_null_ex(zend_class_entry *scope, zend_string *name)
4929+
{
4930+
zval tmp;
4931+
4932+
ZVAL_NULL(&tmp);
4933+
return zend_update_static_property_ex(scope, name, &tmp);
4934+
}
4935+
4936+
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, bool value) /* {{{ */
48624937
{
48634938
zval tmp;
48644939

@@ -4867,6 +4942,14 @@ ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, c
48674942
}
48684943
/* }}} */
48694944

4945+
ZEND_API zend_result zend_update_static_property_bool_ex(zend_class_entry *scope, zend_string *name, bool value)
4946+
{
4947+
zval tmp;
4948+
4949+
ZVAL_BOOL(&tmp, value);
4950+
return zend_update_static_property_ex(scope, name, &tmp);
4951+
}
4952+
48704953
ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value) /* {{{ */
48714954
{
48724955
zval tmp;
@@ -4876,6 +4959,14 @@ ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, c
48764959
}
48774960
/* }}} */
48784961

4962+
ZEND_API zend_result zend_update_static_property_long_ex(zend_class_entry *scope, zend_string *name, zend_long value)
4963+
{
4964+
zval tmp;
4965+
4966+
ZVAL_LONG(&tmp, value);
4967+
return zend_update_static_property_ex(scope, name, &tmp);
4968+
}
4969+
48794970
ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value) /* {{{ */
48804971
{
48814972
zval tmp;
@@ -4885,6 +4976,30 @@ ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope,
48854976
}
48864977
/* }}} */
48874978

4979+
ZEND_API zend_result zend_update_static_property_double_ex(zend_class_entry *scope, zend_string *name, double value)
4980+
{
4981+
zval tmp;
4982+
4983+
ZVAL_DOUBLE(&tmp, value);
4984+
return zend_update_static_property_ex(scope, name, &tmp);
4985+
}
4986+
4987+
ZEND_API zend_result zend_update_static_property_str(zend_class_entry *scope, const char *name, size_t name_length, zend_string *value)
4988+
{
4989+
zval tmp;
4990+
4991+
ZVAL_STR(&tmp, value);
4992+
return zend_update_static_property(scope, name, name_length, &tmp);
4993+
}
4994+
4995+
ZEND_API zend_result zend_update_static_property_str_ex(zend_class_entry *scope, zend_string *name, zend_string *value)
4996+
{
4997+
zval tmp;
4998+
4999+
ZVAL_STR(&tmp, value);
5000+
return zend_update_static_property_ex(scope, name, &tmp);
5001+
}
5002+
48885003
ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value) /* {{{ */
48895004
{
48905005
zval tmp;
@@ -4895,6 +5010,15 @@ ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope,
48955010
}
48965011
/* }}} */
48975012

5013+
ZEND_API zend_result zend_update_static_property_string_ex(zend_class_entry *scope, zend_string *name, const char *value)
5014+
{
5015+
zval tmp;
5016+
5017+
ZVAL_STRING(&tmp, value);
5018+
Z_SET_REFCOUNT(tmp, 0);
5019+
return zend_update_static_property_ex(scope, name, &tmp);
5020+
}
5021+
48985022
ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_len) /* {{{ */
48995023
{
49005024
zval tmp;
@@ -4905,6 +5029,15 @@ ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope
49055029
}
49065030
/* }}} */
49075031

5032+
ZEND_API zend_result zend_update_static_property_stringl_ex(zend_class_entry *scope, zend_string *name, const char *value, size_t value_len)
5033+
{
5034+
zval tmp;
5035+
5036+
ZVAL_STRINGL(&tmp, value, value_len);
5037+
Z_SET_REFCOUNT(tmp, 0);
5038+
return zend_update_static_property_ex(scope, name, &tmp);
5039+
}
5040+
49085041
ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv) /* {{{ */
49095042
{
49105043
zval *value;

Zend/zend_API.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,38 @@ static zend_always_inline HashTable *zend_class_backed_enum_table(zend_class_ent
490490
ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value);
491491
ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value);
492492
ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
493-
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
493+
ZEND_API void zend_update_property_null_ex(zend_class_entry *scope, zend_object *object, zend_string *name);
494+
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool value);
495+
ZEND_API void zend_update_property_bool_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool value);
494496
ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
497+
ZEND_API void zend_update_property_long_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_long value);
495498
ZEND_API void zend_update_property_double(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, double value);
499+
ZEND_API void zend_update_property_double_ex(zend_class_entry *scope, zend_object *object, zend_string *name, double value);
496500
ZEND_API void zend_update_property_str(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_string *value);
501+
ZEND_API void zend_update_property_str_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zend_string *value);
497502
ZEND_API void zend_update_property_string(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value);
503+
ZEND_API void zend_update_property_string_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value);
498504
ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, const char *value, size_t value_length);
505+
ZEND_API void zend_update_property_stringl_ex(zend_class_entry *scope, zend_object *object, zend_string *name, const char *value, size_t value_len);
499506
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length);
507+
ZEND_API void zend_unset_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name);
500508

501509
ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zend_string *name, zval *value);
502510
ZEND_API zend_result zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
503511
ZEND_API zend_result zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
504-
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
512+
ZEND_API zend_result zend_update_static_property_null_ex(zend_class_entry *scope, zend_string *name);
513+
ZEND_API zend_result zend_update_static_property_bool(zend_class_entry *scope, const char *name, size_t name_length, bool value);
514+
ZEND_API zend_result zend_update_static_property_bool_ex(zend_class_entry *scope, zend_string *name, bool value);
505515
ZEND_API zend_result zend_update_static_property_long(zend_class_entry *scope, const char *name, size_t name_length, zend_long value);
516+
ZEND_API zend_result zend_update_static_property_long_ex(zend_class_entry *scope, zend_string *name, zend_long value);
506517
ZEND_API zend_result zend_update_static_property_double(zend_class_entry *scope, const char *name, size_t name_length, double value);
518+
ZEND_API zend_result zend_update_static_property_double_ex(zend_class_entry *scope, zend_string *name, double value);
519+
ZEND_API zend_result zend_update_static_property_str(zend_class_entry *scope, const char *name, size_t name_length, zend_string *value);
520+
ZEND_API zend_result zend_update_static_property_str_ex(zend_class_entry *scope, zend_string *name, zend_string *value);
507521
ZEND_API zend_result zend_update_static_property_string(zend_class_entry *scope, const char *name, size_t name_length, const char *value);
522+
ZEND_API zend_result zend_update_static_property_string_ex(zend_class_entry *scope, zend_string *name, const char *value);
508523
ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope, const char *name, size_t name_length, const char *value, size_t value_length);
524+
ZEND_API zend_result zend_update_static_property_stringl_ex(zend_class_entry *scope, zend_string *name, const char *value, size_t value_len);
509525

510526
ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv);
511527
ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, bool silent, zval *rv);

0 commit comments

Comments
 (0)