Fix a couple of typos.
[p5sagit/p5-mst-13.2.git] / gv.c
diff --git a/gv.c b/gv.c
index 8a9b803..e20f278 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1,7 +1,7 @@
 /*    gv.c
  *
  *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- *    2000, 2001, 2002, 2003, by Larry Wall and others
+ *    2000, 2001, 2002, 2003, 2004, by Larry Wall and others
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
 
 /*
 =head1 GV Functions
+
+A GV is a structure which corresponds to to a Perl typeglob, ie *foo.
+It is a structure that holds a pointer to a scalar, an array, a hash etc,
+corresponding to $foo, @foo, %foo.
+
+GVs are usually found as values in stashes (symbol table hashes) where
+Perl stores its global variables.
+
+=cut
 */
 
 #include "EXTERN.h"
@@ -693,6 +702,10 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type)
     }
     len = namend - name;
 
+    /* $_ should always be in main:: even when our'ed */
+    if (*name == '_' && !name[1])
+       stash = PL_defstash;
+
     /* No stash in name, so see how we can default */
 
     if (!stash) {
@@ -720,7 +733,7 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type)
 
            if (global)
                stash = PL_defstash;
-           else if ((COP*)PL_curcop == &PL_compiling) {
+           else if (IN_PERL_COMPILETIME) {
                stash = PL_curstash;
                if (add && (PL_hints & HINT_STRICT_VARS) &&
                    sv_type != SVt_PVCV &&
@@ -761,12 +774,15 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type)
 
     if (!stash) {
        if (add) {
-           qerror(Perl_mess(aTHX_
+           register SV *err = Perl_mess(aTHX_
                 "Global symbol \"%s%s\" requires explicit package name",
                 (sv_type == SVt_PV ? "$"
                  : sv_type == SVt_PVAV ? "@"
                  : sv_type == SVt_PVHV ? "%"
-                 : ""), name));
+                 : ""), name);
+           if (USE_UTF8_IN_NAMES)
+               SvUTF8_on(err);
+           qerror(err);
            stash = GvHV(gv_fetchpv("<none>::", GV_ADDMULTI, SVt_PVHV));
        }
        else
@@ -1045,24 +1061,18 @@ Perl_gv_fetchpv(pTHX_ const char *nambeg, I32 add, I32 sv_type)
     case ']':
        if (len == 1) {
            SV *sv = GvSV(gv);
-           (void)SvUPGRADE(sv, SVt_PVNV);
-           Perl_sv_setpvf(aTHX_ sv,
-#if defined(PERL_SUBVERSION) && (PERL_SUBVERSION > 0)
-                           "%8.6"
-#else
-                           "%5.3"
-#endif
-                           NVff,
-                           SvNVX(PL_patchlevel));
-           SvNVX(sv) = SvNVX(PL_patchlevel);
-           SvNOK_on(sv);
-           SvREADONLY_on(sv);
+           if (!sv_derived_from(PL_patchlevel, "version"))
+               (void *)upg_version(PL_patchlevel);
+           GvSV(gv) = vnumify(PL_patchlevel);
+           SvREADONLY_on(GvSV(gv));
+           SvREFCNT_dec(sv);
        }
        break;
     case '\026':       /* $^V */
        if (len == 1) {
            SV *sv = GvSV(gv);
-           GvSV(gv) = SvREFCNT_inc(PL_patchlevel);
+           GvSV(gv) = new_version(PL_patchlevel);
+           SvREADONLY_on(GvSV(gv));
            SvREFCNT_dec(sv);
        }
        break;
@@ -1076,7 +1086,7 @@ Perl_gv_fullname4(pTHX_ SV *sv, GV *gv, const char *prefix, bool keepmain)
     char *name;
     HV *hv = GvSTASH(gv);
     if (!hv) {
-       (void)SvOK_off(sv);
+       SvOK_off(sv);
        return;
     }
     sv_setpv(sv, prefix ? prefix : "");
@@ -1239,7 +1249,8 @@ Perl_gp_free(pTHX_ GV *gv)
     if (gp->gp_refcnt == 0) {
        if (ckWARN_d(WARN_INTERNAL))
            Perl_warner(aTHX_ packWARN(WARN_INTERNAL),
-                       "Attempt to free unreferenced glob pointers");
+                       "Attempt to free unreferenced glob pointers"
+                        pTHX__FORMAT pTHX__VALUE);
         return;
     }
     if (gp->gp_cv) {
@@ -1253,7 +1264,7 @@ Perl_gp_free(pTHX_ GV *gv)
     }
 
     if (gp->gp_sv) SvREFCNT_dec(gp->gp_sv);
-    if (gp->gp_sv) SvREFCNT_dec(gp->gp_av);
+    if (gp->gp_av) SvREFCNT_dec(gp->gp_av);
     if (gp->gp_hv) {
         if (PL_stashcache && HvNAME(gp->gp_hv))
              hv_delete(PL_stashcache,