Skip to content

Commit 8d11699

Browse files
committed
Only allocate new arg_infos if types are being resolved
1 parent b4a63c5 commit 8d11699

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Zend/zend_inheritance.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,16 +1981,23 @@ static void zend_resolve_trait_relative_class_types(zend_function *const fn, con
19811981
/* Variadic parameters are not counted as part of the standard number of arguments */
19821982
bool has_variadic_type = fn->common.fn_flags & ZEND_ACC_VARIADIC;
19831983
uint32_t num_args = fn->common.num_args + has_variadic_type;
1984-
/* TODO Only do allocation if need to resolve types, as arg_info is stored in SHM */
19851984
size_t allocated_size = sizeof(zend_arg_info) * (has_return_type + num_args);
19861985

1987-
zend_arg_info *new_arg_infos = zend_arena_alloc(&CG(arena), allocated_size);
1988-
memcpy(new_arg_infos, fn->common.arg_info - has_return_type, allocated_size);
1989-
fn->common.arg_info = new_arg_infos + has_return_type;
1986+
zend_arg_info *new_arg_infos = fn->common.arg_info - has_return_type;
1987+
bool has_resolved_type = false;
19901988

19911989
for (uint32_t i = 0; i < num_args + has_return_type; i++) {
19921990
zend_type type = new_arg_infos[i].type;
1993-
new_arg_infos[i].type = zend_resolve_single_type(type, ce);
1991+
zend_type resolved_type = zend_resolve_single_type(type, ce);
1992+
if (type.ptr != resolved_type.ptr) {
1993+
if (!has_resolved_type) {
1994+
new_arg_infos = zend_arena_alloc(&CG(arena), allocated_size);
1995+
memcpy(new_arg_infos, fn->common.arg_info - has_return_type, allocated_size);
1996+
fn->common.arg_info = new_arg_infos + has_return_type;
1997+
has_resolved_type = true;
1998+
}
1999+
new_arg_infos[i].type = resolved_type;
2000+
}
19942001
}
19952002
}
19962003

0 commit comments

Comments
 (0)