Generate C enums from internal enums, introduce Z_PARAM_ENUM()#20917
Generate C enums from internal enums, introduce Z_PARAM_ENUM()#20917arnaud-lb merged 31 commits intophp:masterfrom
Conversation
| @@ -47,6 +58,12 @@ ZEND_API zend_object *zend_enum_get_case(zend_class_entry *ce, zend_string *name | |||
| ZEND_API zend_object *zend_enum_get_case_cstr(zend_class_entry *ce, const char *name); | |||
| ZEND_API zend_result zend_enum_get_case_by_value(zend_object **result, zend_class_entry *ce, zend_long long_key, zend_string *string_key, bool try_from); | |||
|
|
|||
| 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.
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.
I though about this when adding this assert, but if we consider functions as opaque APIs, we don't know that zend_enum_obj_from_obj() has redundant asserts.
There was a problem hiding this comment.
That is fair, but in this case it is probably reasonable to expect zend_enum_obj_from_obj() to do the verification (if necessary), since that's the purpose of the function, especially since a failed assert is always a programmer error.
There was a problem hiding this comment.
No particularly strong feelings either way, though.
0b7ca66 to
adfa289
Compare
|
Nice approach. How will ADTs be handled? |
|
@iluuu1994 yes this should work. Alternatively it's possible to use |
The compiler should now be able to tell us if we forget one case
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
UPGRADING.INTERNALS: