From 6d84b2fd5dae4cf0664a8fe3b3f33246af7a2dfb Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Sun, 22 Aug 2021 21:37:43 +0100 Subject: [PATCH] Add _mg() versions of the sv_setrv* family --- embed.fnc | 2 ++ embed.h | 2 ++ proto.h | 6 ++++++ sv.c | 26 ++++++++++++++++++++++++++ 4 files changed, 36 insertions(+) diff --git a/embed.fnc b/embed.fnc index ae86bfbd2ce7..4d515a8bbcb4 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1926,6 +1926,8 @@ Apd |char *|sv_setpv_bufsize|NN SV *const sv|const STRLEN cur|const STRLEN len Xp |void |sv_sethek |NN SV *const sv|NULLOK const HEK *const hek Apd |void |sv_setrv_noinc |NN SV *const sv|NN SV *const ref Apd |void |sv_setrv_inc |NN SV *const sv|NN SV *const ref +Apd |void |sv_setrv_noinc_mg |NN SV *const sv|NN SV *const ref +Apd |void |sv_setrv_inc_mg |NN SV *const sv|NN SV *const ref ApMdb |void |sv_setsv |NN SV *dsv|NULLOK SV *ssv CpMdb |void |sv_taint |NN SV* sv CpdR |bool |sv_tainted |NN SV *const sv diff --git a/embed.h b/embed.h index b7cc007c63da..53eee3faf6cf 100644 --- a/embed.h +++ b/embed.h @@ -695,7 +695,9 @@ #define sv_setref_pvn(a,b,c,d) Perl_sv_setref_pvn(aTHX_ a,b,c,d) #define sv_setref_uv(a,b,c) Perl_sv_setref_uv(aTHX_ a,b,c) #define sv_setrv_inc(a,b) Perl_sv_setrv_inc(aTHX_ a,b) +#define sv_setrv_inc_mg(a,b) Perl_sv_setrv_inc_mg(aTHX_ a,b) #define sv_setrv_noinc(a,b) Perl_sv_setrv_noinc(aTHX_ a,b) +#define sv_setrv_noinc_mg(a,b) Perl_sv_setrv_noinc_mg(aTHX_ a,b) #define sv_setsv_flags(a,b,c) Perl_sv_setsv_flags(aTHX_ a,b,c) #define sv_setsv_mg(a,b) Perl_sv_setsv_mg(aTHX_ a,b) #define sv_setuv(a,b) Perl_sv_setuv(aTHX_ a,b) diff --git a/proto.h b/proto.h index 5586ba6532a4..451060bac6c5 100644 --- a/proto.h +++ b/proto.h @@ -3812,9 +3812,15 @@ PERL_CALLCONV SV* Perl_sv_setref_uv(pTHX_ SV *const rv, const char *const classn PERL_CALLCONV void Perl_sv_setrv_inc(pTHX_ SV *const sv, SV *const ref); #define PERL_ARGS_ASSERT_SV_SETRV_INC \ assert(sv); assert(ref) +PERL_CALLCONV void Perl_sv_setrv_inc_mg(pTHX_ SV *const sv, SV *const ref); +#define PERL_ARGS_ASSERT_SV_SETRV_INC_MG \ + assert(sv); assert(ref) PERL_CALLCONV void Perl_sv_setrv_noinc(pTHX_ SV *const sv, SV *const ref); #define PERL_ARGS_ASSERT_SV_SETRV_NOINC \ assert(sv); assert(ref) +PERL_CALLCONV void Perl_sv_setrv_noinc_mg(pTHX_ SV *const sv, SV *const ref); +#define PERL_ARGS_ASSERT_SV_SETRV_NOINC_MG \ + assert(sv); assert(ref) #ifndef NO_MATHOMS PERL_CALLCONV void Perl_sv_setsv(pTHX_ SV *dsv, SV *ssv); #define PERL_ARGS_ASSERT_SV_SETSV \ diff --git a/sv.c b/sv.c index 594b4d48817e..3a9329e0b957 100644 --- a/sv.c +++ b/sv.c @@ -1789,11 +1789,15 @@ Perl_sv_setnv_mg(pTHX_ SV *const sv, const NV num) /* =for apidoc sv_setrv_noinc +=for apidoc_item sv_setrv_noinc_mg Copies an SV pointer into the given SV as an SV reference, upgrading it if necessary. After this, C is equal to I. This does not adjust the reference count of I. The reference I must not be NULL. +C will invoke 'set' magic on the SV; C will +not. + =cut */ @@ -1810,11 +1814,24 @@ Perl_sv_setrv_noinc(pTHX_ SV *const sv, SV *const ref) SvROK_on(sv); } +void +Perl_sv_setrv_noinc_mg(pTHX_ SV *const sv, SV *const ref) +{ + PERL_ARGS_ASSERT_SV_SETRV_NOINC_MG; + + sv_setrv_noinc(sv, ref); + SvSETMAGIC(sv); +} + /* =for apidoc sv_setrv_inc +=for apidoc_item sv_setrv_inc_mg As C but increments the reference count of I. +C will invoke 'set' magic on the SV; C will +not. + =cut */ @@ -1826,6 +1843,15 @@ Perl_sv_setrv_inc(pTHX_ SV *const sv, SV *const ref) sv_setrv_noinc(sv, SvREFCNT_inc_simple_NN(ref)); } +void +Perl_sv_setrv_inc_mg(pTHX_ SV *const sv, SV *const ref) +{ + PERL_ARGS_ASSERT_SV_SETRV_INC_MG; + + sv_setrv_noinc(sv, SvREFCNT_inc_simple_NN(ref)); + SvSETMAGIC(sv); +} + /* Return a cleaned-up, printable version of sv, for non-numeric, or * not incrementable warning display. * Originally part of S_not_a_number().