perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Get -DNO_SHORT_NAMES to work again

Open khwilliamson opened this issue 1 month ago • 0 comments

This option has been broken for a long time, since at least when we started having inline functions. This p.r. 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.

It works by creating a new file long_names.c that is automatically generated by regen/embed.pl. This file contains the API elements that normally are macros that don't have a separate long name. This replaces the use of mathoms.c for the same purpose, but which was of use only in limited circumstances.

If someone wants to use a long name, and it isn't already in the source, embed.pl makes sure it is here, and hence can be linked to.

The more interesting case is when NO_SHORT_NAMES is defined, this file serves as the place for the linker to find the long names.

perl.h is changed to #include "embed.h" in two places. The first one works as previously. For the second #include, it defines a symbol that embed.h looks for. If it finds it works the opposite of the other way. It undefines the symbols that it previously defined, provided PERL_NO_SHORT_NAMES is defined. It it isn't defined, the second include is a no-op.

When not a no-op, after the second include those symbols are inaccessible to the code.

The trick is that the second #include comes just after the includes of the inline functions headers. That means the inlined functions always have full access to the short names. But those definitions are gone for code that comes after perl.h finishes.

This p.r. addresses a comment from @leont in https://github.com/Perl/perl5/pull/23458#issuecomment-3133917530

This p.r., however hides too many short named functions. Right now, you have to say Perl_newSV(aTHX) instead of newSV(). There has to be some core of old API elements that everyone wants to continue using as short names. A new embed.fnc flag, say 'L', could be added to their entries in that file to indicate to not hide its short name.

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 this p.r. doesn't do that.

A future direction would be to parse all the top-level header files and to cause all the definitions that are not part of the public API to be removed from the user's namespace regardless of PERL_NO_SHORT_NAMES. Thus we would stop inadvertently polluting it.

  • This set of changes requires a perldelta entry, and I need help writing it.

khwilliamson avatar Oct 15 '25 00:10 khwilliamson