-
Notifications
You must be signed in to change notification settings - Fork 602
Gain control of macro namespace visibility #23885
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
Prior to this commit, a commented-out prototype was created for all macros that we have argument and return type information for. This might be useful information for a reader of proto.h. This commits stops doing this for private macros. It makes a future commit slightly easier, and I'm unsure of the usefulness of this anyway. But I could be persuaded otherwise.
Where 'weird' is defined as meaning something where the normal rules don't apply, so something we generate is unlikely to be correct. This only affects one element, and it uses aTHX in a way that is incompatible with it being automated.
These keywords all need another word to indicate the parameter type. Previously only 'struct' was considered to have. This changed showed an error in one entry embed.fnc, which is also corrected in this commit.
These macros are not for external use, so don't need a Perl_ prefix
My Linux man page says the arguments to this function should be const, but the compiler refuses to compile it when so. Easiest to just cast them away; the function isn't going to change them.
This is required for the next few commits that start automatically creating long Perl_name functions for the elements in embed.fnc that are macros and don't already have them in the source. Only macros can take a parameter that has to be a literal string, so don't fit with the next few commits. This is the only case in embed.fnc like that, so I'm deferring dealing with it for now.
A function can't return something of that type, but this has always been a macro, so this hasn't been caught.
They were marked as core-only.
Future commits make the new location a better choice
Can you cite some examples of where "we" (Perl programmers in general, or, at a minimum, CPAN authors) have gotten into trouble with this? |
44f89f6 to
1f76cdb
Compare
This commit undefines all macros that are visible to XS code but shouldn't be. This stops macro namespace pollution by perl. It works by changing embed.h to have two modes, controlled by a #ifdef that is set by perl.h. perl.h now #includes embed.h twice. The first time works as it always has. The second sets the #ifdef, and causes embed.h to #undef the macros that shouldn't be visible. This call is just before perl.h returns to its includer, so that these macros have come and gone before the file that #included perl.h is affected by them. The list of macros is determined by the visibility given by the apidoc lines documenting them, and by painstaking experiments with our test suite. Those experiments, and some manual inspection, have produced three long lists of items beyond what the apidoc lines currently give. One list is for items that the re extension to Perl requires. A second list is for items that other Perl extensions require. The third list is for items that at least one module shipped with perl requires (or that I know something on CPAN requires) even though the items aren't marked as being visible. There are over 700 items on this list. And smoking cpan with this will add others. The experiments were done automatically, and I have not manually done much manual inspection. I have wanted this ability to happen for a long time; and now things have come together to enable it. This allows us to have a clear-cut boundary with CPAN. It means you can add macros that have internal-only use without having to worry about making them likely not to clash with user names. It shows precisely what our names are that are visible to CPAN, and we can change some of them to be less likely to clash.
1f76cdb to
63bdd5f
Compare
|
CI tests on Windows are failing. One aspect of these failures is that where we are expecting an escaped backslash ( |
This p.r. undefines all macros that are visible to XS code but shouldn't be. This stops macro namespace pollution by perl.
It works by changing embed.h to have two modes, controlled by a #ifdef that is set by perl.h. perl.h now #includes embed.h twice. The first time works as it always has. The second sets the #ifdef, and causes embed.h to #undef the macros that shouldn't be visible. This call is just before perl.h returns to its includer, so that these macros have come and gone before the file that #included perl.h is affected by them.
The list of macros is determined by the visibility given by the apidoc lines documenting them, and by painstaking experiments with our test suite. Those experiments, and some manual inspection, have produced three long lists of items beyond what the apidoc lines currently give.
One list is for items that the re extension to Perl requires.
A second list is for items that other Perl extensions require.
The third list is for items that at least one module shipped with perl requires (or that I know something on CPAN requires) even though the items aren't marked as being visible. There are over 700 items on this list. And smoking cpan with this will add others.
The experiments were done automatically, and I have not manually done much manual inspection.
I have wanted this ability to happen for a long time; and now things have come together to enable it.
This allows us to have a clear-cut boundary with CPAN.
It means you can add macros that have internal-only use without having to worry about making them likely not to clash with user names.
It shows precisely what our names are that are visible to CPAN, and we can change some of them to be less likely to clash.