Commit 92dc2cbc3d for perl
commit 92dc2cbc3d441896ee9bf477d0fa636ce00890d7
Author: Leon Timmermans <fawaka@gmail.com>
Date: Tue Oct 27 19:22:46 2026 +0100
Add save_scalar_flags
diff --git a/embed.fnc b/embed.fnc
index 43018e486b..f0633e4bb9 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -3289,6 +3289,9 @@ Aadip |char * |savepvn |NULLOK const char *pv \
Cdp |void |save_rcpv |NN char **prcpv
Cp |void |save_re_context
Adhp |SV * |save_scalar |NN GV *gv
+Adhp |SV * |save_scalar_flags \
+ |NN GV *gv \
+ |const U32 flags
Cdp |void |save_set_svflags \
|NN SV *sv \
|U32 mask \
diff --git a/embed.h b/embed.h
index e460b54469..adce942b91 100644
--- a/embed.h
+++ b/embed.h
@@ -642,6 +642,7 @@
# define save_rcpv(a) Perl_save_rcpv(aTHX_ a)
# define save_re_context() Perl_save_re_context(aTHX)
# define save_scalar(a) Perl_save_scalar(aTHX_ a)
+# define save_scalar_flags(a,b) Perl_save_scalar_flags(aTHX_ a,b)
# define save_set_svflags(a,b,c) Perl_save_set_svflags(aTHX_ a,b,c)
# define save_shared_pvref(a) Perl_save_shared_pvref(aTHX_ a)
# define save_sptr(a) Perl_save_sptr(aTHX_ a)
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 9a4346e246..6048aba6bc 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -394,9 +394,9 @@ well.
=over 4
-=item *
+=item * save_scalar_flags
-XXX
+Added a new function analogous to C<save_aelem_flags> and C<save_helem_flags>, to have more control over saving scalars.
=back
diff --git a/pod/perlguts.pod b/pod/perlguts.pod
index c9250d939d..0bf94c183b 100644
--- a/pod/perlguts.pod
+++ b/pod/perlguts.pod
@@ -2414,6 +2414,14 @@ best to just use the macro, and not those or the ones below.
=over 4
+=item C<SV* save_scalar_flags(GV *gv, U32 flags)>
+
+=for apidoc save_scalar_flags
+
+Equivalent to Perl code C<local $gv>. C<flags> can contain
+C<SAVEf_SETMAGIC> to automatically call setmagic; this should be done
+when not immediately assigning to the new scalar.
+
=item C<SV* save_scalar(GV *gv)>
=for apidoc save_scalar
diff --git a/proto.h b/proto.h
index 126abcc36a..d60ee183fe 100644
--- a/proto.h
+++ b/proto.h
@@ -7537,6 +7537,15 @@ Perl_save_scalar(pTHX_ GV *gv)
PERL_UNUSED_CONTEXT_FOR_ARGS_ASSERT; \
} STMT_END
+PERL_CALLCONV SV *
+Perl_save_scalar_flags(pTHX_ GV *gv, const U32 flags)
+ Perl_attribute_nonnull_aTHX
+ Perl_attribute_nonnull(pTHX_1);
+#define PERL_ARGS_ASSERT_SAVE_SCALAR_FLAGS \
+ STMT_START { Perl_assert_aTHX; assert(gv); \
+ PERL_UNUSED_CONTEXT_FOR_ARGS_ASSERT; \
+ } STMT_END
+
PERL_CALLCONV void
Perl_save_set_svflags(pTHX_ SV *sv, U32 mask, U32 val)
Perl_attribute_nonnull_aTHX
diff --git a/scope.c b/scope.c
index 4233e42e83..dc2a48a1e7 100644
--- a/scope.c
+++ b/scope.c
@@ -354,6 +354,14 @@ Perl_save_scalar(pTHX_ GV *gv)
{
PERL_ARGS_ASSERT_SAVE_SCALAR;
+ return save_scalar_flags(gv, SAVEf_SETMAGIC);
+}
+
+SV *
+Perl_save_scalar_flags(pTHX_ GV *gv, const U32 flags)
+{
+ PERL_ARGS_ASSERT_SAVE_SCALAR_FLAGS;
+
SV ** const sptr = &GvSVn(gv);
if (UNLIKELY(SvGMAGICAL(*sptr))) {
@@ -362,7 +370,7 @@ Perl_save_scalar(pTHX_ GV *gv)
PL_localizing = 0;
}
save_pushptrptr(SvREFCNT_inc_simple(gv), SvREFCNT_inc(*sptr), SAVEt_SV);
- return save_scalar_at(sptr, SAVEf_SETMAGIC); /* XXX - FIXME - see #60360 */
+ return save_scalar_at(sptr, flags);
}
/*