gen_stub: Conditionally include zend_attributes.h to arginfo based on usage - #21570
Conversation
|
Another complication: some functions are declared conditionally: php-src/ext/ldap/ldap.stub.php Line 631 in 4f02d15 And the related attributes are declared with the same conditions: e.g. php-src/ext/ldap/ldap_arginfo.h Line 710 in 4f02d15 So ideally, any includes should be wrapped within the necessary conditions. There are already a few parameters which are passed to all generating methods (e.g. And there's already a |
|
Reworked. Header dependencies are collected during generation and passed down as a parameter, so the includes come from the code that emits the declaration rather than from scanning the output. All four points covered: collection in a The third commit drops manual includes that became redundant. |
Headers required by the generated code (zend_attributes.h, zend_constants.h, zend_enum.h) are collected during generation and emitted as includes at the top of the arginfo file, with the same preprocessor conditions and PHP version guards as the code that needs them.
Adds the zend_attributes.h, zend_constants.h and zend_enum.h includes now emitted by gen_stub.php.
Removes the manual zend_attributes.h and zend_enum.h includes from sources that only needed them for the arginfo file they include.
|
Thank you! |
Conditionally include zend_attributes.h only when attributes are actually used.
Currently, zend_attributes.h must be explicitly included in C source files even when only common attributes (e.g. #[\Deprecated]) are needed. This introduces unnecessary coupling between extensions and attribute internals.
This change removes the requirement to manually include the header for common attributes, reducing boilerplate and avoiding unnecessary dependencies.
It does not affect behavior or runtime — only improves developer ergonomics and compilation dependencies.