to simplify GV initialisation.
p4raw-id: //depot/perl@27382
GvSTASH(gv) = stash;
if (stash)
Perl_sv_add_backref(aTHX_ (SV*)stash, (SV*)gv);
- gv_name_set(gv, name, len, 0);
+ gv_name_set(gv, name, len, GV_ADD);
if (multi || doproto) /* doproto means it _was_ mentioned */
GvMULTI_on(gv);
if (doproto) { /* Replicate part of newSUB here. */
if (len > I32_MAX)
Perl_croak(aTHX_ "panic: gv name too long (%"UVuf")", (UV) len);
+ if (!(flags & GV_ADD) && GvNAME_HEK(gv)) {
+ unshare_hek(GvNAME_HEK(gv));
+ }
+
PERL_HASH(hash, name, len);
GvNAME_HEK(gv) = name ? share_hek(name, len, hash) : 0;
}
/*
* symbol creation flags, for use in gv_fetchpv() and get_*v()
*/
-#define GV_ADD 0x01 /* add, if symbol not already there */
+#define GV_ADD 0x01 /* add, if symbol not already there
+ For gv_name_set, adding a HEK for the first
+ time, so don't try to free what's there. */
#define GV_ADDMULTI 0x02 /* add, pretending it has been added already */
#define GV_ADDWARN 0x04 /* add, but warn if symbol wasn't already there */
#define GV_ADDINEVAL 0x08 /* add, as though we're doing so within an eval */
GvSTASH(dstr) = GvSTASH(sstr);
if (GvSTASH(dstr))
Perl_sv_add_backref(aTHX_ (SV*)GvSTASH(dstr), dstr);
- gv_name_set((GV *)dstr, name, len, 0);
+ gv_name_set((GV *)dstr, name, len, GV_ADD);
SvFAKE_on(dstr); /* can coerce to non-glob */
}