The new(er) way of controlling Unicode I/O (and other) features;
[p5sagit/p5-mst-13.2.git] / gv.c
diff --git a/gv.c b/gv.c
index 88e343a..1d0694a 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -133,13 +133,6 @@ Perl_gv_init(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len, int multi)
        CvGV(GvCV(gv)) = gv;
        CvFILE_set_from_cop(GvCV(gv), PL_curcop);
        CvSTASH(GvCV(gv)) = PL_curstash;
-#ifdef USE_5005THREADS
-       CvOWNER(GvCV(gv)) = 0;
-       if (!CvMUTEXP(GvCV(gv))) {
-           New(666, CvMUTEXP(GvCV(gv)), 1, perl_mutex);
-           MUTEX_INIT(CvMUTEXP(GvCV(gv)));
-       }
-#endif /* USE_5005THREADS */
        if (proto) {
            sv_setpv((SV*)GvCV(gv), proto);
            Safefree(proto);
@@ -261,8 +254,8 @@ Perl_gv_fetchmeth(pTHX_ HV *stash, const char *name, STRLEN len, I32 level)
            HV* basestash = gv_stashsv(sv, FALSE);
            if (!basestash) {
                if (ckWARN(WARN_MISC))
-                   Perl_warner(aTHX_ packWARN(WARN_MISC), "Can't locate package %s for @%s::ISA",
-                       SvPVX(sv), HvNAME(stash));
+                   Perl_warner(aTHX_ packWARN(WARN_MISC), "Can't locate package %"SVf" for @%s::ISA",
+                       sv, HvNAME(stash));
                continue;
            }
            gv = gv_fetchmeth(basestash, name, len,
@@ -401,6 +394,10 @@ Perl_gv_fetchmethod_autoload(pTHX_ HV *stash, const char *name, I32 autoload)
     register const char *nend;
     const char *nsplit = 0;
     GV* gv;
+    HV* ostash = stash;
+
+    if (stash && SvTYPE(stash) < SVt_PVHV)
+       stash = Nullhv;
 
     for (nend = name; *nend; nend++) {
        if (*nend == '\'')
@@ -433,6 +430,7 @@ Perl_gv_fetchmethod_autoload(pTHX_ HV *stash, const char *name, I32 autoload)
                gv_stashpvn(origname, nsplit - origname - 7, FALSE))
              stash = gv_stashpvn(origname, nsplit - origname, TRUE);
        }
+       ostash = stash;
     }
 
     gv = gv_fetchmeth(stash, name, nend - name, 0);
@@ -440,7 +438,7 @@ Perl_gv_fetchmethod_autoload(pTHX_ HV *stash, const char *name, I32 autoload)
        if (strEQ(name,"import") || strEQ(name,"unimport"))
            gv = (GV*)&PL_sv_yes;
        else if (autoload)
-           gv = gv_autoload4(stash, name, nend - name, TRUE);
+           gv = gv_autoload4(ostash, name, nend - name, TRUE);
     }
     else if (autoload) {
        CV* cv = GvCV(gv);
@@ -475,11 +473,19 @@ Perl_gv_autoload4(pTHX_ HV *stash, const char *name, STRLEN len, I32 method)
     HV* varstash;
     GV* vargv;
     SV* varsv;
+    char *packname = "";
 
-    if (!stash)
-       return Nullgv;  /* UNIVERSAL::AUTOLOAD could cause trouble */
     if (len == autolen && strnEQ(name, autoload, autolen))
        return Nullgv;
+    if (stash) {
+       if (SvTYPE(stash) < SVt_PVHV) {
+           packname = SvPV_nolen((SV*)stash);
+           stash = Nullhv;
+       }
+       else {
+           packname = HvNAME(stash);
+       }
+    }
     if (!(gv = gv_fetchmeth(stash, autoload, autolen, FALSE)))
        return Nullgv;
     cv = GvCV(gv);
@@ -494,9 +500,8 @@ Perl_gv_autoload4(pTHX_ HV *stash, const char *name, STRLEN len, I32 method)
        (GvCVGEN(gv) || GvSTASH(gv) != stash))
        Perl_warner(aTHX_ packWARN2(WARN_DEPRECATED, WARN_SYNTAX),
          "Use of inherited AUTOLOAD for non-method %s::%.*s() is deprecated",
-            HvNAME(stash), (int)len, name);
+            packname, (int)len, name);
 
