summaryrefslogtreecommitdiff
path: root/regen
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2022-07-07 17:21:46 +0100
committerPaul Evans <leonerd@leonerd.org.uk>2022-08-03 17:55:01 +0100
commit13e5ba49b2cfe0add44db552ecbebb2f785aecbc (patch)
treebd9fe5a72be617cbdfc74fddec2f4adefd63da4c /regen
parentc553bad54cdfab778ac9527b43db5bf974d66cc5 (diff)
downloadperl-13e5ba49b2cfe0add44db552ecbebb2f785aecbc.tar.gz
Emit __VA_ARGS__-using macros into embed.h when on PERL_CORE
Now we're using C99, we can safely use the __VA_ARGS__ expansion in these variable-list macros. Unfortunately we can't just emit them unconditionally, because much existing CPAN code exists that thinks it can call e.g. `warn()` without an aTHX_ in scope (because they don't #define PERL_NO_GET_CONTEXT). Therefore, we have to guard these new macro forms by ... || defined(PERL_CORE) and continue to emit the "..._nocontext()" variants at the end of the file, as we previously did. It's not a great solution but it at least means we can use `croak()`, `warn()`, et.al. within perl core source now.
Diffstat (limited to 'regen')
-rwxr-xr-xregen/embed.pl40
1 files changed, 27 insertions, 13 deletions
diff --git a/regen/embed.pl b/regen/embed.pl
index ee7528666f..00a09b6f75 100755
--- a/regen/embed.pl
+++ b/regen/embed.pl
@@ -382,30 +382,44 @@ sub embed_h {
next if $full_name eq $func; # Don't output a no-op.
$ret = hide($func, $full_name);
}
- elsif ($argc and $args[$argc-1] =~ /\.\.\./) {
- if ($flags =~ /p/) {
- # we're out of luck for varargs functions under CPP
- # So we can only do these macros for non-MULTIPLICITY perls:
- $ret = "#ifndef MULTIPLICITY\n"
- . hide($func, full_name($func, $flags)) . "#endif\n";
- }
- }
else {
- my $alist = join(",", @az[0..$argc-1]);
- $ret = "#define $func($alist)";
+ my $use_va_list = $argc && $args[-1] =~ /\.\.\./;
+
+ if($use_va_list) {
+ # CPP has trouble with empty __VA_ARGS__ and comma joining,
+ # so we'll have to eat an extra params here.
+ if($argc < 2) {
+ die "Cannot use ... as the only parameter to a macro ($func)\n";
+ }
+ $argc -= 2;
+ }
+
+ my $paramlist = join(",", @az[0..$argc-1],
+ $use_va_list ? ("...") : ());
+ my $replacelist = join(",", @az[0..$argc-1],
+ $use_va_list ? ("__VA_ARGS__") : ());
+
+ $ret = "#define $func($paramlist)";
my $t = int(length($ret) / 8);
$ret .= "\t" x ($t < 4 ? 4 - $t : 1);
$ret .= full_name($func, $flags) . "(aTHX";
- $ret .= "_ " if $alist;
- $ret .= $alist;
+ $ret .= "_ " if $replacelist;
+ $ret .= $replacelist;
if ($flags =~ /W/) {
- if ($alist) {
+ if ($replacelist) {
$ret .= " _aDEPTH";
} else {
die "Can't use W without other args (currently)";
}
}
$ret .= ")\n";
+
+ if($use_va_list) {
+ # Make them available to !MULTIPLICITY or PERL_CORE
+ $ret = "#if !defined(MULTIPLICITY) || defined(PERL_CORE)\n" .
+ $ret .
+ "#endif\n";
+ }
}
$ret = "#ifndef NO_MATHOMS\n$ret#endif\n" if $flags =~ /b/;
}