-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Zend/zend_variables: use C99 designated initializers #10655
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
Conversation
/* IS_RESOURCE */ (zend_rc_dtor_func_t)zend_list_free, | ||
/* IS_REFERENCE */ (zend_rc_dtor_func_t)zend_reference_destroy, | ||
/* IS_CONSTANT_AST */ (zend_rc_dtor_func_t)zend_ast_ref_destroy | ||
[IS_UNDEF] = (zend_rc_dtor_func_t)zend_empty_destroy, |
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.
well, if we are to use this C99 feature, would assignments such as
[IS_UNDEF...IS_DOUBLE] =
work ?
otherwise, while the change itself is correct, as is I feel it does not real bring something to the table. What do you think ?
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.
Isn't that range thing a GNU extension?
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.
that s possible, maybe MSVC does not support it (would not surprise me).
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 ll let @Girgias decide if it s worth merging.
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.
Isn't that range thing a GNU extension?
It is. https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html
"To initialize a range of elements to the same value, write ‘[first ... last] = value’. This is a GNU extension."
It's tempting, but in this case it's not worth deviating from the standard.
It makes the code more robust; for example, it obsoletes this comment: Line 539 in f4313a8
Robustness is king. This way, we can later turn these |
Ok if your plan later on is to make them enums then it makes more sense. |
Note that we can't make this a "named" enum just yet because PHP stores type codes in |
Interesting ; I knew for C++, not for C... finally I would say. |
Refering to the comment in the definition of typedef struct {
/* Not using a union here, because there's no good way to initialize them
* in a way that is supported in both C and C++ (designated initializers
* are only supported since C++20). */
void *ptr;
uint32_t type_mask;
/* TODO: We could use the extra 32-bit of padding on 64-bit systems. */
} zend_type;
Wouldn't this change cause issues for extensions that are written in C++? |
Oh wait, didn't look at the code prior to posting the comment, because this is affecting a |
Even if this were in a header - I don't think C++ code would be a problem - older GCC versions that don't know C++20 yet do already support designated initializers as GNU extension (as part of C99 support). I suppose the same is true for MSVC (but I don't know). What's rather interesting about this code comment is that it was added by ac4e0f0 more than 3 years ago, long before PHP switched to C99. In C89, designated initializers did not exist. If ever PHP used them before switching to C99, PHP was already using GNU extensions and beyond the C specification. |
8.0 wasn't released until a year after that, that's what "long before" meant. But apparently the decision to go C99 was indeed around that time (a year before), so the comment is not that interesting, after all! C11 would be interesting, though, because it has atomics. |
Definitively is, we can review this sometime in PHP 9.x time. |
No description provided.