Skip to content

Commit 85198d3

Browse files
committed
Gain control of macro namespace visibility
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.
1 parent d2f07cb commit 85198d3

File tree

3 files changed

+1830
-14
lines changed

3 files changed

+1830
-14
lines changed

embed.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3885,6 +3885,8 @@
38853885
# undef AMGf_unary
38863886
# undef ASCTIME_LOCK
38873887
# undef ASCTIME_UNLOCK
3888+
# undef av_tindex_skip_len_mg
3889+
# undef av_top_index_skip_len_mg
38883890
# undef BhkENTRY
38893891
# undef BHKf_bhk_eval
38903892
# undef BHKf_bhk_post_end
@@ -4017,7 +4019,6 @@
40174019
# undef ENV_UNLOCK
40184020
# undef ENVr_LOCALEr_LOCK
40194021
# undef ENVr_LOCALEr_UNLOCK
4020-
# undef ESC_NATIVE
40214022
# undef EVAL_INEVAL
40224023
# undef EVAL_INREQUIRE
40234024
# undef EVAL_KEEPERR

perl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9349,6 +9349,16 @@ END_EXTERN_C
93499349
93509350
*/
93519351

9352+
START_EXTERN_C
9353+
9354+
/* #including a second time causes it to #undef any unwanted symbols to avoid
9355+
* polluting the user name space */
9356+
# define PERL_DO_UNDEFS
9357+
# include "embed.h"
9358+
# undef PERL_DO_UNDEFS
9359+
9360+
END_EXTERN_C
9361+
93529362
#endif /* Include guard */
93539363

93549364
/*

0 commit comments

Comments
 (0)