Skip to content

Commit 4edfd87

Browse files
committed
Only allocate new arg_infos if types are being resolved
1 parent 62aa531 commit 4edfd87

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
@@ -2029,16 +2029,23 @@ static void zend_resolve_trait_relative_class_types(zend_function *const fn, con
20292029
/* Variadic parameters are not counted as part of the standard number of arguments */
20302030
bool has_variadic_type = fn->common.fn_flags & ZEND_ACC_VARIADIC;
20312031
uint32_t num_args = fn->common.num_args + has_variadic_type;
2032-
/* TODO Only do allocation if need to resolve types, as arg_info is stored in SHM */
20332032
size_t allocated_size = sizeof(zend_arg_info) * (has_return_type + num_args);
20342033

2035-
zend_arg_info *new_arg_infos = zend_arena_alloc(&CG(arena), allocated_size);
2036-
memcpy(new_arg_infos, fn->common.arg_info - has_return_type, allocated_size);
2037-
fn->common.arg_info = new_arg_infos + has_return_type;
2034+
zend_arg_info *new_arg_infos = fn->common.arg_info - has_return_type;
2035+
bool has_resolved_type = false;
20382036

20392037
for (uint32_t i = 0; i < num_args + has_return_type; i++) {
20402038
zend_type type = new_arg_infos[i].type;
2041-
new_arg_infos[i].type = zend_resolve_single_type(type, ce);
2039+
zend_type resolved_type = zend_resolve_single_type(type, ce);
2040+
if (type.ptr != resolved_type.ptr) {
2041+
if (!has_resolved_type) {
2042+
new_arg_infos = zend_arena_alloc(&CG(arena), allocated_size);
2043+
memcpy(new_arg_infos, fn->common.arg_info - has_return_type, allocated_size);
2044+
fn->common.arg_info = new_arg_infos + has_return_type;
2045+
has_resolved_type = true;
2046+
}
2047+
new_arg_infos[i].type = resolved_type;
2048+
}
20422049
}
20432050
}
20442051

0 commit comments

Comments
 (0)