Skip to content

Conversation

@arnaud-lb
Copy link
Member

Update gen_stubs.php to generate C enums from internal enums. Enum values can be compared to the result of zend_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.h files would generate warnings if we tried to include them in a compilation unit that doesn't call the register_{$class} functions, for instance.

Introduce Z_PARAM_ENUM() (similarly to #20898).

cc @TimWolla

Copy link
Member

@TimWolla TimWolla left a 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);
Copy link
Member

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.

Copy link
Member

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";
Copy link
Member

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:

Suggested change
$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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cse ZEND_ENUM_Pcntl_QosClass_UserInteractive:
case ZEND_ENUM_Pcntl_QosClass_UserInteractive:

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.

2 participants