Skip to content

Commit 658039d

Browse files
committed
perlapi: Improve wording of plain/nocontext entries
Certain functions have forms that contain the suffix '_nocontext', and which have long been specially handled in embed.h. autodoc was unaware of these until 14c379e recently. This tweaks the wording added in that commit, and by changing to use an in-line marker where its desired in the pod instead of an arbitrary place dictated from above, makes the result flow better.
1 parent 1ccc2b0 commit 658039d

File tree

5 files changed

+31
-55
lines changed

5 files changed

+31
-55
lines changed

autodoc.pl

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,17 @@
8484
# apidoc_item
8585
my $item_flags_re = qr/[dD fF mM nN oO pT uU Wx;]/xx;
8686

87-
# This is a copy of the list in regen/embed.pl.
88-
my @have_compatibility_macros = qw(
89-
deb
90-
form
91-
load_module
92-
mess
93-
newSVpvf
94-
sv_catpvf
95-
sv_catpvf_mg
96-
sv_setpvf
97-
sv_setpvf_mg
98-
warn
99-
warner
100-
);
101-
my %has_compat_macro;
102-
$has_compat_macro{$_} = 1 for @have_compatibility_macros;
87+
# Certain functions have plain and no_context versions, and meet the criteria
88+
# stated here. Each of their pods has been modified to have a marker line
89+
# which this program replaces by this wording. This way we can tweak the
90+
# wording in one place, and still have it placed in the individual pod entries
91+
# where it makes the most sense.
92+
my $PLAIN_vs_NOCONTEXT_wording = <<~EOT;
93+
C<WHICH> and C<WHICH_nocontext> behave identically when called from outside
94+
the perl core unless C<PERL_WANT_VARARGS> has been explicitly #defined.
95+
When it has, or when called from inside the core, they differ only in that
96+
C<WHICH> requires the thread context (C<aTHX>) to be available.
97+
EOT
10398

10499
use constant {
105100
NOT_APIDOC => -1,
@@ -1665,7 +1660,6 @@ ($fh, $section_name, $element_name, $docref)
16651660
my @deprecated;
16661661
my @experimental;
16671662
my @xrefs;
1668-
my @compat_macros;
16691663

16701664
for (my $i = 0; $i < @items; $i++) {
16711665
last if $docref->{'xref_only'}; # Place holder
@@ -1682,7 +1676,6 @@ ($fh, $section_name, $element_name, $docref)
16821676

16831677
push @deprecated, "C<$name>" if $item->{flags} =~ /D/;
16841678
push @experimental, "C<$name>" if $item->{flags} =~ /x/;
1685-
push @compat_macros, $name if $has_compat_macro{$name};
16861679
}
16871680

16881681
# While we're going though the items, construct a nice list of where
@@ -1780,6 +1773,13 @@ ($fh, $section_name, $element_name, $docref)
17801773
}
17811774

17821775
chomp $pod; # Make sure prints pod with a single trailing \n
1776+
1777+
# Replace this marker line in the pod with what we say it should expand
1778+
# to.
1779+
$pod =~ s{ \b __PLAIN_vs_NOCONTEXT_wording__ \( (\w+) \) }{
1780+
my $this = $1;
1781+
$PLAIN_vs_NOCONTEXT_wording =~ s/WHICH/$this/gr
1782+
}xeg;
17831783
print $fh "\n", $pod, "\n";
17841784

17851785
# Accumulate the usage section of the entry into this array. Output below
@@ -2186,18 +2186,6 @@ ($fh, $section_name, $element_name, $docref)
21862186
}
21872187
}
21882188

