-
Notifications
You must be signed in to change notification settings - Fork 8k
Generate C enums from internal enums, introduce Z_PARAM_ENUM() #20917
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
TimWolla
left a comment
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.
Some first comments. Will take another look once rebased after the merge of #20915.
|
|
||
| static zend_always_inline zend_long zend_enum_fetch_case_id(zend_object *zobj) | ||
| { | ||
| ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM); |
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 assert is redundant with the one in zend_enum_obj_from_obj(). I also don't see how it could help with codegen.
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.
The _decl files should be listed in .gitattributes as linguist-generated -diff.
|
|
||
| $cEnumName = 'zend_enum_' . str_replace('\\', '_', $this->name->toString()); | ||
|
|
||
| $code .= "typedef enum _{$cEnumName} {\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.
The leading underscore is not necessary and I believe for newer symbols we already don't have it:
| $code .= "typedef enum _{$cEnumName} {\n"; | |
| $code .= "typedef enum {$cEnumName} {\n"; |
| extern ZEND_API zend_object_handlers zend_enum_object_handlers; | ||
|
|
||
| typedef struct _zend_enum_obj { | ||
| zend_long case_id; |
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.
| zend_long case_id; | |
| int case_id; |
I believe enums are int (unless a type is specified, which is only possible as of C23). Also applies to zend_enum_next_case_id() and similar.
|
|
||
| if (zend_string_equals_literal(entry, "UserInteractive")) { | ||
| switch (entry) { | ||
| cse ZEND_ENUM_Pcntl_QosClass_UserInteractive: |
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.
| cse ZEND_ENUM_Pcntl_QosClass_UserInteractive: | |
| case ZEND_ENUM_Pcntl_QosClass_UserInteractive: |
Update
gen_stubs.phpto generate C enums from internal enums. Enum values can be compared to the result ofzend_enum_fetch_case_id(zend_object*).The generated enums are added to separate files named
{$extensionName}_decl.h(one for each extension declaring some enums), so that it's possible to include these from anywhere._arginfo.hfiles would generate warnings if we tried to include them in a compilation unit that doesn't call theregister_{$class}functions, for instance.Introduce
Z_PARAM_ENUM()(similarly to #20898).cc @TimWolla