Skip to content

Commit e489fd8

Browse files
committed
Use arena allocator for inherited trait constants
1 parent 5d3f66e commit e489fd8

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
@@ -1621,7 +1621,7 @@ static bool do_inherit_constant_check(
16211621
}
16221622
/* }}} */
16231623

1624-
static void do_inherit_interface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
1624+
static void do_inherit_iface_constant(zend_string *name, zend_class_constant *c, zend_class_entry *ce, zend_class_entry *iface) /* {{{ */
16251625
{
16261626
if (do_inherit_constant_check(ce, c, name)) {
16271627
zend_class_constant *ct;
@@ -1653,7 +1653,7 @@ static void do_interface_implementation(zend_class_entry *ce, zend_class_entry *
16531653
zend_class_constant *c;
16541654

16551655
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->constants_table, key, c) {
1656-
do_inherit_interface_constant(key, c, ce, iface);
1656+
do_inherit_iface_constant(key, c, ce, iface);
16571657
} ZEND_HASH_FOREACH_END();
16581658

16591659
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&iface->function_table, key, func) {
@@ -2206,22 +2206,19 @@ static void do_inherit_trait_constant(zend_string *name, zend_class_constant *c,
22062206
{
22072207
if (do_trait_constant_check(ce, c, name, traits, current_trait)) {
22082208
zend_class_constant *ct = NULL;
2209+
2210+
ct = zend_arena_alloc(&CG(arena),sizeof(zend_class_constant));
2211+
memcpy(ct, c, sizeof(zend_class_constant));
2212+
c = ct;
2213+
22092214
if (Z_TYPE(c->value) == IS_CONSTANT_AST) {
22102215
ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
22112216
ce->ce_flags |= ZEND_ACC_HAS_AST_CONSTANTS;
22122217
if (traits[current_trait]->ce_flags & ZEND_ACC_IMMUTABLE) {
2213-
ct = zend_arena_alloc(&CG(arena), sizeof(zend_class_constant));
2214-
memcpy(ct, c, sizeof(zend_class_constant));
2215-
Z_CONSTANT_FLAGS(ct->value) |= CONST_OWNED;
2218+
Z_CONSTANT_FLAGS(c->value) |= CONST_OWNED;
22162219
}
22172220
}
22182221

2219-
if (!ct) {
2220-
ct = emalloc(sizeof(zend_class_constant));
2221-
memcpy(ct, c, sizeof(zend_class_constant));
2222-
}
2223-
c = ct;
2224-
22252222
c->ce = ce;
22262223
Z_TRY_ADDREF(c->value);
22272224
c->doc_comment = c->doc_comment ? zend_string_copy(c->doc_comment) : NULL;
@@ -2274,7 +2271,7 @@ static void zend_do_traits_property_and_constant_binding(zend_class_entry *ce, z
22742271
if ((colliding_prop->flags & flags_mask) == (flags & flags_mask) &&
22752272
property_types_compatible(property_info, colliding_prop) == INHERITANCE_SUCCESS
22762273
) {
2277-
/* the flags are identical, thus, the properties may be is_compatible */
2274+
/* the flags are identical, thus, the properties may be compatible */
22782275
zval *op1, *op2;
22792276

22802277
if (flags & ZEND_ACC_STATIC) {

0 commit comments

Comments
 (0)