Skip to content

Commit 93f23f0

Browse files
committed
Allow automatic long name macro generation
Prior to this commit, a macro that doesn't deal with thread context can have its long 'Perl_foo' name form be automatically generated. This was added in 5.41 by GH #22691. I had thought it worked in all cases, but the threaded case had to be reverted by #23209. The original scheme was too simplistic. This new commit reintroduces the thread context automatic handling, but isn't so naive this time. This commit will enable the emptying of much of mathoms.c, and the removal of quite a few similar functions scattered throughout the code. The next commit will convert the first such function, as a proof of concept.
1 parent 6277a14 commit 93f23f0

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

embed.fnc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,7 @@
447447
: created that #defines 'foo' as 'Perl_foo'. This can be used to make
448448
: any macro have a long name, perhaps to avoid name collisions. If
449449
: instead you define the macro as 'PERL_FOO' (all uppercase), the
450-
: embed.h entry will use all uppercase. Without the T flag the behavior
451-
: is subject to change when both 'm' and 'p are specified.
450+
: embed.h entry will use all uppercase.
452451
:
453452
: suppress proto.h entry (actually, not suppressed, but commented out)
454453
: suppress entry in the list of exported symbols available on all

regen/embed.pl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,40 @@ sub embed_h {
514514
if ($flags =~ /m/ && $flags =~ /p/) {
515515
my $full_name = full_name($func, $flags);
516516
next if $full_name eq $func; # Don't output a no-op.
517+
518+
# Yields
519+
# #define Perl_func func
520+
# which works when there is no thread context.
517521
$ret = indent_define($full_name, $func, $ind);
522+
523+
if ($flags !~ /[T]/) {
524+
525+
# But when there is the possibility of a thread context
526+
# parameter, $ret works only on non-threaded builds
527+
my $no_thread_full_define = $ret;
528+
529+
# And we have to do more when there are threads. First,
530+
# convert the input argument list to 'a', 'b' .... This keeps
531+
# us from having to worry about all the extra stuff in the
532+
# input list; stuff like the type declarations, things like
533+
# NULLOK, and pointers '*'.
534+
my $argname = 'a';
535+
my @stripped_args;
536+
push @stripped_args, $argname++ for $args->@*;
537+
my $arglist = join ",", @stripped_args;
538+
539+
# In the threaded case, the Perl_ form is expecting an aTHX
540+
# first argument. Use mTHX to match that, which isn't passed
541+
# on to the short form name, as that is expecting an implicit
542+
# aTHX. The non-threaded case just uses what we generated
543+
# above for the /T/ flag case.
544+
$ret = "#${ind}ifdef USE_THREADS\n"
545+
. "#${ind} define $full_name(mTHX,$arglist)"
546+
. " $func($arglist)\n"
547+
. "#${ind}else\n"
548+
. "$ind $no_thread_full_define" # No \n because no chomp
549+
. "#${ind}endif\n";
550+
}
518551
}
519552
elsif ($flags !~ /[omM]/) {
520553
my $argc = scalar @$args;

0 commit comments

Comments
 (0)