[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 80090c9..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) {
@@ -399,7 +399,6 @@ gv_fetchpv(char *nambeg, I32 add, I32 sv_type)
     register char *namend;
     HV *stash = 0;
     U32 add_gvflags = 0;
-    char *tmpbuf;
 
     if (*name == '*' && isALPHA(name[1])) /* accidental stringify on a GV? */
        name++;
@@ -415,7 +414,13 @@ gv_fetchpv(char *nambeg, I32 add, I32 sv_type)
 
            len = namend - name;
            if (len > 0) {
-               New(601, tmpbuf, len+3, char);
+               char *tmpbuf;
+               char autobuf[64];
+
+               if (len < sizeof(autobuf) - 2)
+                   tmpbuf = autobuf;
+               else
+                   New(601, tmpbuf, len+3, char);
                Copy(name, tmpbuf, len, char);
                tmpbuf[len++] = ':';
                tmpbuf[len++] = ':';
@@ -428,11 +433,10 @@ gv_fetchpv(char *nambeg, I32 add, I32 sv_type)
                    else
                        GvMULTI_on(gv);
                }
-               Safefree(tmpbuf);
+               if (tmpbuf != autobuf)
+                   Safefree(tmpbuf);
                if (!gv || gv == (GV*)&sv_undef)
                    return Nullgv;
-               else
-                   gv_init(gv, stash, nambeg, namend - nambeg, (add & 2));
 
                if (!(stash = GvHV(gv)))
                    stash = GvHV(gv) = newHV();
@@ -526,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 */
@@ -1140,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;
             }
           }
@@ -1306,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 ));
@@ -1317,7 +1334,7 @@ amagic_call(SV *left, SV *right, int method, int flags)
     PUTBACK;
 
     if (op = pp_entersub(ARGS))
-      runops();
+      CALLRUNOPS();
     LEAVE;
     SPAGAIN;