mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
Fixed string interning during constants substitution
This commit is contained in:
parent
a8a17a72b0
commit
e0924c52fc
3 changed files with 30 additions and 9 deletions
12
Zend/tests/class_constants_005.phpt
Normal file
12
Zend/tests/class_constants_005.phpt
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
--TEST--
|
||||||
|
String interning during constants substitution
|
||||||
|
--INI--
|
||||||
|
opcache.enable_cli=0
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
define ("A", "." . ord(26) . ".");
|
||||||
|
eval("class A {const a = A;}");
|
||||||
|
var_dump(A::a);
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
string(4) ".50."
|
|
@ -445,13 +445,21 @@ ZEND_API zend_constant* ZEND_FASTCALL zend_quick_get_constant(const zval *key, u
|
||||||
|
|
||||||
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
|
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
|
||||||
{
|
{
|
||||||
void *ret;
|
zval *ret, tmp;
|
||||||
zend_constant *copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
|
zend_constant *copy;
|
||||||
|
|
||||||
|
ZVAL_PTR(&tmp, NULL);
|
||||||
|
ret = zend_hash_add(ht, key, &tmp);
|
||||||
|
if (EXPECTED(ret)) {
|
||||||
|
Z_PTR_P(ret) = copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
|
||||||
memcpy(copy, c, sizeof(zend_constant));
|
memcpy(copy, c, sizeof(zend_constant));
|
||||||
ret = zend_hash_add_ptr(ht, key, copy);
|
if (Z_TYPE(copy->value) == IS_STRING && !ZSTR_IS_INTERNED(Z_STR(copy->value))) {
|
||||||
if (!ret) {
|
SEPARATE_STRING(©->value);
|
||||||
pefree(copy, c->flags & CONST_PERSISTENT);
|
Z_STR(copy->value) = zend_new_interned_string(Z_STR(copy->value));
|
||||||
|
if (ZSTR_IS_INTERNED(Z_STR(copy->value))) {
|
||||||
|
Z_TYPE_FLAGS(copy->value) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -466,9 +474,7 @@ ZEND_API int zend_register_constant(zend_constant *c)
|
||||||
printf("Registering constant for module %d\n", c->module_number);
|
printf("Registering constant for module %d\n", c->module_number);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (c->module_number != PHP_USER_CONSTANT) {
|
|
||||||
c->name = zend_new_interned_string(c->name);
|
c->name = zend_new_interned_string(c->name);
|
||||||
}
|
|
||||||
|
|
||||||
if (!(c->flags & CONST_CS)) {
|
if (!(c->flags & CONST_CS)) {
|
||||||
lowercase_name = zend_string_alloc(ZSTR_LEN(c->name), c->flags & CONST_PERSISTENT);
|
lowercase_name = zend_string_alloc(ZSTR_LEN(c->name), c->flags & CONST_PERSISTENT);
|
||||||
|
|
|
@ -644,6 +644,9 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
|
||||||
if (c->name) {
|
if (c->name) {
|
||||||
c->name = new_interned_string(c->name);
|
c->name = new_interned_string(c->name);
|
||||||
}
|
}
|
||||||
|
if (Z_TYPE(c->value) == IS_STRING) {
|
||||||
|
Z_STR(c->value) = new_interned_string(Z_STR(c->value));
|
||||||
|
}
|
||||||
} ZEND_HASH_FOREACH_END();
|
} ZEND_HASH_FOREACH_END();
|
||||||
|
|
||||||
/* auto globals hash keys and names */
|
/* auto globals hash keys and names */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue