Skip to content

Commit 018bcc6

Browse files
committed
Use temporary debug_info for closures
1 parent 6c98024 commit 018bcc6

File tree

1 file changed

+39
-53
lines changed

1 file changed

+39
-53
lines changed

Zend/zend_closures.c

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ typedef struct _zend_closure {
3838
zend_object std;
3939
zend_function func;
4040
zval this_ptr;
41-
HashTable *debug_info;
4241
} zend_closure;
4342

4443
/* non-static since it needs to be referenced */
@@ -269,11 +268,6 @@ static void zend_closure_free_storage(zend_object *object) /* {{{ */
269268
destroy_op_array(&closure->func.op_array);
270269
}
271270

272-
if (closure->debug_info != NULL) {
273-
zend_hash_destroy(closure->debug_info);
274-
efree(closure->debug_info);
275-
}
276-
277271
if (Z_TYPE(closure->this_ptr) != IS_UNDEF) {
278272
zval_ptr_dtor(&closure->this_ptr);
279273
}
@@ -335,71 +329,63 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp) /* {{{
335329
zend_closure *closure = (zend_closure *)Z_OBJ_P(object);
336330
zval val;
337331
struct _zend_arg_info *arg_info = closure->func.common.arg_info;
332+
HashTable *debug_info;
333+
334+
*is_temp = 1;
338335

339-
*is_temp = 0;
336+
ALLOC_HASHTABLE(debug_info);
337+
zend_hash_init(debug_info, 8, NULL, ZVAL_PTR_DTOR, 0);
340338

341-
if (closure->debug_info == NULL) {
342-
ALLOC_HASHTABLE(closure->debug_info);
343-
zend_hash_init(closure->debug_info, 8, NULL, ZVAL_PTR_DTOR, 0);
339+
if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) {
340+
HashTable *static_variables = closure->func.op_array.static_variables;
341+
ZVAL_ARR(&val, zend_array_dup(static_variables));
342+
zend_hash_str_update(debug_info, "static", sizeof("static")-1, &val);
344343
}
345-
if (closure->debug_info->u.v.nApplyCount == 0) {
346-
if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) {
347-
HashTable *static_variables = closure->func.op_array.static_variables;
348-
ZVAL_ARR(&val, zend_array_dup(static_variables));
349-
zend_hash_str_update(closure->debug_info, "static", sizeof("static")-1, &val);
350-
}
351344

352-
if (Z_TYPE(closure->this_ptr) != IS_UNDEF) {
353-
Z_ADDREF(closure->this_ptr);
354-
zend_hash_str_update(closure->debug_info, "this", sizeof("this")-1, &closure->this_ptr);
355-
}
345+
if (Z_TYPE(closure->this_ptr) != IS_UNDEF) {
346+
Z_ADDREF(closure->this_ptr);
347+
zend_hash_str_update(debug_info, "this", sizeof("this")-1, &closure->this_ptr);
348+
}
356349

357-
if (arg_info &&
358-
(closure->func.common.num_args ||
359-
(closure->func.common.fn_flags & ZEND_ACC_VARIADIC))) {
360-
uint32_t i, num_args, required = closure->func.common.required_num_args;
350+
if (arg_info &&
351+
(closure->func.common.num_args ||
352+
(closure->func.common.fn_flags & ZEND_ACC_VARIADIC))) {
353+
uint32_t i, num_args, required = closure->func.common.required_num_args;
361354

362-
array_init(&val);
355+
array_init(&val);
363356

364-
num_args = closure->func.common.num_args;
365-
if (closure->func.common.fn_flags & ZEND_ACC_VARIADIC) {
366-
num_args++;
367-
}
368-
for (i = 0; i < num_args; i++) {
369-
zend_string *name;
370-
zval info;
371-
if (arg_info->name) {
372-
name = zend_strpprintf(0, "%s$%s",
373-
arg_info->pass_by_reference ? "&" : "",
374-
arg_info->name->val);
375-
} else {
376-
name = zend_strpprintf(0, "%s$param%d",
377-
arg_info->pass_by_reference ? "&" : "",
378-
i + 1);
379-
}
380-
ZVAL_NEW_STR(&info, zend_strpprintf(0, "%s", i >= required ? "<optional>" : "<required>"));
381-
zend_hash_update(Z_ARRVAL(val), name, &info);
382-
zend_string_release(name);
383-
arg_info++;
357+
num_args = closure->func.common.num_args;
358+
if (closure->func.common.fn_flags & ZEND_ACC_VARIADIC) {
359+
num_args++;
360+
}
361+
for (i = 0; i < num_args; i++) {
362+
zend_string *name;
363+
zval info;
364+
if (arg_info->name) {
365+
name = zend_strpprintf(0, "%s$%s",
366+
arg_info->pass_by_reference ? "&" : "",
367+
arg_info->name->val);
368+
} else {
369+
name = zend_strpprintf(0, "%s$param%d",
370+
arg_info->pass_by_reference ? "&" : "",
371+
i + 1);
384372
}
385-
zend_hash_str_update(closure->debug_info, "parameter", sizeof("parameter")-1, &val);
373+
ZVAL_NEW_STR(&info, zend_strpprintf(0, "%s", i >= required ? "<optional>" : "<required>"));
374+
zend_hash_update(Z_ARRVAL(val), name, &info);
375+
zend_string_release(name);
376+
arg_info++;
386377
}
378+
zend_hash_str_update(debug_info, "parameter", sizeof("parameter")-1, &val);
387379
}
388380

389-
return closure->debug_info;
381+
return debug_info;
390382
}
391383
/* }}} */
392384

393385
static HashTable *zend_closure_get_gc(zval *obj, zval **table, int *n) /* {{{ */
394386
{
395387
zend_closure *closure = (zend_closure *)Z_OBJ_P(obj);
396388

397-
if (closure->debug_info != NULL) {
398-
zend_hash_destroy(closure->debug_info);
399-
efree(closure->debug_info);
400-
closure->debug_info = NULL;
401-
}
402-
403389
*table = Z_TYPE(closure->this_ptr) != IS_NULL ? &closure->this_ptr : NULL;
404390
*n = Z_TYPE(closure->this_ptr) != IS_NULL ? 1 : 0;
405391
return (closure->func.type == ZEND_USER_FUNCTION) ?

0 commit comments

Comments
 (0)