Commit 7427171ef2 for perl
commit 7427171ef2331de7d7873f5977687ae8d96102fe
Author: Paul Evans <leonerd@leonerd.org.uk>
Date: Tue Oct 13 14:26:21 2026 +0100
Have export_lexical() return the new PADOFFSET
Technically an ABI-breaking change but that's fine between major
releases. Hopefully not API-breaking enough that it matters to anyone.
In normal uses code will be invoking this in void context so all is
fine.
diff --git a/embed.fnc b/embed.fnc
index f5adf0858a..81d66bfbe7 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -1440,7 +1440,8 @@ AOdp |SV * |eval_pv |NN const char *p \
AOdp |SSize_t|eval_sv |NN SV *sv \
|I32 flags
CTmpx |Size_t |expected_size |UV size
-Adp |void |export_lexical |NN SV *name \
+Adp |PADOFFSET|export_lexical \
+ |NN SV *name \
|NN SV *sv
ATdmp |bool |extended_utf8_to_uv \
|SPTR const U8 * const s \
diff --git a/pad.c b/pad.c
index a17ba11524..b75f9f34ad 100644
--- a/pad.c
+++ b/pad.c
@@ -3156,7 +3156,8 @@ Perl_prepare_export_lexical(pTHX)
Adds an entry into the lexical scope of the code which called this. In order
to have any effect this must be while the surrounding code is still being
compiled; usually by being invoked as part of a C<BEGIN> block (or the one
-implied by a C<use> statement.)
+implied by a C<use> statement.) Returns the pad offset of the newly-added
+lexical.
Calls to this function must be wrapped between a pair of calls to
L</prepare_export_lexical> and L</finish_export_lexical>, between which may be
@@ -3170,7 +3171,7 @@ placed one or more calls to C<export_lexical> itself.
=cut
*/
-void
+PADOFFSET
Perl_export_lexical(pTHX_ SV *name, SV *sv)
{
PERL_ARGS_ASSERT_EXPORT_LEXICAL;
@@ -3178,6 +3179,8 @@ Perl_export_lexical(pTHX_ SV *name, SV *sv)
PADOFFSET off = pad_add_name_sv(name, padadd_STATE, 0, 0);
SvREFCNT_dec(PL_curpad[off]);
PL_curpad[off] = SvREFCNT_inc(sv);
+
+ return off;
}
/*
diff --git a/proto.h b/proto.h
index 0382e5934a..9c099efb17 100644
--- a/proto.h
+++ b/proto.h
@@ -1851,7 +1851,7 @@ PERL_CALLCONV Size_t
Perl_expected_size(UV size);
#define PERL_ARGS_ASSERT_EXPECTED_SIZE
-PERL_CALLCONV void
+PERL_CALLCONV PADOFFSET
Perl_export_lexical(pTHX_ SV *name, SV *sv)
Perl_attribute_nonnull_aTHX
Perl_attribute_nonnull(pTHX_1)