-#ifndef USE_5005THREADS
     if (CvXSUB(cv)) {
         /* rather than lookup/init $AUTOLOAD here
          * only to have the XSUB do another lookup for $AUTOLOAD
@@ -508,7 +513,6 @@ Perl_gv_autoload4(pTHX_ HV *stash, const char *name, STRLEN len, I32 method)
         SvCUR(cv) = len;
         return gv;
     }
-#endif
 
     /*
      * Given &FOO::AUTOLOAD, set $FOO::AUTOLOAD to desired function name.
@@ -520,17 +524,11 @@ Perl_gv_autoload4(pTHX_ HV *stash, const char *name, STRLEN len, I32 method)
     vargv = *(GV**)hv_fetch(varstash, autoload, autolen, TRUE);
     ENTER;
 
-#ifdef USE_5005THREADS
-    sv_lock((SV *)varstash);
-#endif
     if (!isGV(vargv))
        gv_init(vargv, varstash, autoload, autolen, FALSE);
     LEAVE;
     varsv = GvSV(vargv);
-#ifdef USE_5005THREADS
-    sv_lock(varsv);
-#endif
-    sv_setpv(varsv, HvNAME(stash));
+    sv_setpv(varsv, packname);
     sv_catpvn(varsv, "::", 2);
     sv_catpvn(varsv, name, len);
     SvTAINTED_off(varsv);
@@ -766,10 +764,8 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type)
                  : sv_type == SVt_PVAV ? "@"
                  : sv_type == SVt_PVHV ? "%"
                  : ""), name));
-           stash = PL_nullstash;
        }
-       else
-           return Nullgv;
+       return Nullgv;
     }
 
     if (!SvREFCNT(stash))      /* symbol table under destruction */
@@ -978,9 +974,15 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type)
             goto ro_magicalize;
         else
             break;
+    case '\025':
+        if (len > 1 && strNE(name, "\025NICODE")) 
+           break;
+       goto ro_magicalize;
+
     case '\027':       /* $^W & $^WARNING_BITS */
-       if (len > 1 && strNE(name, "\027ARNING_BITS")
-           && strNE(name, "\027IDE_SYSTEM_CALLS"))
+       if (len > 1
+           && strNE(name, "\027ARNING_BITS")
+           )
            break;
        goto magicalize;
 
@@ -1332,21 +1334,19 @@ Perl_Gv_AMupdate(pTHX_ HV *stash)
                /* GvSV contains the name of the method. */
                GV *ngv = Nullgv;
                
-               DEBUG_o( Perl_deb(aTHX_ "Resolving method `%.256s' for overloaded `%s' in package `%.256s'\n",
-                            SvPV_nolen(GvSV(gv)), cp, HvNAME(stash)) );
+               DEBUG_o( Perl_deb(aTHX_ "Resolving method `%.256"SVf"' for overloaded `%s' in package `%.256s'\n",
+                            GvSV(gv), cp, HvNAME(stash)) );
                if (!SvPOK(GvSV(gv))
                    || !(ngv = gv_fetchmethod_autoload(stash, SvPVX(GvSV(gv)),
                                                       FALSE)))
                {
                    /* Can be an import stub (created by `can'). */
-                   if (GvCVGEN(gv)) {
-                       Perl_croak(aTHX_ "Stub found while resolving method `%.256s' overloading `%s' in package `%.256s'",
-                             (SvPOK(GvSV(gv)) ?  SvPVX(GvSV(gv)) : "???" ),
-                             cp, HvNAME(stash));
-                   } else
-                       Perl_croak(aTHX_ "Can't resolve method `%.256s' overloading `%s' in package `%.256s'",
-                             (SvPOK(GvSV(gv)) ?  SvPVX(GvSV(gv)) : "???" ),
-                             cp, HvNAME(stash));
+                   SV *gvsv = GvSV(gv);
+                   const char *name = SvPOK(gvsv) ?  SvPVX(gvsv) : "???";
+                   Perl_croak(aTHX_ "%s method `%.256s' overloading `%s' in package `%.256s'",
+                              (GvCVGEN(gv) ? "Stub found while resolving"
+                               : "Can't resolve"),
+                              name, cp, HvNAME(stash));
                }
                cv = GvCV(gv = ngv);
            }
@@ -1799,10 +1799,13 @@ Perl_is_gv_magical(pTHX_ char *name, STRLEN len, U32 flags)
            goto yes;
        }
        break;
+    case '\025':
+        if (len > 1 && strEQ(name, "\025NICODE"))
+           goto yes;
     case '\027':   /* $^W & $^WARNING_BITS */
        if (len == 1
            || (len == 12 && strEQ(name, "\027ARNING_BITS"))
-           || (len == 17 && strEQ(name, "\027IDE_SYSTEM_CALLS")))
+           )
        {
            goto yes;
        }