-
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
Draft
arnaud-lb
wants to merge
14
commits into
php:master
Choose a base branch
from
arnaud-lb:enum-c-enum
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ea64baa
Make ZEND_AST_CONST_ENUM_INIT a 4-children node
arnaud-lb d03e872
Store enum case id in ZEND_AST_CONST_ENUM_INIT
arnaud-lb 87b446b
Store enum case id in instance
arnaud-lb a775603
Set default_object_handlers when registering internal enum
arnaud-lb 46437b6
Expose enum case_id internally
arnaud-lb 0ca4a9e
Generate C enum for internal enums
arnaud-lb 975779a
Port ext/random
arnaud-lb 56b40fb
Z_PARAM_ENUM()
arnaud-lb 1b00f6e
ext/dom
arnaud-lb e8144d0
ext/pcntl
arnaud-lb 26dfb6d
ext/reflection
arnaud-lb 22fdee1
ext/uri
arnaud-lb 397e020
ext/standard
arnaud-lb aad476a
ext/bcmath
arnaud-lb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --TEST-- | ||
| Bug GH-20914: Internal enums can be cloned | ||
| --EXTENSIONS-- | ||
| zend_test | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| try { | ||
| var_dump(clone ZendTestIntEnum::Foo); | ||
| } catch (Error $e) { | ||
| echo $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| Trying to clone an uncloneable object of class ZendTestIntEnum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| --TEST-- | ||
| Bug GH-20914: Internal enums can be compared | ||
| --EXTENSIONS-- | ||
| zend_test | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $foo = ZendTestUnitEnum::Foo; | ||
| $bar = ZendTestUnitEnum::Bar; | ||
|
|
||
| var_dump($foo === $foo); | ||
| var_dump($foo == $foo); | ||
|
|
||
| var_dump($foo === $bar); | ||
| var_dump($foo == $bar); | ||
|
|
||
| var_dump($bar === $foo); | ||
| var_dump($bar == $foo); | ||
|
|
||
| var_dump($foo > $foo); | ||
| var_dump($foo < $foo); | ||
| var_dump($foo >= $foo); | ||
| var_dump($foo <= $foo); | ||
|
|
||
| var_dump($foo > $bar); | ||
| var_dump($foo < $bar); | ||
| var_dump($foo >= $bar); | ||
| var_dump($foo <= $bar); | ||
|
|
||
| var_dump($foo > true); | ||
| var_dump($foo < true); | ||
| var_dump($foo >= true); | ||
| var_dump($foo <= true); | ||
|
|
||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(true) | ||
| bool(true) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(false) | ||
| bool(true) | ||
| bool(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,14 +30,25 @@ extern ZEND_API zend_class_entry *zend_ce_unit_enum; | |
| extern ZEND_API zend_class_entry *zend_ce_backed_enum; | ||
| extern ZEND_API zend_object_handlers zend_enum_object_handlers; | ||
|
|
||
| typedef struct _zend_enum_obj { | ||
| zend_long case_id; | ||
| zend_object std; | ||
| } zend_enum_obj; | ||
|
|
||
| static inline zend_enum_obj *zend_enum_obj_from_obj(zend_object *zobj) { | ||
| ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM); | ||
| return (zend_enum_obj*)((char*)(zobj) - XtOffsetOf(zend_enum_obj, std)); | ||
| } | ||
|
|
||
| void zend_enum_startup(void); | ||
| void zend_register_enum_ce(void); | ||
| void zend_enum_add_interfaces(zend_class_entry *ce); | ||
| zend_result zend_enum_build_backed_enum_table(zend_class_entry *ce); | ||
| zend_object *zend_enum_new(zval *result, zend_class_entry *ce, zend_string *case_name, zval *backing_value_zv); | ||
| zend_object *zend_enum_new(zval *result, zend_class_entry *ce, zend_long case_id, zend_string *case_name, zval *backing_value_zv); | ||
| void zend_verify_enum(const zend_class_entry *ce); | ||
| void zend_enum_register_funcs(zend_class_entry *ce); | ||
| void zend_enum_register_props(zend_class_entry *ce); | ||
| zend_long zend_enum_next_case_id(zend_class_entry *enum_class); | ||
|
|
||
| ZEND_API zend_class_entry *zend_register_internal_enum( | ||
| const char *name, uint8_t type, const zend_function_entry *functions); | ||
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assert is redundant with the one in |
||
| return zend_enum_obj_from_obj(zobj)->case_id; | ||
| } | ||
|
|
||
| static zend_always_inline zval *zend_enum_fetch_case_name(zend_object *zobj) | ||
| { | ||
| ZEND_ASSERT(zobj->ce->ce_flags & ZEND_ACC_ENUM); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 believe enums are
int(unless a type is specified, which is only possible as of C23). Also applies tozend_enum_next_case_id()and similar.