Skip to content

embed.pl Create Perl_foo functions for all mp-flagged macros#24279

Merged
khwilliamson merged 4 commits intoPerl:bleadfrom
khwilliamson:mp
Mar 31, 2026
Merged

embed.pl Create Perl_foo functions for all mp-flagged macros#24279
khwilliamson merged 4 commits intoPerl:bleadfrom
khwilliamson:mp

Conversation

@khwilliamson
Copy link
Copy Markdown
Contributor

This extends the existing mechanism to macros that don't have an aTHX parameter. This allows a module to #undef a macro whose name collides with its version, and still have access to the functionality via the long name.

This is a step towards avoiding name space pollution.

The previous mechanism which didn't create a function is retained for macros not visible outside the core or its extensions, as we don't have to worry about name collisions.

  • This set of changes does not require a perldelta entry.

A future commit will, for the first time, call strstr with a
    const char *
'haystack parameter.  On my Linux box that doesn't compile because, in
spite of the man page, that parameter is declared merely 'char *'.

Looking at string.h, it appears that it can be const under the right
circumstances.
This creates some more mnemonics so that, for example, 'AC' is repeated
everywhere for that class of visibility
This allows XS code to #undef a short name macro, and still have access
to its functionality via a Perl_foo function.  This would go a long way
to allowing XS code to cope with namespace collisions.

Prior to this commit, macros without a thread context parameter did not
have function fallbacks.

The current catch is that all such macros must be flagged as 'mp'.  It's
trivial to add the 'p' flag to any such macro we want.  Or maybe there
could be a Configure option to add it to all public macros.  But that is
future work.  This lays the foundation for it.

One gotcha it took me a while to realize.  Suppose there's a name space
collision with macro A; so the XS code undefs our 'A' in favor of its
own.  But if another of our macros, say 'B',  calls 'A', it will get the
XS version.  Hopefully there's a parameter mismatch and the code doesn't
compile; and the solution would be to #undef 'B' as well.
The previous commit creates a function for any macro flagged 'mp' that
is visible outside the core, so that name collisions for the short form
macro name can easily be solved.  This isn't needed for perl core use,
as we will fix any collisions that come up before shipping the product.
But the same is true of extensions to core.  Change so that we extend
the exception to include those.
@khwilliamson khwilliamson merged commit 1f4f334 into Perl:blead Mar 31, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant