sv_del_backref(MUTABLE_SV(oldgv), MUTABLE_SV(cv));
}
}
- else if ((hek = CvNAME_HEK(cv))) unshare_hek(hek);
+ else if ((hek = CvNAME_HEK(cv))) {
+ unshare_hek(hek);
+ CvNAMED_off(cv);
+ }
SvANY(cv)->xcv_gv_u.xcv_gv = gv;
assert(!CvCVGV_RC(cv));
break;
case SVt_PVCV:
{
- HEK * const hek = CvNAME_HEK((CV *)sv);
+ HEK *hek =
+ CvNAME_HEK((CV *)(
+ CvNAMED(sv)
+ ? sv
+ : mg_find(PadlistNAMESARRAY(
+ CvPADLIST(find_runcv(NULL))
+ )[svp-PL_curpad],
+ PERL_MAGIC_proto
+ )->mg_obj));
assert(hek);
share_hek_hek(hek);
cv_undef((CV *)sv);
*svp = newSV_type(SVt_PVCV);
/* Share name */
- assert(CvNAMED(sv));
CvNAME_HEK_set(*svp,
- share_hek_hek(CvNAME_HEK((CV *)sv)));
+ share_hek_hek(CvNAME_HEK((CV *)(
+ CvNAMED(sv)
+ ? sv
+ : mg_find(PadlistNAMESARRAY(
+ CvPADLIST(find_runcv(NULL))
+ )[svp-PL_curpad],
+ PERL_MAGIC_proto
+ )->mg_obj))));
break;
}
default: *svp = newSV(0); break;
*bar::is = *is;
*bar::like = *like;
}
-plan 124;
+plan 127;
# -------------------- Errors with feature disabled -------------------- #
package o { use overload qr => \&quire }
ok "quires" =~ bless([], o::), 'state sub used as overload method';
}
+{
+ state sub foo;
+ *cvgv = \&foo;
+ local *cvgv2 = *cvgv;
+ eval 'sub cvgv2 {42}'; # uses the stub already present
+ is foo, 42, 'defining state sub body via package sub declaration';
+}
# -------------------- my -------------------- #
package mo { use overload qr => \&quire }
ok "quires" =~ bless([], mo::), 'my sub used as overload method';
}
+{
+ my sub foo;
+ *mcvgv = \&foo;
+ local *mcvgv2 = *mcvgv;
+ eval 'sub mcvgv2 {42}'; # uses the stub already present
+ is foo, 42, 'defining my sub body via package sub declaration';
+}
+{
+ my sub foo;
+ *mcvgv3 = \&foo;
+ local *mcvgv4 = *mcvgv3;
+ eval 'sub mcvgv4 {42}'; # uses the stub already present
+ undef *mcvgv3; undef *mcvgv4; # leaves the pad with the only reference
+}
+# We would have crashed by now if it weren’t fixed.
+pass "pad taking ownership once more of packagified my-sub";
# -------------------- Interactions (and misc tests) -------------------- #