You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
0 commit comments