[asperl] added AS patch#12 with minor changes
[p5sagit/p5-mst-13.2.git] / gv.c
diff --git a/gv.c b/gv.c
index 3633e7b..62e39c2 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -104,7 +104,7 @@ gv_init(GV *gv, HV *stash, char *name, STRLEN len, int multi)
        GvMULTI_on(gv);
 }
 
-static void
+STATIC void
 gv_init_sv(GV *gv, I32 sv_type)
 {
     switch (sv_type) {
@@ -426,18 +426,17 @@ gv_fetchpv(char *nambeg, I32 add, I32 sv_type)
                tmpbuf[len++] = ':';
                tmpbuf[len] = '\0';
                gvp = (GV**)hv_fetch(stash,tmpbuf,len,add);
+               gv = gvp ? *gvp : Nullgv;
+               if (gv && gv != (GV*)&sv_undef) {
+                   if (SvTYPE(gv) != SVt_PVGV)
+                       gv_init(gv, stash, tmpbuf, len, (add & 2));
+                   else
+                       GvMULTI_on(gv);
+               }
                if (tmpbuf != autobuf)
                    Safefree(tmpbuf);
-               if (!gvp || *gvp == (GV*)&sv_undef)
+               if (!gv || gv == (GV*)&sv_undef)
                    return Nullgv;
-               gv = *gvp;
-
-                if (SvTYPE(gv) == SVt_PVGV)
-                    GvMULTI_on(gv);
-                else if (!add)
-                    return Nullgv;
-               else
-                   gv_init(gv, stash, nambeg, namend - nambeg, (add & 2));
 
                if (!(stash = GvHV(gv)))
                    stash = GvHV(gv) = newHV();
@@ -531,17 +530,26 @@ gv_fetchpv(char *nambeg, I32 add, I32 sv_type)
     /* By this point we should have a stash and a name */
 
     if (!stash) {
-       if (add) {
-           warn("Global symbol \"%s\" requires explicit package name", name);
-           ++error_count;
-           stash = curstash ? curstash : defstash;     /* avoid core dumps */
-           add_gvflags = ((sv_type == SVt_PV) ? GVf_IMPORTED_SV
-                          : (sv_type == SVt_PVAV) ? GVf_IMPORTED_AV
-                          : (sv_type == SVt_PVHV) ? GVf_IMPORTED_HV
-                          : 0);
-       }
-       else
+       if (!add)
            return Nullgv;
+       if (add & ~2) {
+           char sv_type_char = ((sv_type == SVt_PV) ? '$'
+                                : (sv_type == SVt_PVAV) ? '@'
+                                : (sv_type == SVt_PVHV) ? '%'
+                                : 0);
+           if (sv_type_char) 
+               warn("Global symbol \"%c%s\" requires explicit package name",
+                    sv_type_char, name);
+           else
+               warn("Global symbol \"%s\" requires explicit package name",
+                    name);
+       }
+       ++error_count;
+       stash = curstash ? curstash : defstash; /* avoid core dumps */
+       add_gvflags = ((sv_type == SVt_PV) ? GVf_IMPORTED_SV
+                      : (sv_type == SVt_PVAV) ? GVf_IMPORTED_AV
+                      : (sv_type == SVt_PVHV) ? GVf_IMPORTED_HV
+                      : 0);
     }
 
     if (!SvREFCNT(stash))      /* symbol table under destruction */
@@ -1145,15 +1153,19 @@ amagic_call(SV *left, SV *right, int method, int flags)
    break;
         case copy_amg:
           {
-            SV* ref=SvRV(left);
-            if (!SvROK(ref) && SvTYPE(ref) <= SVt_PVMG) {
+            /*
+                 * SV* ref causes confusion with the interpreter variable of
+                 * the same name
+                 */
+            SV* tmpRef=SvRV(left);
+            if (!SvROK(tmpRef) && SvTYPE(tmpRef) <= SVt_PVMG) {
                /*
                 * Just to be extra cautious.  Maybe in some
                 * additional cases sv_setsv is safe, too.
                 */
-               SV* newref = newSVsv(ref);
+               SV* newref = newSVsv(tmpRef);
                SvOBJECT_on(newref);
-               SvSTASH(newref) = (HV*)SvREFCNT_inc(SvSTASH(ref));
+               SvSTASH(newref) = (HV*)SvREFCNT_inc(SvSTASH(tmpRef));
                return newref;
             }
           }
@@ -1311,7 +1323,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
     PUTBACK;
     pp_pushmark(ARGS);
 
-    EXTEND(sp, notfound + 5);
+    EXTEND(SP, notfound + 5);
     PUSHs(lr>0? right: left);
     PUSHs(lr>0? left: right);
     PUSHs( lr > 0 ? &sv_yes : ( assign ? &sv_undef : &sv_no ));
@@ -1322,7 +1334,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
     PUTBACK;
 
     if (op = pp_entersub(ARGS))
-      runops();
+      CALLRUNOPS();
     LEAVE;
     SPAGAIN;