#include "EXTERN.h"
#define PERL_IN_GV_C
#include "perl.h"
+#include "overload.c"
static const char S_autoload[] = "AUTOLOAD";
static const STRLEN S_autolen = sizeof(S_autoload)-1;
Perl_newGP(pTHX_ GV *const gv)
{
GP *gp;
+ U32 hash;
+#ifdef USE_ITHREADS
const char *const file
= (PL_curcop && CopFILE(PL_curcop)) ? CopFILE(PL_curcop) : "";
- STRLEN len = strlen(file);
- U32 hash;
+ const STRLEN len = strlen(file);
+#else
+ SV *const temp_sv = CopFILESV(PL_curcop);
+ const char *file;
+ STRLEN len;
+
+ if (temp_sv) {
+ file = SvPVX(temp_sv);
+ len = SvCUR(temp_sv);
+ } else {
+ file = "";
+ len = 0;
+ }
+#endif
PERL_HASH(hash, file, len);
dVAR;
const U32 old_type = SvTYPE(gv);
const bool doproto = old_type > SVt_NULL;
- const char * const proto = (doproto && SvPOK(gv)) ? SvPVX_const(gv) : NULL;
+ char * const proto = (doproto && SvPOK(gv)) ? SvPVX(gv) : NULL;
+ const STRLEN protolen = proto ? SvCUR(gv) : 0;
SV *const has_constant = doproto && SvROK(gv) ? SvRV(gv) : NULL;
const U32 exported_constant = has_constant ? SvPCS_IMPORTED(gv) : 0;
CvFILE_set_from_cop(GvCV(gv), PL_curcop);
CvSTASH(GvCV(gv)) = PL_curstash;
if (proto) {
- sv_setpv((SV*)GvCV(gv), proto);
- Safefree(proto);
+ sv_usepvn_flags((SV*)GvCV(gv), proto, protolen,
+ SV_HAS_TRAILING_NUL);
}
}
}
=cut
*/
+STATIC HV*
+S_gv_get_super_pkg(pTHX_ const char* name, I32 namelen)
+{
+ AV* superisa;
+ GV** gvp;
+ GV* gv;
+ HV* stash;
+
+ stash = gv_stashpvn(name, namelen, 0);
+ if(stash) return stash;
+
+ /* If we must create it, give it an @ISA array containing
+ the real package this SUPER is for, so that it's tied
+ into the cache invalidation code correctly */
+ stash = gv_stashpvn(name, namelen, GV_ADD);
+ gvp = (GV**)hv_fetchs(stash, "ISA", TRUE);
+ gv = *gvp;
+ gv_init(gv, stash, "ISA", 3, TRUE);
+ superisa = GvAVn(gv);
+ GvMULTI_on(gv);
+ sv_magic((SV*)superisa, (SV*)gv, PERL_MAGIC_isa, NULL, 0);
+#ifdef USE_ITHREADS
+ av_push(superisa, newSVpv(CopSTASHPV(PL_curcop), 0));
+#else
+ av_push(superisa, newSVhek(CopSTASH(PL_curcop)
+ ? HvNAME_HEK(CopSTASH(PL_curcop)) : NULL));
+#endif
+
+ return stash;
+}
+
+/* FIXME. If changing this function note the comment in pp_hot's
+ S_method_common:
+
+ This code tries to figure out just what went wrong with
+ gv_fetchmethod. It therefore needs to duplicate a lot of
+ the internals of that function. ...
+
+ I'd guess that with one more flag bit that could all be moved inside
+ here.
+*/
+
GV *
Perl_gv_fetchmethod_autoload(pTHX_ HV *stash, const char *name, I32 autoload)
{
SV * const tmpstr = sv_2mortal(Perl_newSVpvf(aTHX_ "%s::SUPER",
CopSTASHPV(PL_curcop)));
/* __PACKAGE__::SUPER stash should be autovivified */
- stash = gv_stashpvn(SvPVX_const(tmpstr), SvCUR(tmpstr), GV_ADD);
+ stash = gv_get_super_pkg(SvPVX_const(tmpstr), SvCUR(tmpstr));
DEBUG_o( Perl_deb(aTHX_ "Treating %s as %s::%s\n",
origname, HvNAME_get(stash), name) );
}
if (!stash && (nsplit - origname) >= 7 &&
strnEQ(nsplit - 7, "::SUPER", 7) &&
gv_stashpvn(origname, nsplit - origname - 7, 0))
- stash = gv_stashpvn(origname, nsplit - origname, GV_ADD);
+ stash = gv_get_super_pkg(origname, nsplit - origname);
}
ostash = stash;
}
const I32 add = flags & ~GV_NOADD_MASK;
const char *const name_end = nambeg + full_len;
const char *const name_em1 = name_end - 1;
+ U32 faking_it;
if (flags & GV_NOTQUAL) {
/* Caller promised that there is no stash, so we can skip the check. */
if (*name == '!')
require_tie_mod(gv, "!", newSVpvs("Errno"), "TIEHASH", 1);
else if (*name == '-' || *name == '+')
- require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "FETCH", 0);
+ require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "TIEHASH", 0);
}
}
return gv;
return gv;
}
- /* Adding a new symbol */
+ /* Adding a new symbol.
+ Unless of course there was already something non-GV here, in which case
+ we want to behave as if there was always a GV here, containing some sort
+ of subroutine.
+ Otherwise we run the risk of creating things like GvIO, which can cause
+ subtle bugs. eg the one that tripped up SQL::Translator */
+
+ faking_it = SvOK(gv);
if (add & GV_ADDWARN && ckWARN_d(WARN_INTERNAL))
Perl_warner(aTHX_ packWARN(WARN_INTERNAL), "Had to create %s unexpectedly", nambeg);
gv_init(gv, stash, name, len, add & GV_ADDMULTI);
- gv_init_sv(gv, sv_type);
+ gv_init_sv(gv, faking_it ? SVt_PVCV : sv_type);
if (isALPHA(name[0]) && ! (isLEXWARN_on ? ckWARN(WARN_ONCE)
: (PL_dowarn & G_WARN_ON ) ) )
break;
case '\015': /* $^MATCH */
if (strEQ(name2, "ATCH"))
- goto ro_magicalize;
+ goto magicalize;
case '\017': /* $^OPEN */
if (strEQ(name2, "PEN"))
goto magicalize;
break;
case '\020': /* $^PREMATCH $^POSTMATCH */
if (strEQ(name2, "REMATCH") || strEQ(name2, "OSTMATCH"))
- goto ro_magicalize;
+ goto magicalize;
case '\024': /* ${^TAINT} */
if (strEQ(name2, "AINT"))
goto ro_magicalize;
case '8':
case '9':
{
- /* ensures variable is only digits */
- /* ${"1foo"} fails this test (and is thus writeable) */
- /* added by japhy, but borrowed from is_gv_magical */
+ /* Ensures that we have an all-digit variable, ${"1foo"} fails
+ this test */
+ /* This snippet is taken from is_gv_magical */
const char *end = name + len;
while (--end > name) {
- if (!isDIGIT(*end)) return gv;
+ if (!isDIGIT(*end)) return gv;
}
- goto ro_magicalize;
+ goto magicalize;
}
}
}
sv_type == SVt_PVIO
) { break; }
PL_sawampersand = TRUE;
- goto ro_magicalize;
+ goto magicalize;
case ':':
sv_setpv(GvSVn(gv),PL_chopset);
SvREADONLY_on(av);
if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
- require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "FETCH", 0);
+ require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "TIEHASH", 0);
break;
}
case '*':
case '#':
- if (sv_type == SVt_PV && ckWARN2(WARN_DEPRECATED, WARN_SYNTAX))
+ if (sv_type == SVt_PV && ckWARN2_d(WARN_DEPRECATED, WARN_SYNTAX))
Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
"$%c is no longer supported", *name);
break;
}
goto magicalize;
case '\023': /* $^S */
+ ro_magicalize:
+ SvREADONLY_on(GvSVn(gv));
+ /* FALL THROUGH */
case '1':
case '2':
case '3':
case '7':
case '8':
case '9':
- ro_magicalize:
- SvREADONLY_on(GvSVn(gv));
- /* FALL THROUGH */
case '[':
case '^':
case '~':
#ifdef USE_ITHREADS
CopFILE(PL_curcop) = (char *)file; /* set for warning */
#else
- CopFILEGV(PL_curcop) = gv_fetchfile(file);
+ CopFILEGV(PL_curcop)
+ = gv_fetchfile_flags(file, HEK_LEN(GvFILE_HEK(gv)), 0);
#endif
Perl_warner(aTHX_ packWARN(WARN_ONCE),
"Name \"%s::%s\" used only once: possible typo",
if (gp->gp_hv && SvTYPE(gp->gp_hv) == SVt_PVHV) {
const char *hvname = HvNAME_get(gp->gp_hv);
if (PL_stashcache && hvname)
- hv_delete(PL_stashcache, hvname, HvNAMELEN_get(gp->gp_hv),
+ (void)hv_delete(PL_stashcache, hvname, HvNAMELEN_get(gp->gp_hv),
G_DISCARD);
SvREFCNT_dec(gp->gp_hv);
}
dVAR;
MAGIC* const mg = mg_find((SV*)stash, PERL_MAGIC_overload_table);
AMT amt;
+ const struct mro_meta* stash_meta = HvMROMETA(stash);
U32 newgen;
- newgen = PL_sub_generation + HvMROMETA(stash)->cache_gen;
+ newgen = PL_sub_generation + stash_meta->pkg_gen + stash_meta->cache_gen;
if (mg) {
const AMT * const amtp = (AMT*)mg->mg_ptr;
if (amtp->was_ok_am == PL_amagic_generation
const char * const cooky = PL_AMG_names[i];
/* Human-readable form, for debugging: */
const char * const cp = (i >= DESTROY_amg ? cooky : AMG_id2name(i));
- const STRLEN l = strlen(cooky);
+ const STRLEN l = PL_AMG_namelens[i];
DEBUG_o( Perl_deb(aTHX_ "Checking overloading of \"%s\" in package \"%.256s\"\n",
cp, HvNAME_get(stash)) );
MAGIC *mg;
AMT *amtp;
U32 newgen;
+ struct mro_meta* stash_meta;
if (!stash || !HvNAME_get(stash))
return NULL;
- newgen = PL_sub_generation + HvMROMETA(stash)->cache_gen;
+ stash_meta = HvMROMETA(stash);
+ newgen = PL_sub_generation + stash_meta->pkg_gen + stash_meta->cache_gen;
mg = mg_find((SV*)stash, PERL_MAGIC_overload_table);
if (!mg) {
PUSHs(lr>0? left: right);
PUSHs( lr > 0 ? &PL_sv_yes : ( assign ? &PL_sv_undef : &PL_sv_no ));
if (notfound) {
- PUSHs( sv_2mortal(newSVpv(AMG_id2name(method + assignshift),0)));
+ PUSHs( sv_2mortal(newSVpvn(AMG_id2name(method + assignshift),
+ AMG_id2namelen(method + assignshift))));
}
PUSHs((SV*)cv);
PUTBACK;