This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Nit to S_isa_lookup by Brandon Black
[perl5.git] / universal.c
index e1ceea1..6999adc 100644 (file)
@@ -36,12 +36,12 @@ S_isa_lookup(pTHX_ HV *stash, const char *name, const HV* const name_stash,
              int len, int level)
 {
     dVAR;
-    AV* av;
-    GV* gv;
-    GV** gvp;
-    HV* hv = NULL;
-    SV* subgen = NULL;
+    AV* stash_linear_isa;
+    SV** svp;
     const char *hvname;
+    I32 items;
+    PERL_UNUSED_ARG(len);
+    PERL_UNUSED_ARG(level);
 
     /* A stash/class can go by many names (ie. User == main::User), so 
        we compare the stash itself just in case */
@@ -56,75 +56,23 @@ S_isa_lookup(pTHX_ HV *stash, const char *name, const HV* const name_stash,
     if (strEQ(name, "UNIVERSAL"))
        return TRUE;
 
-    if (level > 100)
-       Perl_croak(aTHX_ "Recursive inheritance detected in package '%s'",
-                  hvname);
-
-    gvp = (GV**)hv_fetchs(stash, "::ISA::CACHE::", FALSE);
-
-    if (gvp && (gv = *gvp) && isGV_with_GP(gv) && (subgen = GvSV(gv))
-       && (hv = GvHV(gv)))
-    {
-       if (SvIV(subgen) == (IV)PL_sub_generation) {
-           SV** const svp = (SV**)hv_fetch(hv, name, len, FALSE);
-           if (svp) {
-               SV * const sv = *svp;
-#ifdef DEBUGGING
-               if (sv != &PL_sv_undef)
-                   DEBUG_o( Perl_deb(aTHX_ "Using cached ISA %s for package %s\n",
-                                   name, hvname) );
-#endif
-               return (sv == &PL_sv_yes);
-           }
-       }
-       else {
-           DEBUG_o( Perl_deb(aTHX_ "ISA Cache in package %s is stale\n",
-                             hvname) );
-           hv_clear(hv);
-           sv_setiv(subgen, PL_sub_generation);
+    stash_linear_isa = mro_get_linear_isa(stash);
+    svp = AvARRAY(stash_linear_isa) + 1;
+    items = AvFILLp(stash_linear_isa);
+    while (items--) {
+       SV* const basename_sv = *svp++;
+        HV* basestash = gv_stashsv(basename_sv, 0);
+       if (!basestash || (HvMROMETA(basestash)->fake && !HvFILL(basestash))) {
+           if (ckWARN(WARN_SYNTAX))
+               Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
+                           "Can't locate package %"SVf" for the parents of %s",
+                           SVfARG(basename_sv), hvname);
+           continue;
        }
+        if(name_stash == basestash || strEQ(name, SvPVX(basename_sv)))
+           return TRUE;
     }
 
-    gvp = (GV**)hv_fetchs(stash, "ISA", FALSE);
-
-    if (gvp && (gv = *gvp) && isGV_with_GP(gv) && (av = GvAV(gv))) {
-       if (!hv || !subgen) {
-           gvp = (GV**)hv_fetchs(stash, "::ISA::CACHE::", TRUE);
-
-           gv = *gvp;
-
-           if (SvTYPE(gv) != SVt_PVGV)
-               gv_init(gv, stash, "::ISA::CACHE::", 14, TRUE);
-
-           if (!hv)
-               hv = GvHVn(gv);
-           if (!subgen) {
-               subgen = newSViv(PL_sub_generation);
-               GvSV(gv) = subgen;
-           }
-       }
-       if (hv) {
-           SV** svp = AvARRAY(av);
-           /* NOTE: No support for tied ISA */
-           I32 items = AvFILLp(av) + 1;
-           while (items--) {
-               SV* const sv = *svp++;
-               HV* const basestash = gv_stashsv(sv, 0);
-               if (!basestash) {
-                   if (ckWARN(WARN_MISC))
-                       Perl_warner(aTHX_ packWARN(WARN_SYNTAX),
-                                   "Can't locate package %"SVf" for @%s::ISA",
-                                   SVfARG(sv), hvname);
-                   continue;
-               }
-               if (isa_lookup(basestash, name, name_stash, len, level + 1)) {
-                   (void)hv_store(hv,name,len,&PL_sv_yes,0);
-                   return TRUE;
-               }
-           }
-           (void)hv_store(hv,name,len,&PL_sv_no,0);
-       }
-    }
     return FALSE;
 }
 
@@ -185,6 +133,7 @@ Perl_sv_does(pTHX_ SV *sv, const char *name)
 {
     const char *classname;
     bool does_it;
+    SV *methodname;
 
     dSP;
     ENTER;
@@ -199,7 +148,7 @@ Perl_sv_does(pTHX_ SV *sv, const char *name)
     if (sv_isobject(sv)) {
        classname = sv_reftype(SvRV(sv),TRUE);
     } else {
-       classname = SvPV(sv,PL_na);
+       classname = SvPV_nolen(sv);
     }
 
     if (strEQ(name,classname))
@@ -210,7 +159,12 @@ Perl_sv_does(pTHX_ SV *sv, const char *name)
     XPUSHs(sv_2mortal(newSVpv(name, 0)));
     PUTBACK;
 
-    call_method("isa", G_SCALAR);
+    methodname = sv_2mortal(newSVpv("isa", 0));
+    /* ugly hack: use the SvSCREAM flag so S_method_common
+     * can figure out we're calling DOES() and not isa(),
+     * and report eventual errors correctly. --rgs */
+    SvSCREAM_on(methodname);
+    call_sv(methodname, G_SCALAR | G_METHOD);
     SPAGAIN;
 
     does_it = SvTRUE( TOPs );
@@ -416,7 +370,7 @@ XS(XS_UNIVERSAL_DOES)
     PERL_UNUSED_ARG(cv);
 
     if (items != 2)
-       Perl_croak(aTHX_ "Usage: invocant->does(kind)");
+       Perl_croak(aTHX_ "Usage: invocant->DOES(kind)");
     else {
        SV * const sv = ST(0);
        const char *name;
@@ -1209,8 +1163,8 @@ XS(XS_re_regnames)
                         I32 *nums = (I32*)SvPVX(sv_dat);
                         for ( i = 0; i < SvIVX(sv_dat); i++ ) {
                             if ((I32)(re->lastcloseparen) >= nums[i] &&
-                                re->startp[nums[i]] != -1 &&
-                                re->endp[nums[i]] != -1)
+                                re->offs[nums[i]].start != -1 &&
+                                re->offs[nums[i]].end != -1)
                             {
                                 parno = nums[i];
                                 break;
@@ -1291,8 +1245,8 @@ XS(XS_re_regnames_iternext)
                     I32 *nums = (I32*)SvPVX(sv_dat);
                     for ( i = 0; i < SvIVX(sv_dat); i++ ) {
                         if ((I32)(re->lastcloseparen) >= nums[i] &&
-                            re->startp[nums[i]] != -1 &&
-                            re->endp[nums[i]] != -1)
+                            re->offs[nums[i]].start != -1 &&
+                            re->offs[nums[i]].end != -1)
                         {
                             parno = nums[i];
                             break;