This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Abstract the specific use of SvCUR in GVs for detecting variables on
[perl5.git] / gv.h
diff --git a/gv.h b/gv.h
index 6dd206c..81a42cf 100644 (file)
--- a/gv.h
+++ b/gv.h
@@ -1,6 +1,7 @@
 /*    gv.h
  *
- *    Copyright (c) 1991-2001, Larry Wall
+ *    Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ *    2000, 2001, 2002, 2003, 2004, 2005, 2006, 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.
@@ -17,22 +18,55 @@ struct gp {
     GV *       gp_egv;         /* effective gv, if *glob */
     CV *       gp_cv;          /* subroutine value */
     U32                gp_cvgen;       /* generational validity of cached gv_cv */
-    U32                gp_flags;       /* XXX unused */
     line_t     gp_line;        /* line first declared at (for -w) */
     char *     gp_file;        /* file first declared in (for -w) */
 };
 
-#if defined(CRIPPLED_CC) && (defined(iAPX286) || defined(M_I286) || defined(I80286))
-#define MICROPORT
-#endif
-
 #define GvXPVGV(gv)    ((XPVGV*)SvANY(gv))
 
-#define GvGP(gv)       (GvXPVGV(gv)->xgv_gp)
-#define GvNAME(gv)     (GvXPVGV(gv)->xgv_name)
-#define GvNAMELEN(gv)  (GvXPVGV(gv)->xgv_namelen)
-#define GvSTASH(gv)    (GvXPVGV(gv)->xgv_stash)
-#define GvFLAGS(gv)    (GvXPVGV(gv)->xgv_flags)
+
+#if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
+#  define GvGP(gv)                                                     \
+       (*({GV *const shplep = (GV *) gv;                               \
+           assert(SvTYPE(shplep) == SVt_PVGV ||                        \
+           SvTYPE(shplep) == SVt_PVLV);                                \
+           assert(isGV_with_GP(shplep));                               \
+           &((shplep)->sv_u.svu_gp);}))
+#  define GvFLAGS(gv)                                                  \
+       (*({GV *const yaah  = (GV *) gv;                                \
+           assert(SvTYPE(yaah) == SVt_PVGV || SvTYPE(yaah) == SVt_PVLV); \
+           assert(isGV_with_GP(yaah));                                 \
+           &(GvXPVGV(yaah)->xgv_flags);}))
+#  define GvSTASH(gv)                                                  \
+       (*({ GV *_gv = (GV *) gv;                                       \
+           assert(isGV_with_GP(_gv));                                  \
+           assert(SvTYPE(_gv) == SVt_PVGV || SvTYPE(_gv) >= SVt_PVLV); \
+           &(GvXPVGV(_gv)->xnv_u.xgv_stash);                           \
+        }))
+#  define GvNAME(gv)                                                   \
+       (*({ GV *zzzz = (GV *) gv;                                      \
+           assert(isGV_with_GP(zzzz));                                 \
+           assert(SvTYPE(zzzz) == SVt_PVGV || SvTYPE(zzzz) >= SVt_PVLV); \
+           &(GvXPVGV(zzzz)->xgv_name);                                 \
+        }))
+#  define GvNAMELEN(gv)                                                        \
+       (*({ GV *glank = (GV *) gv;                                     \
+           assert(isGV_with_GP(glank));                                \
+           assert(SvTYPE(glank) == SVt_PVGV || SvTYPE(glank) >= SVt_PVLV); \
+           &(GvXPVGV(glank)->xgv_namelen);                             \
+        }))
+#else
+#  define GvGP(gv)     ((gv)->sv_u.svu_gp)
+#  define GvFLAGS(gv)  (GvXPVGV(gv)->xgv_flags)
+#  define GvSTASH(gv)  (GvXPVGV(gv)->xnv_u.xgv_stash)
+#  define GvNAME(gv)   (GvXPVGV(gv)->xgv_name)
+#  define GvNAMELEN(gv)        (GvXPVGV(gv)->xgv_namelen)
+#endif
+
+#define        GvASSIGN_GENERATION(gv)         (0 + ((XPV*) SvANY(gv))->xpv_cur)
+#define        GvASSIGN_GENERATION_set(gv,val)                 \
+       STMT_START { assert(SvTYPE(gv) == SVt_PVGV);    \
+               (((XPV*) SvANY(gv))->xpv_cur = (val)); } STMT_END
 
 /*
 =head1 GV Functions
@@ -45,8 +79,16 @@ Return the SV from the GV.
 */
 
 #define GvSV(gv)       (GvGP(gv)->gp_sv)
