1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Generate C enums from internal enums, introduce Z_PARAM_ENUM() (#20917)

Update gen_stubs.php to generate C enums from internal enums, when the stub is annotated with @generate-c-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, 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().

* Make ZEND_AST_CONST_ENUM_INIT a 4-children node

* Store enum case id in ZEND_AST_CONST_ENUM_INIT

* Store enum case id in instance

* Expose enum case_id internally

* Generate C enum for internal enums

* Introduce Z_PARAM_ENUM()

* Port extensions
This commit is contained in:
Arnaud Le Blanc
2026-02-03 12:38:04 +01:00
committed by GitHub
parent 4a1cca7ddc
commit d16e6f52a4
47 changed files with 576 additions and 207 deletions

View File

@@ -6547,16 +6547,16 @@ ZEND_METHOD(ReflectionProperty, hasHook)
reflection_object *intern;
property_reference *ref;
zend_object *type;
zend_enum_PropertyHookType type;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJ_OF_CLASS(type, reflection_property_hook_type_ptr)
Z_PARAM_ENUM(type, reflection_property_hook_type_ptr)
ZEND_PARSE_PARAMETERS_END();
GET_REFLECTION_OBJECT_PTR(ref);
zend_property_hook_kind kind;
if (zend_string_equals_literal(Z_STR_P(zend_enum_fetch_case_name(type)), "Get")) {
if (type == ZEND_ENUM_PropertyHookType_Get) {
kind = ZEND_PROPERTY_HOOK_GET;
} else {
kind = ZEND_PROPERTY_HOOK_SET;
@@ -6569,10 +6569,10 @@ ZEND_METHOD(ReflectionProperty, getHook)
{
reflection_object *intern;
property_reference *ref;
zend_object *type;
zend_enum_PropertyHookType type;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJ_OF_CLASS(type, reflection_property_hook_type_ptr)
Z_PARAM_ENUM(type, reflection_property_hook_type_ptr)
ZEND_PARSE_PARAMETERS_END();
GET_REFLECTION_OBJECT_PTR(ref);
@@ -6583,7 +6583,7 @@ ZEND_METHOD(ReflectionProperty, getHook)
}
zend_function *hook;
if (zend_string_equals_literal(Z_STR_P(zend_enum_fetch_case_name(type)), "Get")) {
if (type == ZEND_ENUM_PropertyHookType_Get) {
hook = ref->prop->hooks[ZEND_PROPERTY_HOOK_GET];
} else {
hook = ref->prop->hooks[ZEND_PROPERTY_HOOK_SET];