return gv;
}
+/*
+=for apidoc gv_const_sv
+
+If C<gv> is a typeglob whose subroutine entry is a constant sub eligible for
+inlining, or C<gv> is a placeholder reference that would be promoted to such
+a typeglob, then returns the value returned by the sub. Otherwise, returns
+NULL.
+
+=cut
+*/
+
+SV *
+Perl_gv_const_sv(pTHX_ GV *gv)
+{
+ if (SvTYPE(gv) == SVt_PVGV)
+ return cv_const_sv(GvCVu(gv));
+ return SvROK(gv) ? SvRV(gv) : NULL;
+}
+
void
Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi)
{
register GP *gp;
const bool doproto = SvTYPE(gv) > SVt_NULL;
const char * const proto = (doproto && SvPOK(gv)) ? SvPVX_const(gv) : NULL;
+ SV *const has_constant = doproto && SvROK(gv) ? SvRV(gv) : NULL;
+
+ assert (!(proto && has_constant));
+
+ if (has_constant) {
+ /* The constant has to be a simple scalar type. */
+ switch (SvTYPE(has_constant)) {
+ case SVt_PVAV:
+ case SVt_PVHV:
+ case SVt_PVCV:
+ case SVt_PVFM:
+ case SVt_PVIO:
+ Perl_croak(aTHX_ "Cannot convert a reference to %s to typeglob",
+ sv_reftype(has_constant, 0));
+ }
+ SvRV_set(gv, NULL);
+ SvROK_off(gv);
+ }
sv_upgrade((SV*)gv, SVt_PVGV);
if (SvLEN(gv)) {
if (doproto) { /* Replicate part of newSUB here. */
SvIOK_off(gv);
ENTER;
- /* XXX unsafe for threads if eval_owner isn't held */
- start_subparse(0,0); /* Create CV in compcv. */
- GvCV(gv) = PL_compcv;
+ if (has_constant) {
+ /* newCONSTSUB takes ownership of the reference from us. */
+ GvCV(gv) = newCONSTSUB(stash, name, has_constant);
+ } else {
+ /* XXX unsafe for threads if eval_owner isn't held */
+ (void) start_subparse(0,0); /* Create empty CV in compcv. */
+ GvCV(gv) = PL_compcv;
+ }
LEAVE;
PL_sub_generation++;
}
gvp = (GV**)hv_fetch(stash, "ISA", 3, FALSE);
- av = (gvp && (gv = *gvp) && gv != (GV*)&PL_sv_undef) ? GvAV(gv) : Nullav;
+ av = (gvp && (gv = *gvp) && gv != (GV*)&PL_sv_undef) ? GvAV(gv) : NULL;
/* create and re-create @.*::SUPER::ISA on demand */
if (!av || !SvMAGIC(av)) {
/* NOTE: No support for tied ISA */
I32 items = AvFILLp(av) + 1;
while (items--) {
- SV* sv = *svp++;
- HV* basestash = gv_stashsv(sv, FALSE);
+ SV* const sv = *svp++;
+ HV* const basestash = gv_stashsv(sv, FALSE);
if (!basestash) {
if (ckWARN(WARN_MISC))
Perl_warner(aTHX_ packWARN(WARN_MISC), "Can't locate package %"SVf" for @%s::ISA",
/* if at top level, try UNIVERSAL */
if (level == 0 || level == -1) {
- HV* lastchance;
+ HV* const lastchance = gv_stashpvn("UNIVERSAL", 9, FALSE);
- if ((lastchance = gv_stashpvn("UNIVERSAL", 9, FALSE))) {
+ if (lastchance) {
if ((gv = gv_fetchmeth(lastchance, name, len,
(level >= 0) ? level + 1 : level - 1)))
{
}
/*
-=for apidoc gv_fetchmethod
-
-See L<gv_fetchmethod_autoload>.
-
-=cut
-*/
-
-GV *
-Perl_gv_fetchmethod(pTHX_ HV *stash, const char *name)
-{
- return gv_fetchmethod_autoload(stash, name, TRUE);
-}
-
-/*
=for apidoc gv_fetchmethod_autoload
Returns the glob which contains the subroutine to call to invoke the method
HV* ostash = stash;
if (stash && SvTYPE(stash) < SVt_PVHV)
- stash = Nullhv;
+ stash = NULL;
for (nend = name; *nend; nend++) {
if (*nend == '\'')
if (stash) {
if (SvTYPE(stash) < SVt_PVHV) {
packname = SvPV_const((SV*)stash, packname_len);
- stash = Nullhv;
+ stash = NULL;
}
else {
packname = HvNAME_get(stash);
GvHV(tmpgv) = newHV();
stash = GvHV(tmpgv);
if (!HvNAME_get(stash))
- Perl_hv_name_set(aTHX_ stash, name, namelen, 0);
+ hv_name_set(stash, name, namelen, 0);
return stash;
}
I32 len;
register const char *namend;
HV *stash = 0;
- const I32 add = flags & ~SVf_UTF8;
+ const I32 no_init = flags & (GV_NOADD_NOINIT | GV_NOINIT);
+ const I32 add = flags & ~SVf_UTF8 & ~ GV_NOADD_NOINIT;
PERL_UNUSED_ARG(full_len);
stash = GvHV(gv) = newHV();
if (!HvNAME_get(stash))
- Perl_hv_name_set(aTHX_ stash, nambeg, namend - nambeg, 0);
+ hv_name_set(stash, nambeg, namend - nambeg, 0);
}
if (*namend == ':')
require_errno(gv);
}
return gv;
- } else if (add & GV_NOINIT) {
+ } else if (no_init) {
return gv;
}
hv = GvHVn(gv);
hv_magic(hv, Nullgv, PERL_MAGIC_sig);
for (i = 1; i < SIG_SIZE; i++) {
- SV ** const init = hv_fetch(hv, PL_sig_name[i], strlen(PL_sig_name[i]), 1);
+ SV * const * const init = hv_fetch(hv, PL_sig_name[i], strlen(PL_sig_name[i]), 1);
if (init)
sv_setsv(*init, &PL_sv_undef);
PL_psig_ptr[i] = 0;
}
void
-Perl_gv_fullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
-{
- gv_fullname4(sv, gv, prefix, TRUE);
-}
-
-void
Perl_gv_efullname4(pTHX_ SV *sv, const GV *gv, const char *prefix, bool keepmain)
{
- const GV *egv = GvEGV(gv);
- if (!egv)
- egv = gv;
- gv_fullname4(sv, egv, prefix, keepmain);
-}
-
-void
-Perl_gv_efullname3(pTHX_ SV *sv, const GV *gv, const char *prefix)
-{
- gv_efullname4(sv, gv, prefix, TRUE);
-}
-
-/* compatibility with versions <= 5.003. */
-void
-Perl_gv_fullname(pTHX_ SV *sv, const GV *gv)
-{
- gv_fullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
-}
-
-/* compatibility with versions <= 5.003. */
-void
-Perl_gv_efullname(pTHX_ SV *sv, const GV *gv)
-{
- gv_efullname3(sv, gv, sv == (const SV*)gv ? "*" : "");
+ const GV * const egv = GvEGV(gv);
+ gv_fullname4(sv, egv ? egv : gv, prefix, keepmain);
}
IO *
IO * const io = (IO*)NEWSV(0,0);
sv_upgrade((SV *)io,SVt_PVIO);
- SvREFCNT(io) = 1;
+ /* This used to read SvREFCNT(io) = 1;
+ It's not clear why the reference count needed an explicit reset. NWC
+ */
+ assert (SvREFCNT(io) == 1);
SvOBJECT_on(io);
/* Clear the stashcache because a new IO could overrule a package name */
hv_clear(PL_stashcache);
- iogv = gv_fetchpv("FileHandle::", FALSE, SVt_PVHV);
+ iogv = gv_fetchpv("FileHandle::", 0, SVt_PVHV);
/* unless exists($main::{FileHandle}) and defined(%main::FileHandle::) */
if (!(iogv && GvHV(iogv) && HvARRAY(GvHV(iogv))))
iogv = gv_fetchpv("IO::Handle::", TRUE, SVt_PVHV);
file = GvFILE(gv);
/* performance hack: if filename is absolute and it's a standard
* module, don't bother warning */
- if (file
- && PERL_FILE_IS_ABSOLUTE(file)
#ifdef MACOS_TRADITIONAL
- && (instr(file, ":lib:")
+# define LIB_COMPONENT ":lib:"
#else
- && (instr(file, "/lib/")
+# define LIB_COMPONENT "/lib/"
#endif
- || instr(file, ".pm")))
+ if (file
+ && PERL_FILE_IS_ABSOLUTE(file)
+ && (instr(file, LIB_COMPONENT) || instr(file, ".pm")))
{
continue;
}