Skip to content

Zend: Move FCI/FCC/callables related functions to a dedicated header and C file #12240

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Sep 18, 2023

This groups all related functions into one C file and gives a good overview of the API via the header, instead of it being spread around multiple different files.

I am currently not sure if I should not move zend_fcc_addref() and zend_call_known_fcc() to the .c file to reduce some header inclusions, as I'm not entirely sure if it makes a lot of sense for them to be always inlined.

Primary motivation

Having the FCI and FCC structures in their own header to be able to include them in zend_gc.h to be able to move zend_get_gc_buffer_add_fcc() into zend_gc.h as it is otherwise not very discoverable.

Future scope

Making the zend_is_callable_ex() private as it is only used by zend_call_function(), the non ex variant is used twice in php-src, however the PCNTL usage is bogus (as it doesn't do anything) and the usage in sapi_windows_set_ctrl_handler() is about not being able to attach the function, and could possibly be changed to be generic. Meaning, we could possibly also drop the non ex variant.

Another thing would be to drop the rather confusing FCI API which I started in #9723

One minor thing that may also be useful, is to drop the dependency on zend_API.h in the .c file to not have a circular dependency.

@iluuu1994
Copy link
Member

Is the motivation strong enough to move all this code? Merge conflicts are guaranteed, and git blame is broken. We also don't have a broader concept of how to structure things. There are many overlapping areas, it's not always clear where it belongs.

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

I don't understand the motivation of this code motion and I don't like to lose git history.
I'm against this kind of changes.

@Girgias
Copy link
Member Author

Girgias commented Sep 19, 2023

I don't understand the argument about the git history being lost, it still exists and even with git blame as the -C and -M options exist.

Using git blame -C Zend/zend_callables.h I get the following (truncated to show a relevant) output:

92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  26) typedef struct _zend_fcall_info {
92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  27)        size_t size;
f4cfaf36e23 Zend/zend_API.h         (Dmitry Stogov        2014-02-10 10:04:30 +0400  28)        zval function_name;
f4cfaf36e23 Zend/zend_API.h         (Dmitry Stogov        2014-02-10 10:04:30 +0400  29)        zval *retval;
f4cfaf36e23 Zend/zend_API.h         (Dmitry Stogov        2014-02-10 10:04:30 +0400  30)        zval *params;
ea85451b65b Zend/zend_API.h         (Dmitry Stogov        2014-03-28 02:11:22 +0400  31)        zend_object *object;
5d5a70205cf Zend/zend_API.h         (Anatol Belski        2014-09-12 16:23:24 +0200  32)        uint32_t param_count;
d92229d8c78 Zend/zend_API.h         (Nikita Popov         2020-04-06 12:46:52 +0200  33)        /* This hashtable can also contain positional arguments (with integer keys),
d92229d8c78 Zend/zend_API.h         (Nikita Popov         2020-04-06 12:46:52 +0200  34)         * which will be appended to the normal params[]. This makes it easier to
d92229d8c78 Zend/zend_API.h         (Nikita Popov         2020-04-06 12:46:52 +0200  35)         * integrate APIs like call_user_func_array(). The usual restriction that
d92229d8c78 Zend/zend_API.h         (Nikita Popov         2020-04-06 12:46:52 +0200  36)         * there may not be position arguments after named arguments applies. */
d92229d8c78 Zend/zend_API.h         (Nikita Popov         2020-04-06 12:46:52 +0200  37)        HashTable *named_params;
92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  38) } zend_fcall_info;
92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  39) 
92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  40) typedef struct _zend_fcall_info_cache {
92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  41)        zend_function *function_handler;
92b4013e8d6 Zend/zend_API.h         (Zeev Suraski         2003-08-05 10:24:40 +0000  42)        zend_class_entry *calling_scope;
feb85801667 Zend/zend_API.h         (Dmitry Stogov        2008-07-24 09:42:18 +0000  43)        zend_class_entry *called_scope;
7c45b95894e Zend/zend_API.h         (George Peter Banyard 2022-10-26 13:45:19 +0100  44)        zend_object *object; /* Instance of object for method calls */
7c45b95894e Zend/zend_API.h         (George Peter Banyard 2022-10-26 13:45:19 +0100  45)        zend_object *closure; /* Closure reference, only if the callable *is* the object */
feb85801667 Zend/zend_API.h         (Dmitry Stogov        2008-07-24 09:42:18 +0000  46) } zend_fcall_info_cache;
feb85801667 Zend/zend_API.h         (Dmitry Stogov        2008-07-24 09:42:18 +0000  47) 
61cc4446811 Zend/zend_callables.h   (George Peter Banyard 2023-09-09 19:40:44 +0100  48) BEGIN_EXTERN_C()
61cc4446811 Zend/zend_callables.h   (George Peter Banyard 2023-09-09 19:40:44 +0100  49) 
b4892511775 Zend/zend_API.h         (Jani Taskinen        2007-11-02 19:40:39 +0000  50) #define ZEND_FCI_INITIALIZED(fci) ((fci).size != 0)
de4cfff5f66 Zend/zend_API.h         (George Peter Banyard 2022-10-26 14:15:11 +0100  51) #define ZEND_FCC_INITIALIZED(fcc) ((fcc).function_handler != NULL)
b4892511775 Zend/zend_API.h         (Jani Taskinen        2007-11-02 19:40:39 +0000  52) 
c81db6bc560 Zend/zend_API.h         (Dmitry Stogov        2005-04-27 15:45:36 +0000  53) #define IS_CALLABLE_CHECK_SYNTAX_ONLY (1<<0)
af15923bc34 Zend/zend_API.h         (Rowan Tommins        2022-06-08 18:16:22 +0100  54) #define IS_CALLABLE_SUPPRESS_DEPRECATIONS (1<<1)

The zend_callables.c file keeps the history fine from the parts moved from zend_execute_API.c, but for some reason refuses to keep the history from zend_API.c

Verified

This commit was signed with the committer’s verified signature. The key has expired.
Girgias Gina Peter Banyard

Verified

This commit was signed with the committer’s verified signature. The key has expired.
Girgias Gina Peter Banyard
…and C file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants