summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cv.h9
-rw-r--r--op.c12
-rw-r--r--pad.c13
-rw-r--r--scope.c8
4 files changed, 22 insertions, 20 deletions
diff --git a/cv.h b/cv.h
index 3d44a73968..5da9a502f5 100644
--- a/cv.h
+++ b/cv.h
@@ -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
diff --git a/op.c b/op.c
index 63e98b1606..a21364d499 100644
--- a/op.c
+++ b/op.c
@@ -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);
diff --git a/pad.c b/pad.c
index 7a3fad4f66..afd63892b0 100644
--- a/pad.c
+++ b/pad.c
@@ -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;
diff --git a/scope.c b/scope.c
index c21fea0616..db2d43be5b 100644
--- a/scope.c
+++ b/scope.c
@@ -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) {