Skip to content

Conversation

@khwilliamson
Copy link
Contributor

Until C99 we couldn't use the type of macro we have that hides the need for thread context to call a function that needed both a thread context parameter and a format with varying numbers of parameters. Therefore you had to call the function directly with aTHX_. For some such functions, there were parallel functions created that omitted the thread context parameter (re-deriving it themselves). And there were compatibility macros created that called these. So, for example warn() would call Perl_warn_nocontext().

That changed in C99, and the calls in core to such functions were changed to use the macro that now expanded to Perl_warn().

Not all functions with this problem had '_nocontext()' versions. It turns out that the way the macros were #defined in embed.h, a definition existed for core, and non-threaded builds, but not threaded ones. This meant that, likely unknown to you, if you wrote an XS module, and used one of those macros, such as ck_warner(), it would compile and run on a non-threaded system, but would not compile on a threaded build.

Commits 13e5ba4 and d933027 did not affect the '_nocontext()' versions. This commit exposes their macros to the public. There is no need to worry about breaking existing code, as these macros existed only on non-threaded builds, and they still work there. They now work on threaded builds as well, as long as you have an aTHX variable available. This is no different than any newly created macro for which we are also requiring aTHX availability.

  • This set of changes does not require a perldelta entry because it is the first commit in an eventual series

Until C99 we couldn't use the type of macro we have that hides the need
for thread context to call a function that needed both a thread context
parameter and a format with varying numbers of parameters.  Therefore
you had to call the function directly with aTHX_.  For some such
functions, there were parallel functions created that omitted the thread
context parameter (re-deriving it themselves).  And there were
compatibility macros created that called these.  So, for example warn()
would call Perl_warn_nocontext().

That changed in C99, and the calls in core to such functions were
changed to use the macro that now expanded to Perl_warn().

Not all functions with this problem had '_nocontext()' versions.  It
turns out that the way the macros were #defined in embed.h, a definition
existed for core, and non-threaded builds, but not threaded ones.  This
meant that, likely unknown to you, if you wrote an XS module, and used
one of those macros, such as ck_warner(), it would compile and run on
a non-threaded system, but would not compile on a threaded build.

Commits 13e5ba4 and
d933027 did not affect the
'_nocontext()' versions.  This commit exposes their macros to the
public.  There is no need to worry about breaking existing code, as
these macros existed only on non-threaded builds, and they still work
there.  They now work on threaded builds as well, as long as you have an
aTHX variable available.  This is no different than any newly created
macro for which we are also requiring aTHX availability.
@khwilliamson khwilliamson requested review from Leont and leonerd August 21, 2025 00:00
@khwilliamson khwilliamson merged commit 6a9f2d6 into Perl:blead Aug 27, 2025
34 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