-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Use the same zend_arg_info struct for internal and user functions #19022
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for having a look at this, I'm overall in favour of unifying those, as it makes it easier to reason about.
See some of my comments, which are mostly nits. :)
@@ -790,17 +785,15 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_ | |||
if (ZEND_ARG_IS_VARIADIC(arg_info)) { | |||
smart_str_appends(str, "..."); | |||
} | |||
smart_str_append_printf(str, "$%s", has_internal_arg_info(fptr) | |||
? ((zend_internal_arg_info*)arg_info)->name : ZSTR_VAL(arg_info->name)); | |||
smart_str_append_printf(str, "$%s", ZSTR_VAL(arg_info->name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do this with a printf? Can't we just append a char and then the zend_string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, but I want to avoid changes that are not directly related
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, let's keep this for a follow-up then :)
if (arginfo) { | ||
if (func->type == ZEND_INTERNAL_FUNCTION) { | ||
arg_name = (char *) ((zend_internal_arg_info *) &arginfo[i])->name; | ||
} else { | ||
arg_name = ZSTR_VAL(arginfo[i].name); | ||
} | ||
arg_name = ZSTR_VAL(arginfo[i].name); | ||
} | ||
smart_str_appends(s, arg_name ? arg_name : "?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be improved to prevent a strlen computation within the smart_str_appends.
Co-authored-by: Gina Peter Banyard <[email protected]>
Zend/zend_API.c
Outdated
void zend_convert_internal_arg_info(zend_arg_info *new_arg_info, const zend_internal_arg_info *arg_info, bool is_return_info) | ||
{ | ||
if (!is_return_info) { | ||
new_arg_info->name = zend_string_init_interned(arg_info->name, strlen(arg_info->name), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should pass true
instead of 1
(same elsewhere).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! I never remember which functions were converted to bool.
You can probably get rid of ZEND_ACC_USER_ARG_INFO |
Right :) I wanted to do it, but it's not trivial because the flag is also used to signal how arg default values should be fetched. I may try to remove it later. |
#endif | ||
return get_default_via_ast(default_value_zval, default_value); | ||
return get_default_via_ast(default_value_zval, ZSTR_VAL(default_value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a follow-up, the get_default_via_ast()
function should be changed to accept a zend_string to get rid of an unnecessary strlen()
computation :)
This does seem to have a negative impact on the Valgrind instruction counts though. Probably because of the slightly higher memory requirement if you have the zend_string header too. |
@@ -790,17 +785,15 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_ | |||
if (ZEND_ARG_IS_VARIADIC(arg_info)) { | |||
smart_str_appends(str, "..."); | |||
} | |||
smart_str_append_printf(str, "$%s", has_internal_arg_info(fptr) | |||
? ((zend_internal_arg_info*)arg_info)->name : ZSTR_VAL(arg_info->name)); | |||
smart_str_append_printf(str, "$%s", ZSTR_VAL(arg_info->name)); | |||
|
|||
if (!required && !ZEND_ARG_IS_VARIADIC(arg_info)) { | |||
if (fptr->type == ZEND_INTERNAL_FUNCTION) { | |||
smart_str_appends(str, " = "); | |||
/* TODO: We don't have a way to fetch the default value for an internal function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment still correct?
zend_type legacy_iterable = ZEND_TYPE_INIT_CLASS_MASK( | ||
ZSTR_KNOWN(ZEND_STR_TRAVERSABLE), | ||
(type->type_mask | MAY_BE_ARRAY) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest reducing indentation to match the indentation of the start
); | |
); |
@@ -917,4 +909,13 @@ void zend_closure_bind_var_ex(zval *closure_zv, uint32_t offset, zval *val) /* { | |||
zval_ptr_dtor(var); | |||
ZVAL_COPY_VALUE(var, val); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated newline addition
Internal functions use
char*
strings to represent arg names and default values. This differs from user functions, which use zend strings.Here I unify this by using the same struct,
zend_arg_info
in both function types.This simplifies accesses to arg infos. Also, in the PFAs RFC this avoids converting internal arg infos at runtime when applying an internal function.