+#ifdef PERL_DONT_CREATE_GVSV
+#define GvSVn(gv)      (*(GvGP(gv)->gp_sv ? \
+                        &(GvGP(gv)->gp_sv) : \
+                        &(GvGP(gv_SVadd(gv))->gp_sv)))
+#else
+#define GvSVn(gv)      GvSV(gv)
+#endif
+
 #define GvREFCNT(gv)   (GvGP(gv)->gp_refcnt)
-#define GvIO(gv)       ((gv) && SvTYPE((SV*)gv) == SVt_PVGV ? GvIOp(gv) : 0)
+#define GvIO(gv)       ((gv) && SvTYPE((SV*)gv) == SVt_PVGV && GvGP(gv) ? GvIOp(gv) : 0)
 #define GvIOp(gv)      (GvGP(gv)->gp_io)
 #define GvIOn(gv)      (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
 
@@ -56,28 +98,18 @@ Return the SV from the GV.
 /* This macro is deprecated.  Do not use! */
 #define GvREFCNT_inc(gv) ((GV*)SvREFCNT_inc(gv))       /* DO NOT USE */
 
-#ifdef MICROPORT       /* Microport 2.4 hack */
-AV *GvAVn();
-#else
 #define GvAVn(gv)      (GvGP(gv)->gp_av ? \
                         GvGP(gv)->gp_av : \
                         GvGP(gv_AVadd(gv))->gp_av)
-#endif
 #define GvHV(gv)       ((GvGP(gv))->gp_hv)
 
-#ifdef MICROPORT       /* Microport 2.4 hack */
-HV *GvHVn();
-#else
 #define GvHVn(gv)      (GvGP(gv)->gp_hv ? \
                         GvGP(gv)->gp_hv : \
                         GvGP(gv_HVadd(gv))->gp_hv)
-#endif                 /* Microport 2.4 hack */
 
 #define GvCV(gv)       (GvGP(gv)->gp_cv)
 #define GvCVGEN(gv)    (GvGP(gv)->gp_cvgen)
-#define GvCVu(gv)      (GvGP(gv)->gp_cvgen ? Nullcv : GvGP(gv)->gp_cv)
-
-#define GvGPFLAGS(gv)  (GvGP(gv)->gp_flags)
+#define GvCVu(gv)      (GvGP(gv)->gp_cvgen ? NULL : GvGP(gv)->gp_cv)
 
 #define GvLINE(gv)     (GvGP(gv)->gp_line)
 #define GvFILE(gv)     (GvGP(gv)->gp_file)
@@ -133,12 +165,9 @@ HV *GvHVn();
 #define GvIN_PAD_on(gv)                (GvFLAGS(gv) |= GVf_IN_PAD)
 #define GvIN_PAD_off(gv)       (GvFLAGS(gv) &= ~GVf_IN_PAD)
 
-/* XXX: all GvFLAGS options are used, borrowing GvGPFLAGS for the moment */
-
-#define GVf_UNIQUE           0x0001
-#define GvUNIQUE(gv)         (GvGP(gv) && (GvGPFLAGS(gv) & GVf_UNIQUE))
-#define GvUNIQUE_on(gv)      (GvGPFLAGS(gv) |= GVf_UNIQUE)
-#define GvUNIQUE_off(gv)     (GvGPFLAGS(gv) &= ~GVf_UNIQUE)
+#define GvUNIQUE(gv)            0
+#define GvUNIQUE_on(gv)
+#define GvUNIQUE_off(gv)
 
 #ifdef USE_ITHREADS
 #define GV_UNIQUE_CHECK
@@ -164,3 +193,17 @@ HV *GvHVn();
 #define GV_ADDWARN     0x04    /* add, but warn if symbol wasn't already there */
 #define GV_ADDINEVAL   0x08    /* add, as though we're doing so within an eval */
 #define GV_NOINIT      0x10    /* add, but don't init symbol, if type != PVGV */
+/* This is used by toke.c to avoid turing placeholder constants in the symbol
+   table into full PVGVs with attached constant subroutines.  */
+#define GV_NOADD_NOINIT        0x20    /* Don't add the symbol if it's not there.
+                                  Don't init it if it is there but ! PVGV */
+#define GV_NOEXPAND    0x40    /* Don't expand SvOK() entries to PVGV */
+#define GV_NOTQUAL     0x80    /* A plain symbol name, not qualified with a
+                                  package (so skip checks for :: and ')  */
+
+/*      SVf_UTF8 (more accurately the return value from SvUTF8) is also valid
+       as a flag to gv_fetch_pvn_flags, so ensure it lies outside this range.
+*/
+#define gv_fullname3(sv,gv,prefix) gv_fullname4(sv,gv,prefix,TRUE)
+#define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE)
+#define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)