Skip to content

Commit

Permalink
Add _mg() versions of the sv_setrv* family
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Aug 25, 2021
1 parent 49f934d commit 6d84b2f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions embed.fnc
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions embed.h
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions proto.h
Expand Up @@ -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 \
Expand Down
26 changes: 26 additions & 0 deletions sv.c
Expand Up @@ -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<SvRV(sv)> is equal to I<ref>. This does not adjust
the reference count of I<ref>. The reference I<ref> must not be NULL.

C<sv_setrv_noinc_mg> will invoke 'set' magic on the SV; C<sv_setrv_noinc> will
not.

=cut
*/

Expand All @@ -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<sv_setrv_noinc> but increments the reference count of I<ref>.

C<sv_setrv_inc_mg> will invoke 'set' magic on the SV; C<sv_setrv_inc> will
not.

=cut
*/

Expand All @@ -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().
Expand Down

0 comments on commit 6d84b2f

Please sign in to comment.