-
Notifications
You must be signed in to change notification settings - Fork 8k
gen_stub: Add support for generation C #include
statements
#19869
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
This is useful to include the necessary files for a constant’s `@cvalue` from within the arginfo itself.
$conds = []; | ||
foreach ($stmts as $stmt) { | ||
$cond = self::handlePreprocessorConditions($conds, $stmt); | ||
|
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 don't think using declare()
is the right approach here, it adds a new declaration in stubs that isn't valid in normal PHP code, meaning that stubs would no longer be valid PHP:
Warning: Unsupported declare 'c_include' in /in/oj65h on line 3
can I suggest instead just using a C preprocessor macro, #include <stdint.h>
this would be a comment, so it would get skipped in the next block, and you would just add handling to handlePreprocessorConditions
to ensure that for #include
a new IncludeInfo is added (make the handlePreprocessorConditions
method non-static)
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.
Yes, I agree that this is somewhat abusing the existing PHP syntax.
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.
meaning that stubs would no longer be valid PHP:
This is just a warning. It's valid PHP code.
can I suggest instead just using a C preprocessor macro,
I initially tried that, but it got pretty ugly: The existing logic to handle #if
/ #endif
is “statement-based”. Since the #include
would not be a statement, special handling would be required.
Also the declare
nicely forces the #include
to appear at the top of the file, avoiding random includes from appearing somewhere in the middle of the stub.
$generatedFuncInfos = []; | ||
|
||
$argInfoCode = generateCodeWithConditions( | ||
$fileInfo->includeInfos, "\n", |
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.
we don't need both a "\n" at the end of each line and a "\n" when combining them, that leads to blank lines between the inclusions
#if 0 | ||
declare( | ||
c_include='<stdint.h>', | ||
c_include='"zend_attributes.h"' |
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.
My 2 cents: why I'm not enthusiastic about this feature is that it would add even more C code in stubs. For ifdefs and a few constant values it was unavoidable, but these includes are different: one should decide if they need a particular include or not, or which includes they want to use.
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.
This one in test.stub.php
is just to test that the functionality works with both include syntaxes and that the preprocessor checks also work. My use case is including the necessary headers for @cvalue
, such that the files including the _arginfo
don't need to know which constants are required by the various register_*()
functions, particularly when the same _arginfo
is required in multiple files.
zend_attributes.h
should just automatically included by the stubs when attributes are used to make them self-contained. It's incredibly annoying to manually include it when using deprecations.
I'm not a big fan of this. Let's have the files included by the code file including the arginfo file and keep the stub files clean. |
This is useful to include the necessary files for a constant’s
@cvalue
from within the arginfo itself.