Skip to content

Commit 63bdd5f

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 63bdd5f

File tree

3 files changed

+1922
-92
lines changed

3 files changed

+1922
-92
lines changed

embed.h

Lines changed: 2 additions & 79 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
@@ -2087,16 +2044,12 @@
20872044
# undef LOC
20882045
# undef LOCALE_CATEGORIES_COUNT_
20892046
# undef LOCALE_INIT
2090-
# undef LOCALE_LOCK_
20912047
# undef LOCALE_LOCK_DOES_SOMETHING_
20922048
# undef locale_panic_
20932049
# undef locale_panic_via_
20942050
# undef LOCALE_PAT_MODS
20952051
# undef LOCALE_TERM
20962052
# undef LOCALE_TERM_POSIX_2008_
2097-
# undef LOCALE_UNLOCK_
2098-
# undef LOCALTIME_LOCK
2099-
# undef LOCALTIME_UNLOCK
21002053
# undef LOCK_LC_NUMERIC_STANDARD
21012054
# undef LOGICAL
21022055
# undef LOGICAL_t8
@@ -2184,19 +2137,13 @@
21842137
# undef MAYBE_DEREF_GV
21852138
# undef MAYBE_DEREF_GV_flags
21862139
# undef MAYBE_DEREF_GV_nomg
2187-
# undef MBLEN_LOCK_
2188-
# undef MBLEN_UNLOCK_
21892140
# undef MBOL
21902141
# undef MBOL_t8
21912142
# undef MBOL_t8_p8
21922143
# undef MBOL_t8_pb
21932144
# undef MBOL_tb
21942145
# undef MBOL_tb_p8
21952146
# undef MBOL_tb_pb
2196-
# undef MBRTOWC_LOCK_
2197-
# undef MBRTOWC_UNLOCK_
2198-
# undef MBTOWC_LOCK_
2199-
# undef MBTOWC_UNLOCK_
22002147
# undef MEM_LOG_DEL_SV
22012148
# undef MEM_LOG_NEW_SV
22022149
# undef MEM_WRAP_CHECK_1
@@ -2531,8 +2478,6 @@
25312478
# undef PoisonPADLIST
25322479
# undef POPpconstx
25332480
# undef POSIX_CC_COUNT
2534-
# undef POSIX_SETLOCALE_LOCK
2535-
# undef POSIX_SETLOCALE_UNLOCK
25362481
# undef POSIXA
25372482
# undef POSIXA_t8
25382483
# undef POSIXA_t8_p8
@@ -3074,8 +3019,6 @@
30743019
# undef S_iv_add_may_overflow
30753020
# undef S_iv_mul_may_overflow
30763021
# undef S_iv_sub_may_overflow
3077-
# undef S_IWOTH
3078-
# undef S_IXOTH
30793022
# undef S_PAT_MODS
30803023
# undef S_uv_add_overflow
30813024
# undef S_uv_mul_overflow
@@ -3329,8 +3272,6 @@
33293272
# undef STAR_tb_p8
33303273
# undef STAR_tb_pb
33313274
# undef StashHANDLER
3332-
# undef STATIC_ASSERT_STRUCT_BODY_
3333-
# undef STATIC_ASSERT_STRUCT_NAME_
33343275
# undef STATUS_ALL_FAILURE
33353276
# undef STATUS_ALL_SUCCESS
33363277
# undef STATUS_EXIT_SET
@@ -3344,10 +3285,6 @@
33443285
# undef STR_LENl
33453286
# undef STR_LENs
33463287
# undef STR_SZ
3347-
# undef STRFMON_LOCK
3348-
# undef STRFMON_UNLOCK
3349-
# undef STRFTIME_LOCK
3350-
# undef STRFTIME_UNLOCK
33513288
# undef STRING
33523289
# undef STRINGl
33533290
# undef STRINGs
@@ -3651,7 +3588,6 @@
36513588
# undef UNLESSM_tb_pb
36523589
# undef UNLINK
36533590
# undef UNLOCK_LC_NUMERIC_STANDARD
3654-
# undef UNOP_AUX_item_sv
36553591
# undef UPDATE_WARNINGS_LOC
36563592
# undef UPG_VERSION
36573593
# undef uproot_SV
@@ -3770,8 +3706,6 @@
37703706
# undef WARN_NONEstring
37713707
# undef WARNshift
37723708
# undef WARNsize
3773-
# undef WCTOMB_LOCK_
3774-
# undef WCTOMB_UNLOCK_
37753709
# undef WHILEM
37763710
# undef WHILEM_A_max
37773711
# undef WHILEM_A_max_fail
@@ -3852,8 +3786,6 @@
38523786
# undef WIN32SCK_IS_STDSCK
38533787
# undef with_t_UTF8ness
38543788
# undef with_tp_UTF8ness
3855-
# undef WSETLOCALE_LOCK
3856-
# undef WSETLOCALE_UNLOCK
38573789
# undef xI
38583790
# undef xI_offset
38593791
# undef xio_any
@@ -3885,6 +3817,8 @@
38853817
# undef AMGf_unary
38863818
# undef ASCTIME_LOCK
38873819
# undef ASCTIME_UNLOCK
3820+
# undef av_tindex_skip_len_mg
3821+
# undef av_top_index_skip_len_mg
38883822
# undef BhkENTRY
38893823
# undef BHKf_bhk_eval
38903824
# undef BHKf_bhk_post_end
@@ -3914,15 +3848,9 @@
39143848
# undef CHANGE_MULTICALL_FLAGS
39153849
# undef CHECK_AND_WARN_PROBLEMATIC_LOCALE_
39163850
# undef ckDEAD
3917-
# undef CLANG_DIAG_IGNORE
3918-
# undef CLANG_DIAG_IGNORE_STMT
3919-
# undef CLANG_DIAG_RESTORE
3920-
# undef CLANG_DIAG_RESTORE_STMT
39213851
# undef cLISTOPo
39223852
# undef cLISTOPx
39233853
# undef cLOGOPo
3924-
# undef CLONEf_CLONE_HOST
3925-
# undef CLONEf_COPY_STACKS
39263854
# undef cLOOPo
39273855
# undef cLOOPx
39283856
# undef cMETHOPo
@@ -4017,7 +3945,6 @@
40173945
# undef ENV_UNLOCK
40183946
# undef ENVr_LOCALEr_LOCK
40193947
# undef ENVr_LOCALEr_UNLOCK
4020-
# undef ESC_NATIVE
40213948
# undef EVAL_INEVAL
40223949
# undef EVAL_INREQUIRE
40233950
# undef EVAL_KEEPERR
@@ -4137,8 +4064,6 @@
41374064
# undef LvTARGOFF
41384065
# undef LvTYPE
41394066
# undef MAX_UNICODE_UTF8_BYTES
4140-
# undef MBRLEN_LOCK_
4141-
# undef MBRLEN_UNLOCK_
41424067
# undef MDEREF_ACTION_MASK
41434068
# undef MDEREF_AV_gvav_aelem
41444069
# undef MDEREF_AV_gvsv_vivify_rv2av_aelem
@@ -4530,8 +4455,6 @@
45304455
# undef UTF_START_MASK
45314456
# undef want_vtbl_bm
45324457
# undef want_vtbl_fm
4533-
# undef WCRTOMB_LOCK_
4534-
# undef WCRTOMB_UNLOCK_
45354458
# undef xlv_targoff
45364459
# undef XOPf_xop_dump
45374460
# 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)