Skip to content

Commit 2843053

Browse files
committed
Use arena allocator for inherited trait constants
1 parent 95fe7d1 commit 2843053

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

Zend/zend_inheritance.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ static bool do_inherit_constant_check(
16901690
}
16911691
/* }}} */
16921692

1693-
static void do_inherit_interface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
1693+
static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
16941694
{
16951695
if (do_inherit_constant_check(ce, c, name)) {
16961696
zend_class_constant *ct;
@@ -1722,7 +1722,7 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
17221722
zend_class_constant *c;
17231723

17241724
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) {
1725-
do_inherit_interface_constant(key, c, ce, iface);
1725+
do_inherit_iface_constant(key, c, ce, iface);
17261726
} ZEND_HASH_FOREACH_END();
17271727

17281728
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->function_table, key, func) {
@@ -2275,22 +2275,19 @@ static void do_inherit_trait_constant(zend_string *name, zend_class_constant *c,
22752275
{
22762276
if (do_trait_constant_check(ce, c, name, traits, current_trait)) {
22772277
zend_class_constant *ct = NULL;
2278+
2279+
ct = zend_arena_alloc(&CG(arena),sizeof(zend_class_constant));
2280+
memcpy(ct, c, sizeof(zend_class_constant));
2281+
c = ct;
2282+
22782283
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
22792284
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
22802285
ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
22812286
if (traits[current_trait]->ce_flags & ZEND_ACC_IMMUTABLE) {
2282-
ct = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
2283-
memcpy(ct, c, sizeof(zend_class_constant));
2284-
Z_CONSTANT_FLAGS(ct->value) |= CONST_OWNED;
2287+
Z_CONSTANT_FLAGS(c->value) |= CONST_OWNED;
22852288
}
22862289
}
22872290

2288-
if (!ct) {
2289-
ct = emalloc(sizeof(zend_class_constant));
2290-
memcpy(ct, c, sizeof(zend_class_constant));
2291-
}
2292-
c = ct;
2293-
22942291
c->ce = ce;
22952292
Z_TRY_ADDREF(c->value);
22962293
c->doc_comment = c->doc_comment ? zend_string_copy(c->doc_comment) : NULL;
@@ -2343,7 +2340,7 @@ static void zend_do_traits_property_and_constant_binding(zend_class_entry *ce, z
23432340
if ((colliding_prop->flags & flags_mask) == (flags & flags_mask) &&
23442341
property_types_compatible(property_info, colliding_prop) == INHERITANCE_SUCCESS
23452342
) {
2346-
/* the flags are identical, thus, the properties may be is_compatible */
2343+
/* the flags are identical, thus, the properties may be compatible */
23472344
zval *op1, *op2;
23482345

23492346
if (flags & ZEND_ACC_STATIC) {

0 commit comments

Comments
 (0)