-
Notifications
You must be signed in to change notification settings - Fork 580
Use C99 named initialisers in core structs that define MGVTBLs #22086
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
base: blead
Are you sure you want to change the base?
Conversation
I thought we couldn't use this in public headers because C++? |
Ugh; it's |
It gets included in |
Another option would be to generate a separate The |
@leonerd, Given where we are in our annual production cycle, are you thinking of this for 5.40 or 5.42? |
2bb5119
to
7b38f46
Compare
Oh it doesn't need to be in 5.40 at all; it isn't doing any kind of user-benefit change. It's purely tidying up the code internally for our benefit. It can wait for 5.42, I just happen to have started writing it now. |
cf6347e
to
678aa24
Compare
Looking more closely at things, |
Since most Magic vtables do not provide every function, using C99 named initialisers allows us to more easily specify which ones are present, so readers don't have to count commas. Additionally provides a layer of robustness in case more functions are added in future.
678aa24
to
625cd98
Compare
These named initialisers are not permitted by C++ compilers using standards older than C++20, but fortunately even though they appear in mg_vtable.h and hence perl.h, they are hidden behind an `#ifdef` that is only defined when compiling `globals.c`, so this should be fine.
C99 allows trailing commas in on struct and table initialisers, so get rid of the code to avoid it in PL_magic_vtables and adjust the _names code to match. We don't add it to the enum, since magic_vtable_max is always the last element, so there won't be any diff noise from adding new elements after it.
[want_vtbl_arylen] = "arylen", | ||
[want_vtbl_arylen_p] = "arylen_p", | ||
[want_vtbl_backref] = "backref", | ||
[want_vtbl_checkcall] = "checkcall", | ||
[want_vtbl_collxfrm] = "collxfrm", | ||
[want_vtbl_dbline] = "dbline", | ||
[want_vtbl_debugvar] = "debugvar", | ||
[want_vtbl_defelem] = "defelem", | ||
[want_vtbl_destruct] = "destruct", | ||
[want_vtbl_env] = "env", | ||
[want_vtbl_envelem] = "envelem", |
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.
Array designated initializers are not C++ compatible, and since we have people who build perl with a C++ compiler, it's excluded by the guide in perlhacktips.pod
.
g++ supports it as an extension. but MSVC doesn't.
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.
Since most Magic vtables do not provide every function, using C99 named initialisers allows us to more easily specify which ones are present, so readers don't have to count commas. Additionally provides a layer of robustness in case more functions are added in future.
(No rush before 5.39.9 but I would like to test this out at least, sometime before too long)