com php-src: Make sure string property/class const values are interned: Zend/zend_API.c Zend/zend_compile.c
| From: | Nikita Popov | Date: | Sat, 25 Nov 2017 16:12:37 +0000 |
| Subject: | com php-src: Make sure string property/class const values are interned: Zend/zend_API.c Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-100370@lists.php.net to get a copy of this message | ||
Commit: 8795893f4f90a344cc9a9d48523b7aa0ba5ebf05
Author: Nikita Popov <nikita.ppv@gmail.com> Sat, 25 Nov 2017 13:31:18 +0100
Parents: c5767db441e4db2a1e07b5880129ad7ce0b25b6f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8795893f4f90a344cc9a9d48523b7aa0ba5ebf05
Log:
Make sure string property/class const values are interned
This was done for user-definde class constant values, however this
is also important for properties and internal classes..
Changed paths:
M Zend/zend_API.c
M Zend/zend_compile.c
Diff:
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index 03a0df9..53eca99 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -3616,6 +3616,16 @@ ZEND_API const char *zend_get_module_version(const char *module_name) /* {{{
*/
}
/* }}} */
+static inline zend_string *zval_make_interned_string(zval *zv) /* {{{ */
+{
+ ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
+ Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
+ if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
+ Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
+ }
+ return Z_STR_P(zv);
+}
+
ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string *name, zval *property, int
access_type, zend_string *doc_comment) /* {{{ */
{
zend_property_info *property_info, *property_info_ptr;
@@ -3632,6 +3642,10 @@ ZEND_API int zend_declare_property_ex(zend_class_entry *ce, zend_string
*name, z
}
}
+ if (Z_TYPE_P(property) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(property))) {
+ zval_make_interned_string(property);
+ }
+
if (!(access_type & ZEND_ACC_PPP_MASK)) {
access_type |= ZEND_ACC_PUBLIC;
}
@@ -3774,6 +3788,10 @@ ZEND_API int zend_declare_class_constant_ex(zend_class_entry *ce, zend_string
*n
"A class constant must not be called 'class'; it is reserved for class name
fetching");
}
+ if (Z_TYPE_P(value) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR_P(value))) {
+ zval_make_interned_string(value);
+ }
+
if (ce->type == ZEND_INTERNAL_CLASS) {
c = pemalloc(sizeof(zend_class_constant), 1);
} else {
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 4381a24..d4ec431 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -6064,9 +6064,6 @@ void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */
}
zend_const_expr_to_zval(&value_zv, value_ast);
- if (Z_TYPE(value_zv) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR(value_zv))) {
- zval_make_interned_string(&value_zv);
- }
zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment);
}
}