diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-09-07 22:43:34 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-09-08 22:50:05 -0700 |
commit | ab3a355e8adbf2a0abfe6972f2d194e5becfb2e8 (patch) | |
tree | 9a51f8db92387b59c51d169030af8400754217cd /dist/threads-shared | |
parent | 4e848ca977b29932dcb7cc8c716cb661868cb91c (diff) | |
download | perl-ab3a355e8adbf2a0abfe6972f2d194e5becfb2e8.tar.gz |
shared.xs: Refactor to simplify S_get_RV’s callers
Every function that calls S_get_RV needs this same incantation:
S_get_RV(aTHX_ sv, ssv);
/* Look ahead for refs of refs */
if (SvROK(SvRV(ssv))) {
SvROK_on(SvRV(sv));
S_get_RV(aTHX_ SvRV(sv), SvRV(ssv));
}
Also, S_get_RV keeps repeating SvRV(ssv), even though it assigns it to
sobj at the top.
Also, an upcoming commit will need the ability to pass the referent to
S_get_RV.
So this patch changes S_get_RV to accept a referent instead (eliminat-
ing its multiple use of SvRV) and adds a get_RV macro to take care of
the standard calling rite.
Diffstat (limited to 'dist/threads-shared')
-rw-r--r-- | dist/threads-shared/shared.xs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/dist/threads-shared/shared.xs b/dist/threads-shared/shared.xs index 13e4a564b4..aea148ea97 100644 --- a/dist/threads-shared/shared.xs +++ b/dist/threads-shared/shared.xs @@ -661,14 +661,13 @@ Perl_sharedsv_cond_timedwait(perl_cond *cond, perl_mutex *mut, double abs) } -/* Given a shared RV, copy it's value to a private RV, also copying the - * object status of the referent. +/* Given a thingy referenced by a shared RV, copy it's value to a private + * RV, also copying the object status of the referent. * If the private side is already an appropriate RV->SV combination, keep * it if possible. */ STATIC void -S_get_RV(pTHX_ SV *sv, SV *ssv) { - SV *sobj = SvRV(ssv); +S_get_RV(pTHX_ SV *sv, SV *sobj) { SV *obj; if (! (SvROK(sv) && ((obj = SvRV(sv))) && @@ -683,7 +682,7 @@ S_get_RV(pTHX_ SV *sv, SV *ssv) { sv_setsv_nomg(sv, &PL_sv_undef); SvROK_on(sv); } - obj = S_sharedsv_new_private(aTHX_ SvRV(ssv)); + obj = S_sharedsv_new_private(aTHX_ sobj); SvRV_set(sv, obj); } @@ -702,6 +701,16 @@ S_get_RV(pTHX_ SV *sv, SV *ssv) { } } +/* Every caller of S_get_RV needs this incantation (which cannot go inside + S_get_RV itself, as we do not want recursion beyond one level): */ +#define get_RV(sv, sobj) \ + S_get_RV(aTHX_ sv, sobj); \ + /* Look ahead for refs of refs */ \ + if (SvROK(sobj)) { \ + SvROK_on(SvRV(sv)); \ + S_get_RV(aTHX_ SvRV(sv), SvRV(sobj)); \ + } + /* ------------ PERL_MAGIC_shared_scalar(n) functions -------------- */ @@ -715,12 +724,7 @@ sharedsv_scalar_mg_get(pTHX_ SV *sv, MAGIC *mg) ENTER_LOCK; if (SvROK(ssv)) { - S_get_RV(aTHX_ sv, ssv); - /* Look ahead for refs of refs */ - if (SvROK(SvRV(ssv))) { - SvROK_on(SvRV(sv)); - S_get_RV(aTHX_ SvRV(sv), SvRV(ssv)); - } + get_RV(sv, SvRV(ssv)); } else { sv_setsv_nomg(sv, ssv); } @@ -898,12 +902,7 @@ sharedsv_elem_mg_FETCH(pTHX_ SV *sv, MAGIC *mg) if (svp) { /* Exists in the array */ if (SvROK(*svp)) { - S_get_RV(aTHX_ sv, *svp); - /* Look ahead for refs of refs */ - if (SvROK(SvRV(*svp))) { - SvROK_on(SvRV(sv)); - S_get_RV(aTHX_ SvRV(sv), SvRV(*svp)); - } + get_RV(sv, SvRV(*svp)); } else { /* $ary->[elem] or $ary->{elem} is a scalar */ Perl_sharedsv_associate(aTHX_ sv, *svp); |