Skip to content

Commit 5e697dc

Browse files
committed
Get -DNO_SHORT_NAMES to work again
This option has been broken for a long time, since at least when we started having inline functions. This commit gets it working again, but further efforts are needed for it to be useful. In part, I have adapated an idea from Tony Cook that is a new angle on an approach I had previously considered and found unworkable. But his idea solves the problems I had found. It has two main components. 1) Prior to this p.r., long names for macros were #defined to just expand to that macro (plus potential compensating for the thread context parameter). That meant these would completely fail under NO_SHORT_NAMES, as pointed out in #23458 (comment) Now, a new file 'long_names.c' is automatically generated by regen/embed.pl. This file contains the API elements that are macros that don't have a separate long name. (mathoms.c had before 5.43 been used for this purpose, but only for a limited number of macros.) As a result, there is a long-name function automatically generated for every API macro. It becomes much easier to convert a macro to a function and vice versa. This also means that when NO_SHORT_NAMES is defined, there already is a long name available for every API element. 2) To handle NO_SHORT_NAMES, perl.h is changed to #include "embed.h" in an extra place. The existing #include works as previously. The new #include is wrapped with #defining a symbol that embed.h has been changed to look for, as well as for PERL_NO_SHORT_NAMES. If the new symbol isn't defined, embed.h works just as before. This is what happens in the first #include. If the new symbol is defined, but PERL_NO_SHORT_NAMES isn't, embed.h expands to nothing. This is the usual scenario, and effectively it means this behaves as if there were just a single #include of embed.h, as has always been the case. But if someone has #defined PERL_NO_SHORT_NAMES in their XS code before #including perl.h, this expansion of embed.h undefines all the symbols the first expansion had defined. Thus the XS code has no access to those short names, and they don't pollute its name space. The XS code needs to #include perl.h very early in its source, before it starts #defining its own symbols. The trick that makes this work for inline functions is that the second #include in perl.h comes just after the #includes of the inline functions headers. (Those #includes continue to come after the #includes of everything they need to have defined.) That means the inlined functions always have full access to the short names. But those definitions are gone for code that #defines PERL_NO_SHORT_NAMES and which comes after perl.h finishes. This p.r. however hides too many short named functions and macros. Traditionally, for example, newSV() is always called with the short name version, and is not considered to be a name space pollutant. A list of such API elements should be generated to serve as exceptions. A new embed.fnc flag, say 'L', could be added to their entries in that file to indicate to not hide their short names. The other thing it doesn't address is short names that have to be macros because of problematic parameters. hv_stores() is one such, because one of its parameters is a literal string, which just doesn't work with a function prototype. There are ways to automatically handle these cases, but that is for the future. The next step after this would be to take the non-API elements listed in embed.fnc, and #undef them unconditionally outside core. We would then be able to add whatever names we want for internal use, without fear of clashing with outside uses. A future direction would be to parse all the top-level header files and to add an #undef for every macro #defined in them that aren't API. That would allow us to have shorter, more readable, macro names for our use, without having to consider name space pollution.
1 parent 805b93b commit 5e697dc

File tree

16 files changed

+3383
-609
lines changed

16 files changed

+3383
-609
lines changed

Cross/Makefile-cross-SH

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,14 @@ h = $(h1) $(h2) $(h3) $(h4) $(h5)
342342
c1 = av.c scope.c op.c doop.c doio.c dquote.c dump.c gv.c hv.c mg.c reentr.c mro_core.c perl.c
343343
c2 = perly.c pp.c pp_hot.c pp_ctl.c pp_sys.c regcomp.c regexec.c utf8.c sv.c
344344
c3 = taint.c time64.c toke.c util.c deb.c run.c universal.c pad.c globals.c keywords.c
345-
c4 = perlio.c numeric.c mathoms.c locale.c pp_pack.c pp_sort.c
345+
c4 = perlio.c numeric.c mathoms.c locale.c long_names.c pp_pack.c pp_sort.c
346346
c5 = $(mallocsrc)
347347
348348
c = $(c1) $(c2) $(c3) $(c4) $(c5) miniperlmain.c perlmain.c opmini.c
349349
350350
obj1 = $(mallocobj) gv$(OBJ_EXT) toke$(OBJ_EXT) perly$(OBJ_EXT) op$(OBJ_EXT) pad$(OBJ_EXT) regcomp$(OBJ_EXT) dquote$(OBJ_EXT) dump$(OBJ_EXT) util$(OBJ_EXT) mg$(OBJ_EXT) reentr$(OBJ_EXT) mro_core$(OBJ_EXT)
351351
obj2 = hv$(OBJ_EXT) av$(OBJ_EXT) perl$(OBJ_EXT) run$(OBJ_EXT) pp_hot$(OBJ_EXT) sv$(OBJ_EXT) pp$(OBJ_EXT) scope$(OBJ_EXT) pp_ctl$(OBJ_EXT) pp_sys$(OBJ_EXT)
352-
obj3 = doop$(OBJ_EXT) doio$(OBJ_EXT) regexec$(OBJ_EXT) utf8$(OBJ_EXT) taint$(OBJ_EXT) deb$(OBJ_EXT) universal$(OBJ_EXT) globals$(OBJ_EXT) perlio$(OBJ_EXT) numeric$(OBJ_EXT) mathoms$(OBJ_EXT) locale$(OBJ_EXT) pp_pack$(OBJ_EXT) pp_sort$(OBJ_EXT) time64$(OBJ_EXT)
352+
obj3 = doop$(OBJ_EXT) doio$(OBJ_EXT) regexec$(OBJ_EXT) utf8$(OBJ_EXT) taint$(OBJ_EXT) deb$(OBJ_EXT) universal$(OBJ_EXT) globals$(OBJ_EXT) perlio$(OBJ_EXT) numeric$(OBJ_EXT) mathoms$(OBJ_EXT) locale$(OBJ_EXT) long_names($OBJ_EXT) pp_pack$(OBJ_EXT) pp_sort$(OBJ_EXT) time64$(OBJ_EXT)
353353
354354
obj = $(obj1) $(obj2) $(obj3) $(ARCHOBJS)
355355

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ keywords.h The keyword numbers
6161
l1_char_class_tab.h 256 word bit table of character classes (for handy.h)
6262
locale.c locale-specific utility functions
6363
locale_table.h header for locale.c
64+
long_names.c for use when NO_SHORT_NAMES is defined
6465
make_ext.pl Used by Makefile to execute extension Makefiles
6566
make_patchnum.pl Script to generate git_version.h and lib/Config_git.pl files for all OS'es
6667
makedef.pl Create symbol export lists for linking

