diff options
-rw-r--r-- | cv.h | 9 | ||||
-rw-r--r-- | op.c | 12 | ||||
-rw-r--r-- | pad.c | 13 | ||||
-rw-r--r-- | scope.c | 8 |
4 files changed, 22 insertions, 20 deletions
@@ -202,6 +202,15 @@ CvNAME_HEK(CV *sv) ? ((XPVCV*)MUTABLE_PTR(SvANY(sv)))->xcv_gv_u.xcv_hek : 0; } +/* This lowers the refernce count of the previous value, but does *not* + increment the reference count of the new value. */ +#define CvNAME_HEK_set(cv, hek) ( \ + CvNAME_HEK((CV *)(cv)) \ + ? unshare_hek(SvANY((CV *)(cv))->xcv_gv_u.xcv_hek) \ + : (void)0, \ + ((XPVCV*)MUTABLE_PTR(SvANY(cv)))->xcv_gv_u.xcv_hek = (hek), \ + CvNAMED_on(cv) \ + ) /* =head1 CV reference counts and CvOUTSIDE @@ -6990,12 +6990,12 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) if (CvNAMED(*spot)) hek = CvNAME_HEK(*spot); else { - SvANY(*spot)->xcv_gv_u.xcv_hek = hek = + CvNAME_HEK_set(*spot, hek = share_hek( PadnamePV(name)+1, PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), 0 - ); - CvNAMED_on(*spot); + ) + ); } mg = mg_find(*svspot, PERL_MAGIC_proto); if (mg) { @@ -7155,13 +7155,13 @@ Perl_newMYSUB(pTHX_ I32 floor, OP *o, OP *proto, OP *attrs, OP *block) *spot = cv; } if (!CvNAME_HEK(cv)) { - SvANY(cv)->xcv_gv_u.xcv_hek = + CvNAME_HEK_set(cv, hek ? share_hek_hek(hek) : share_hek(PadnamePV(name)+1, PadnameLEN(name)-1 * (PadnameUTF8(name) ? -1 : 1), - 0); - CvNAMED_on(cv); + 0) + ); } CvFILE_set_from_cop(cv, PL_curcop); CvSTASH_set(cv, PL_curstash); @@ -381,8 +381,7 @@ Perl_cv_undef(pTHX_ CV *cv) #endif SvPOK_off(MUTABLE_SV(cv)); /* forget prototype */ sv_unmagic((SV *)cv, PERL_MAGIC_checkcall); - if (CvNAMED(cv)) unshare_hek(CvNAME_HEK(cv)), - SvANY(cv)->xcv_gv_u.xcv_hek = NULL; + if (CvNAMED(cv)) CvNAME_HEK_set(cv, NULL); else CvGV_set(cv, NULL); /* This statement and the subsequence if block was pad_undef(). */ @@ -2071,9 +2070,8 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside) assert(SvTYPE(ppad[ix]) == SVt_PVCV); assert(CvNAME_HEK((CV *)ppad[ix])); sv = newSV_type(SVt_PVCV); - SvANY((CV *)sv)->xcv_gv_u.xcv_hek = - share_hek_hek(CvNAME_HEK((CV *)ppad[ix])); - CvNAMED_on(sv); + CvNAME_HEK_set(sv, + share_hek_hek(CvNAME_HEK((CV *)ppad[ix]))); sv_magic(sv,mg->mg_obj,PERL_MAGIC_proto,NULL,0); } else sv = SvREFCNT_inc(ppad[ix]); @@ -2123,10 +2121,7 @@ S_cv_clone(pTHX_ CV *proto, CV *cv, CV *outside) CvFILE(cv) = CvDYNFILE(proto) ? savepv(CvFILE(proto)) : CvFILE(proto); if (CvNAMED(proto)) - { - SvANY(cv)->xcv_gv_u.xcv_hek = share_hek_hek(CvNAME_HEK(proto)); - CvNAMED_on(cv); - } + CvNAME_HEK_set(cv, share_hek_hek(CvNAME_HEK(proto))); else CvGV_set(cv,CvGV(proto)); CvSTASH_set(cv, CvSTASH(proto)); OP_REFCNT_LOCK; @@ -937,8 +937,7 @@ Perl_leave_scope(pTHX_ I32 base) assert(hek); share_hek_hek(hek); cv_undef((CV *)sv); - SvANY((CV *)sv)->xcv_gv_u.xcv_hek = hek; - CvNAMED_on(sv); + CvNAME_HEK_set(sv, hek); break; } default: @@ -964,9 +963,8 @@ Perl_leave_scope(pTHX_ I32 base) /* Share name */ assert(CvNAMED(sv)); - SvANY((CV *)*svp)->xcv_gv_u.xcv_hek = - share_hek_hek(SvANY((CV *)sv)->xcv_gv_u.xcv_hek); - CvNAMED_on(*svp); + CvNAME_HEK_set(*svp, + share_hek_hek(CvNAME_HEK((CV *)sv))); /* Steal magic */ while (mg) { |