2189-
for my $compat (@compat_macros) {
2190-
print $fh <<~"EOT";
2191-
2192-
Note: When called from XS code, $compat(...) expands to
2193-
C<Perl_${compat}_no_context(...)> unless C<PERL_WANT_VARARGS> has
2194-
been C<#defined>, in which case it expands to
2195-
C<Perl_$compat(aTHX_ ...)>. When called from the perl core,
2196-
it assumes C<aTHX> is available, so expands to
2197-
C<Perl_$compat(aTHX_ ...)>
2198-
EOT
2199-
}
2200-
22012189
if (grep { /\S/ } @usage) {
22022190
print $fh "\n=over $usage_indent\n\n";
22032191
print $fh join "", @usage;

deb.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ the script causing the call, and the line number within that file.
5353
If the C<v> (verbose) debugging option is in effect, the process id is also
5454
printed.
5555
56-
C<deb> and C<deb_nocontext> differ only in that C<deb_nocontext> does not take
57-
a thread context (C<aTHX>) parameter, so is used in situations where the caller
58-
doesn't already have the thread context.
56+
__PLAIN_vs_NOCONTEXT_wording__(deb)
5957
6058
C<vdeb> is the same as C<deb> except C<args> is a pointer to a C<va_list>.
6159

op.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8495,9 +8495,7 @@ decremented. In addition, the C<name> argument is modified.
84958495
If C<PERL_LOADMOD_DENY> is set, the module is loaded as if with C<no> rather
84968496
than C<use>.
84978497

8498-
C<load_module> and C<load_module_nocontext> have the same apparent signature,
8499-
but the former hides the fact that it is accessing a thread context parameter.
8500-
So use the latter when you get a compilation error about C<pTHX>.
8498+
__PLAIN_vs_NOCONTEXT_wording__(load_module)
85018499

85028500
=for apidoc Amnh||PERL_LOADMOD_DENY
85038501
=for apidoc Amnh||PERL_LOADMOD_NOIMPORT

sv.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10434,6 +10434,7 @@ Perl_newSVpvf_nocontext(const char *const pat, ...)
1043410434
These each create a new SV and initialize it with the string formatted like
1043510435
C<sv_catpvf>.
1043610436

10437+
__PLAIN_vs_NOCONTEXT_wording__(newSVpvf)
1043710438

1043810439
=for apidoc vnewSVpvf
1043910440
Like C<L</newSVpvf>> but the arguments are a C<va_list>.
@@ -11626,9 +11627,9 @@ to be the same UTF8ness as the destination C<sv>, though certain Perl
1162611627
extensions to the standard set of %formats can override this (see
1162711628
L<perlguts/Formatted Printing of Strings> and adjacent sections).
1162811629

11629-
The forms whose name contains C<_no_context> do not take a thread
11630-
context (C<aTHX>) parameter, so are used in situations where the caller
11631-
doesn't already have the thread context.
11630+
__PLAIN_vs_NOCONTEXT_wording__(sv_setpvf)
11631+
11632+
__PLAIN_vs_NOCONTEXT_wording__(sv_setpvf_mg)
1163211633

1163311634
The forms whose name contains C<vset> use a C<va_list>, the
1163411635
other forms use C<sprintf>-style arguments.
@@ -11785,9 +11786,9 @@ to be the same UTF8ness as the destination C<sv>, though certain Perl
1178511786
extensions to the standard set of %formats can override this (see
1178611787
L<perlguts/Formatted Printing of Strings> and adjacent sections).
1178711788

11788-
The forms whose name contains C<_no_context> do not take a thread
11789-
context (C<aTHX>) parameter, so are used in situations where the caller
11790-
doesn't already have the thread context.
11789+
__PLAIN_vs_NOCONTEXT_wording__(sv_catpvf)
11790+
11791+
__PLAIN_vs_NOCONTEXT_wording__(sv_catpvf_mg)
1179111792

1179211793
The forms whose name contains C<vcat> use a C<va_list>, the
1179311794
other forms use C<sprintf>-style arguments.

util.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,7 @@ This is contrary to the incorrect previous documentation of these that claimed
14341434
that the return was a single per-thread buffer. That was (and is) actually
14351435
true only when these are called during global destruction.
14361436
1437-
C<form> and C<form_nocontext> differ only in that C<form_nocontext> does
1438-
not take a thread context (C<aTHX>) parameter, so is used in situations where
1439-
the caller doesn't already have the thread context (and can be called without
1440-
the C<Perl_> prefix.
1437+
__PLAIN_vs_NOCONTEXT_wording__(form)
14411438
14421439
C<vform> is the same as C<form> except the arguments are a C<va_list>.
14431440
It does need a thread context parameter, but that is supplied
@@ -1477,9 +1474,7 @@ used to generate a string message. If the message does not end with a newline,
14771474
then it will be extended with some indication of the current location in the
14781475
code, as described for C<L</mess_sv>>.
14791476
1480-
C<mess> and C<mess_nocontext> differ only in that C<mess_nocontext> does
1481-
not take a thread context (C<aTHX>) parameter, so is used in situations where
1482-
the caller doesn't already have the thread context.
1477+
__PLAIN_vs_NOCONTEXT_wording__(mess)
14831478
14841479
C<vmess> is the same as C<mess> except the arguments are a <va_list>.
14851480
It needs a thread context parameter only when called with the
@@ -2018,9 +2013,7 @@ but this is subject to modification by a C<$SIG{__WARN__}> handler.
20182013
20192014
Unlike with C<L</croak>>, C<pat> is not permitted to be null.
20202015
2021-
The two forms differ only in that C<warn_nocontext> does not take a thread
2022-
context (C<aTHX>) parameter, so is used in situations where the caller doesn't
2023-
already have the thread context.
2016+
__PLAIN_vs_NOCONTEXT_wording__(warn)
20242017
20252018
=cut
20262019
*/
@@ -2069,9 +2062,7 @@ but this is subject to modification by a C<$SIG{__WARN__}> handler.
20692062
20702063
C<pat> is not permitted to be null.
20712064
2072-
The two forms differ only in that C<warner_nocontext> does not take a thread
2073-
context (C<aTHX>) parameter, so is used in situations where the caller doesn't
2074-
already have the thread context.
2065+
__PLAIN_vs_NOCONTEXT_wording__(warner)
20752066
20762067
These functions differ from the similarly named C<L</warn>> functions, in that
20772068
the latter are for XS code to unconditionally display a warning, whereas these

0 commit comments

Comments
 (0)