Makefile.SH

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,8 @@ h = \
550550
551551
c_base = \
552552
av.c builtin.c caretx.c class.c deb.c doio.c doop.c dquote.c dump.c \
553-
globals.c gv.c hv.c keywords.c locale.c mathoms.c mg.c mro_core.c \
554-
numeric.c op.c pad.c peep.c perl.c perlio.c perly.c \
553+
globals.c gv.c hv.c keywords.c locale.c long_names.c mathoms.c mg.c \
554+
mro_core.c numeric.c op.c pad.c peep.c perl.c perlio.c perly.c \
555555
pp.c pp_ctl.c pp_hot.c pp_pack.c pp_sort.c pp_sys.c \
556556
reentr.c regcomp.c regcomp_debug.c regcomp_invlist.c regcomp_study.c \
557557
regcomp_trie.c regexec.c run.c scope.c sv.c taint.c time64.c toke.c \
@@ -578,15 +578,15 @@ common_objs = \
578578
av$(OBJ_EXT) builtin$(OBJ_EXT) caretx$(OBJ_EXT) class$(OBJ_EXT) \
579579
deb$(OBJ_EXT) doio$(OBJ_EXT) doop$(OBJ_EXT) dquote$(OBJ_EXT) \
580580
dump$(OBJ_EXT) globals$(OBJ_EXT) gv$(OBJ_EXT) hv$(OBJ_EXT) \
581-
keywords$(OBJ_EXT) locale$(OBJ_EXT) mathoms$(OBJ_EXT) mg$(OBJ_EXT) \
582-
mro_core$(OBJ_EXT) numeric$(OBJ_EXT) pad$(OBJ_EXT) peep$(OBJ_EXT) \
583-
perlio$(OBJ_EXT) perly$(OBJ_EXT) pp$(OBJ_EXT) pp_ctl$(OBJ_EXT) \
584-
pp_hot$(OBJ_EXT) pp_pack$(OBJ_EXT) pp_sort$(OBJ_EXT) pp_sys$(OBJ_EXT) \
585-
reentr$(OBJ_EXT) regcomp$(OBJ_EXT) regcomp_debug$(OBJ_EXT) \
586-
regcomp_invlist$(OBJ_EXT) regcomp_study$(OBJ_EXT) regcomp_trie$(OBJ_EXT) \
587-
regexec$(OBJ_EXT) run$(OBJ_EXT) scope$(OBJ_EXT) sv$(OBJ_EXT) \
588-
taint$(OBJ_EXT) time64$(OBJ_EXT) toke$(OBJ_EXT) utf8$(OBJ_EXT) \
589-
util$(OBJ_EXT) \
581+
keywords$(OBJ_EXT) locale$(OBJ_EXT) long_names$(OBJ_EXT) \
582+
mathoms$(OBJ_EXT) mg$(OBJ_EXT) mro_core$(OBJ_EXT) numeric$(OBJ_EXT) \
583+
pad$(OBJ_EXT) peep$(OBJ_EXT) perlio$(OBJ_EXT) perly$(OBJ_EXT) \
584+
pp$(OBJ_EXT) pp_ctl$(OBJ_EXT) pp_hot$(OBJ_EXT) pp_pack$(OBJ_EXT) \
585+
pp_sort$(OBJ_EXT) pp_sys$(OBJ_EXT) reentr$(OBJ_EXT) regcomp$(OBJ_EXT) \
586+
regcomp_debug$(OBJ_EXT) regcomp_invlist$(OBJ_EXT) \
587+
regcomp_study$(OBJ_EXT) regcomp_trie$(OBJ_EXT) regexec$(OBJ_EXT) \
588+
run$(OBJ_EXT) scope$(OBJ_EXT) sv$(OBJ_EXT) taint$(OBJ_EXT) \
589+
time64$(OBJ_EXT) toke$(OBJ_EXT) utf8$(OBJ_EXT) util$(OBJ_EXT) \
590590
$(mallocobj) $(ARCHOBJS)
591591
592592
miniperl_objs_nodt = $(mini_only_objs) $(common_objs) miniperlmain$(OBJ_EXT)

0 commit comments

Comments
 (0)