Skip to content

Commit 30e3a5b

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 30e3a5b

File tree

3 files changed

+1912
-80
lines changed

3 files changed

+1912
-80
lines changed

embed.h

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,6 @@
707707
# undef ckWARNexperimental_with_arg
708708
# undef ckWARNreg
709709
# undef ckWARNregdep
710-
# undef CLANG_DIAG_IGNORE_DECL
711-
# undef CLANG_DIAG_PRAGMA
712-
# undef CLANG_DIAG_RESTORE_DECL
713710
# undef classnum_to_namedclass
714711
# undef CLEAR_ARGARRAY
715712
# undef CLEAR_OPTSTART
@@ -795,8 +792,6 @@
795792
# undef cSVOP
796793
# undef cSVOP_sv
797794
# undef cSVOPx_svp
798-
# undef CTIME_LOCK
799-
# undef CTIME_UNLOCK
800795
# undef Ctl
801796
# undef cUNOP
802797
# undef cUNOP_AUX
@@ -1573,83 +1568,53 @@
15731568
# undef get_extended_os_errno
15741569
# undef GET_REGCLASS_AUX_DATA
15751570
# undef GETATARGET
1576-
# undef GETENV_LOCK
1577-
# undef GETENV_UNLOCK
15781571
# undef GETGRENT_R_HAS_BUFFER
15791572
# undef GETGRENT_R_HAS_FPTR
15801573
# undef GETGRENT_R_HAS_PTR
15811574
# undef GETGRGID_R_HAS_BUFFER
15821575
# undef GETGRGID_R_HAS_PTR
15831576
# undef GETGRNAM_R_HAS_BUFFER
15841577
# undef GETGRNAM_R_HAS_PTR
1585-
# undef GETHOSTBYADDR_LOCK
15861578
# undef GETHOSTBYADDR_R_HAS_BUFFER
15871579
# undef GETHOSTBYADDR_R_HAS_ERRNO
15881580
# undef GETHOSTBYADDR_R_HAS_PTR
1589-
# undef GETHOSTBYADDR_UNLOCK
1590-
# undef GETHOSTBYNAME_LOCK
15911581
# undef GETHOSTBYNAME_R_HAS_BUFFER
15921582
# undef GETHOSTBYNAME_R_HAS_ERRNO
15931583
# undef GETHOSTBYNAME_R_HAS_PTR
1594-
# undef GETHOSTBYNAME_UNLOCK
15951584
# undef GETHOSTENT_R_HAS_BUFFER
15961585
# undef GETHOSTENT_R_HAS_ERRNO
15971586
# undef GETHOSTENT_R_HAS_PTR
1598-
# undef GETNETBYADDR_LOCK
15991587
# undef GETNETBYADDR_R_HAS_BUFFER
16001588
# undef GETNETBYADDR_R_HAS_ERRNO
16011589
# undef GETNETBYADDR_R_HAS_PTR
1602-
# undef GETNETBYADDR_UNLOCK
1603-
# undef GETNETBYNAME_LOCK
16041590
# undef GETNETBYNAME_R_HAS_BUFFER
16051591
# undef GETNETBYNAME_R_HAS_ERRNO
16061592
# undef GETNETBYNAME_R_HAS_PTR
1607-
# undef GETNETBYNAME_UNLOCK
16081593
# undef GETNETENT_R_HAS_BUFFER
16091594
# undef GETNETENT_R_HAS_ERRNO
16101595
# undef GETNETENT_R_HAS_PTR
1611-
# undef GETPROTOBYNAME_LOCK
16121596
# undef GETPROTOBYNAME_R_HAS_BUFFER
16131597
# undef GETPROTOBYNAME_R_HAS_PTR
1614-
# undef GETPROTOBYNAME_UNLOCK
1615-
# undef GETPROTOBYNUMBER_LOCK
16161598
# undef GETPROTOBYNUMBER_R_HAS_BUFFER
16171599
# undef GETPROTOBYNUMBER_R_HAS_PTR
1618-
# undef GETPROTOBYNUMBER_UNLOCK
1619-
# undef GETPROTOENT_LOCK
16201600
# undef GETPROTOENT_R_HAS_BUFFER
16211601
# undef GETPROTOENT_R_HAS_PTR
1622-
# undef GETPROTOENT_UNLOCK
16231602
# undef GETPWENT_R_HAS_BUFFER
16241603
# undef GETPWENT_R_HAS_FPTR
16251604
# undef GETPWENT_R_HAS_PTR
1626-
# undef GETPWNAM_LOCK
16271605
# undef GETPWNAM_R_HAS_BUFFER
16281606
# undef GETPWNAM_R_HAS_PTR
1629-
# undef GETPWNAM_UNLOCK
1630-
# undef GETPWUID_LOCK
16311607
# undef GETPWUID_R_HAS_PTR
1632-
# undef GETPWUID_UNLOCK
1633-
# undef GETSERVBYNAME_LOCK
16341608
# undef GETSERVBYNAME_R_HAS_BUFFER
16351609
# undef GETSERVBYNAME_R_HAS_PTR
1636-
# undef GETSERVBYNAME_UNLOCK
1637-
# undef GETSERVBYPORT_LOCK
16381610
# undef GETSERVBYPORT_R_HAS_BUFFER
16391611
# undef GETSERVBYPORT_R_HAS_PTR
1640-
# undef GETSERVBYPORT_UNLOCK
1641-
# undef GETSERVENT_LOCK
16421612
# undef GETSERVENT_R_HAS_BUFFER
16431613
# undef GETSERVENT_R_HAS_PTR
1644-
# undef GETSERVENT_UNLOCK
1645-
# undef GETSPNAM_LOCK
16461614
# undef GETSPNAM_R_HAS_BUFFER
16471615
# undef GETSPNAM_R_HAS_PTR
1648-
# undef GETSPNAM_UNLOCK
16491616
# undef GETTARGET
16501617
# undef GETTARGETSTACKED
1651-
# undef GMTIME_LOCK
1652-
# undef GMTIME_UNLOCK
16531618
# undef GOSUB
16541619
# undef GOSUB_t8
16551620
# undef GOSUB_t8_p8
@@ -1727,10 +1692,6 @@
17271692
# undef GvONCE_FATAL_off
17281693
# undef GvONCE_FATAL_on
17291694
# undef GvREFCNT
1730-
# undef gwLOCALE_LOCK
1731-
# undef gwLOCALE_UNLOCK
1732-
# undef gwLOCALEr_LOCK
1733-
# undef gwLOCALEr_UNLOCK
17341695
# undef HADNV
17351696
# undef HAS_BUILTIN_UNREACHABLE
17361697
# undef HAS_C99
@@ -1791,9 +1752,7 @@
17911752
# undef HINT_UTF8
17921753
# undef HINTS_DEFAULT
17931754
# undef HINTS_REFCNT_INIT
1794-
# undef HINTS_REFCNT_LOCK
17951755
# undef HINTS_REFCNT_TERM
1796-
# undef HINTS_REFCNT_UNLOCK
17971756
# undef HS_GETAPIVERLEN
17981757
# undef HS_GETINTERPSIZE
17991758
# undef HS_GETXSVERLEN
@@ -2022,9 +1981,7 @@
20221981
# undef KEY_y
20231982
# undef KEYWORD_PLUGIN_DECLINE
20241983
# undef KEYWORD_PLUGIN_MUTEX_INIT
2025-
# undef KEYWORD_PLUGIN_MUTEX_LOCK
20261984
# undef KEYWORD_PLUGIN_MUTEX_TERM
2027-
# undef KEYWORD_PLUGIN_MUTEX_UNLOCK
20281985
# undef kGVOP_gv
20291986
# undef kLISTOP
20301987
# undef kLOGOP
@@ -2095,8 +2052,6 @@
20952052
# undef LOCALE_TERM
20962053
# undef LOCALE_TERM_POSIX_2008_
20972054
# undef LOCALE_UNLOCK_
2098-
# undef LOCALTIME_LOCK
2099-
# undef LOCALTIME_UNLOCK
21002055
# undef LOCK_LC_NUMERIC_STANDARD
21012056
# undef LOGICAL
21022057
# undef LOGICAL_t8
@@ -2531,8 +2486,6 @@
25312486
# undef PoisonPADLIST
25322487
# undef POPpconstx
25332488
# undef POSIX_CC_COUNT
2534-
# undef POSIX_SETLOCALE_LOCK
2535-
# undef POSIX_SETLOCALE_UNLOCK
25362489
# undef POSIXA
25372490
# undef POSIXA_t8
25382491
# undef POSIXA_t8_p8
@@ -3074,8 +3027,6 @@
30743027
# undef S_iv_add_may_overflow
30753028
# undef S_iv_mul_may_overflow
30763029
# undef S_iv_sub_may_overflow
3077-
# undef S_IWOTH
3078-
# undef S_IXOTH
30793030
# undef S_PAT_MODS
30803031
# undef S_uv_add_overflow
30813032
# undef S_uv_mul_overflow
@@ -3329,8 +3280,6 @@
33293280
# undef STAR_tb_p8
33303281
# undef STAR_tb_pb
33313282
# undef StashHANDLER
3332-
# undef STATIC_ASSERT_STRUCT_BODY_
3333-
# undef STATIC_ASSERT_STRUCT_NAME_
33343283
# undef STATUS_ALL_FAILURE
33353284
# undef STATUS_ALL_SUCCESS
33363285
# undef STATUS_EXIT_SET
@@ -3344,10 +3293,6 @@
33443293
# undef STR_LENl
33453294
# undef STR_LENs
33463295
# undef STR_SZ
3347-
# undef STRFMON_LOCK
3348-
# undef STRFMON_UNLOCK
3349-
# undef STRFTIME_LOCK
3350-
# undef STRFTIME_UNLOCK
33513296
# undef STRING
33523297
# undef STRINGl
33533298
# undef STRINGs
@@ -3651,7 +3596,6 @@
36513596
# undef UNLESSM_tb_pb
36523597
# undef UNLINK
36533598
# undef UNLOCK_LC_NUMERIC_STANDARD
3654-
# undef UNOP_AUX_item_sv
36553599
# undef UPDATE_WARNINGS_LOC
36563600
# undef UPG_VERSION
36573601
# undef uproot_SV
@@ -3852,8 +3796,6 @@
38523796
# undef WIN32SCK_IS_STDSCK
38533797
# undef with_t_UTF8ness
38543798
# undef with_tp_UTF8ness
3855-
# undef WSETLOCALE_LOCK
3856-
# undef WSETLOCALE_UNLOCK
38573799
# undef xI
38583800
# undef xI_offset
38593801
# undef xio_any
@@ -3885,6 +3827,8 @@
38853827
# undef AMGf_unary
38863828
# undef ASCTIME_LOCK
38873829
# undef ASCTIME_UNLOCK
3830+
# undef av_tindex_skip_len_mg
3831+
# undef av_top_index_skip_len_mg
38883832
# undef BhkENTRY
38893833
# undef BHKf_bhk_eval
38903834
# undef BHKf_bhk_post_end
@@ -3914,10 +3858,6 @@
39143858
# undef CHANGE_MULTICALL_FLAGS
39153859
# undef CHECK_AND_WARN_PROBLEMATIC_LOCALE_
39163860
# undef ckDEAD
3917-
# undef CLANG_DIAG_IGNORE
3918-
# undef CLANG_DIAG_IGNORE_STMT
3919-
# undef CLANG_DIAG_RESTORE
3920-
# undef CLANG_DIAG_RESTORE_STMT
39213861
# undef cLISTOPo
39223862
# undef cLISTOPx
39233863
# undef cLOGOPo
@@ -4017,7 +3957,6 @@
40173957
# undef ENV_UNLOCK
40183958
# undef ENVr_LOCALEr_LOCK
40193959
# undef ENVr_LOCALEr_UNLOCK
4020-
# undef ESC_NATIVE
40213960
# undef EVAL_INEVAL
40223961
# undef EVAL_INREQUIRE
40233962
# undef EVAL_KEEPERR
@@ -4137,8 +4076,6 @@
41374076
# undef LvTARGOFF
41384077
# undef LvTYPE
41394078
# undef MAX_UNICODE_UTF8_BYTES
4140-
# undef MBRLEN_LOCK_
4141-
# undef MBRLEN_UNLOCK_
41424079
# undef MDEREF_ACTION_MASK
41434080
# undef MDEREF_AV_gvav_aelem
41444081
# undef MDEREF_AV_gvsv_vivify_rv2av_aelem
@@ -4530,8 +4467,6 @@
45304467
# undef UTF_START_MASK
45314468
# undef want_vtbl_bm
45324469
# undef want_vtbl_fm
4533-
# undef WCRTOMB_LOCK_
4534-
# undef WCRTOMB_UNLOCK_
45354470
# undef xlv_targoff
45364471
# undef XOPf_xop_dump
45374472
# undef XOPf_xop_peep

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)