From: Marcus Holland-Moritz Date: Mon, 10 Nov 2008 19:13:20 +0000 (+0000) Subject: Allow lvalue usage of SvRV() and add MUTABLE_SV() check. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f19a12a3a65a1b840e4df1373a12eab6e50a8d5c;p=p5sagit%2Fp5-mst-13.2.git Allow lvalue usage of SvRV() and add MUTABLE_SV() check. Also add new SvRV_const() macro for read-only access. p4raw-id: //depot/perl@34804 --- diff --git a/sv.c b/sv.c index 436f18f..bae7604 100644 --- a/sv.c +++ b/sv.c @@ -10562,8 +10562,8 @@ Perl_rvpv_dup(pTHX_ SV *const dstr, const SV *const sstr, CLONE_PARAMS *const pa if (SvROK(sstr)) { SvRV_set(dstr, SvWEAKREF(sstr) - ? sv_dup(SvRV(sstr), param) - : sv_dup_inc(SvRV(sstr), param)); + ? sv_dup(SvRV_const(sstr), param) + : sv_dup_inc(SvRV_const(sstr), param)); } else if (SvPVX_const(sstr)) { diff --git a/sv.h b/sv.h index 3717070..7a65fe8 100644 --- a/sv.h +++ b/sv.h @@ -1048,6 +1048,7 @@ the scalar's value cannot change unless written to. # define SvUVX(sv) (0 + ((XPVUV*) SvANY(sv))->xuv_uv) # define SvNVX(sv) (-0.0 + ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv) # define SvRV(sv) (0 + (sv)->sv_u.svu_rv) +# define SvRV_const(sv) (0 + (sv)->sv_u.svu_rv) /* Don't test the core XS code yet. */ # if defined (PERL_CORE) && PERL_DEBUG_COW > 1 # define SvPVX(sv) (0 + (assert(!SvREADONLY(sv)), (sv)->sv_u.svu_pv)) @@ -1119,7 +1120,7 @@ the scalar's value cannot change unless written to. &(((XPVNV*) MUTABLE_PTR(SvANY(_svnvx)))->xnv_u.xnv_nv); \ })) # define SvRV(sv) \ - (*({ const SV *const _svrv = (const SV *)(sv); \ + (*({ SV *const _svrv = MUTABLE_SV(sv); \ assert(SvTYPE(_svrv) >= SVt_PV || SvTYPE(_svrv) == SVt_IV); \ assert(SvTYPE(_svrv) != SVt_PVAV); \ assert(SvTYPE(_svrv) != SVt_PVHV); \ @@ -1128,6 +1129,16 @@ the scalar's value cannot change unless written to. assert(!isGV_with_GP(_svrv)); \ &((_svrv)->sv_u.svu_rv); \ })) +# define SvRV_const(sv) \ + ({ const SV *const _svrv = (const SV *)(sv); \ + assert(SvTYPE(_svrv) >= SVt_PV || SvTYPE(_svrv) == SVt_IV); \ + assert(SvTYPE(_svrv) != SVt_PVAV); \ + assert(SvTYPE(_svrv) != SVt_PVHV); \ + assert(SvTYPE(_svrv) != SVt_PVCV); \ + assert(SvTYPE(_svrv) != SVt_PVFM); \ + assert(!isGV_with_GP(_svrv)); \ + (_svrv)->sv_u.svu_rv; \ + }) # define SvMAGIC(sv) \ (*({ const SV *const _svmagic = (const SV *)(sv); \ assert(SvTYPE(_svmagic) >= SVt_PVMG); \ @@ -1147,6 +1158,7 @@ the scalar's value cannot change unless written to. # define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv # define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv # define SvRV(sv) ((sv)->sv_u.svu_rv) +# define SvRV_const(sv) (0 + (sv)->sv_u.svu_rv) # define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_u.xmg_magic # define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash # endif