Skip to content

zend_closures.c: Call closure directly #17372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ typedef struct _zend_closure {
ZEND_API zend_class_entry *zend_ce_closure;
static zend_object_handlers closure_handlers;

static zend_result zend_closure_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only);

ZEND_METHOD(Closure, __invoke) /* {{{ */
{
zend_function *func = EX(func);
Expand All @@ -51,9 +53,12 @@ ZEND_METHOD(Closure, __invoke) /* {{{ */
Z_PARAM_VARIADIC_WITH_NAMED(args, num_args, named_args)
ZEND_PARSE_PARAMETERS_END();

if (call_user_function_named(CG(function_table), NULL, ZEND_THIS, return_value, num_args, args, named_args) == FAILURE) {
RETVAL_FALSE;
}
zend_fcall_info_cache fcc = {
Copy link
Member

@iluuu1994 iluuu1994 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This causes some unnecessary initialization or most fields that are set later. It's probably elided if zend_closure_get_closure() is inlined though.

.closure = Z_OBJ_P(ZEND_THIS),
};
zend_closure_get_closure(Z_OBJ_P(ZEND_THIS), &fcc.calling_scope, &fcc.function_handler, &fcc.object, false);
fcc.called_scope = fcc.calling_scope;
zend_call_known_fcc(&fcc, return_value, num_args, args, named_args);

/* destruct the function also, then - we have allocated it in get_method */
zend_string_release_ex(func->internal_function.function_name, 0);
Expand Down
Loading