3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 SV * gp_sv; /* scalar value */
13 U32 gp_refcnt; /* how many globs point to this? */
14 struct io * gp_io; /* filehandle value */
15 CV * gp_form; /* format value */
16 AV * gp_av; /* array value */
17 HV * gp_hv; /* hash value */
18 GV * gp_egv; /* effective gv, if *glob */
19 CV * gp_cv; /* subroutine value */
20 U32 gp_cvgen; /* generational validity of cached gv_cv */
21 line_t gp_line; /* line first declared at (for -w) */
22 char * gp_file; /* file first declared in (for -w) */
25 #define GvXPVGV(gv) ((XPVGV*)SvANY(gv))
28 #if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
30 (*({GV *const shplep = (GV *) (gv); \
31 assert(SvTYPE(shplep) == SVt_PVGV || SvTYPE(shplep) == SVt_PVLV); \
32 assert(isGV_with_GP(shplep)); \
33 &((shplep)->sv_u.svu_gp);}))
34 # define GvFLAGS(gv) \
35 (*({GV *const yaah = (GV *) (gv); \
36 assert(SvTYPE(yaah) == SVt_PVGV || SvTYPE(yaah) == SVt_PVLV); \
37 assert(isGV_with_GP(yaah)); \
38 &(GvXPVGV(yaah)->xpv_cur);}))
39 # define GvSTASH(gv) \
40 (*({ GV * const _gv = (GV *) (gv); \
41 assert(isGV_with_GP(_gv)); \
42 assert(SvTYPE(_gv) == SVt_PVGV || SvTYPE(_gv) >= SVt_PVLV); \
43 &(GvXPVGV(_gv)->xnv_u.xgv_stash); \
45 # define GvNAME_HEK(gv) \
46 (*({ GV * const zzzz = (GV *) (gv); \
47 assert(isGV_with_GP(zzzz)); \
48 assert(SvTYPE(zzzz) == SVt_PVGV || SvTYPE(zzzz) >= SVt_PVLV); \
49 &(GvXPVGV(zzzz)->xiv_u.xivu_namehek); \
52 # define GvGP(gv) ((gv)->sv_u.svu_gp)
53 # define GvFLAGS(gv) (GvXPVGV(gv)->xpv_cur)
54 # define GvSTASH(gv) (GvXPVGV(gv)->xnv_u.xgv_stash)
55 # define GvNAME_HEK(gv) (GvXPVGV(gv)->xiv_u.xivu_namehek)
58 #define GvNAME_get(gv) (GvNAME_HEK(gv) ? HEK_KEY(GvNAME_HEK(gv)) : NULL)
59 #define GvNAMELEN_get(gv) (GvNAME_HEK(gv) ? HEK_LEN(GvNAME_HEK(gv)) : 0)
61 #define GvNAME(gv) GvNAME_get(gv)
62 #define GvNAMELEN(gv) GvNAMELEN_get(gv)
64 #define GvASSIGN_GENERATION(gv) (0 + ((XPV*) SvANY(gv))->xpv_len)
65 #define GvASSIGN_GENERATION_set(gv,val) \
66 STMT_START { assert(SvTYPE(gv) == SVt_PVGV); \
67 (((XPV*) SvANY(gv))->xpv_len = (val)); } STMT_END
72 =for apidoc Am|SV*|GvSV|GV* gv
74 Return the SV from the GV.
79 #define GvSV(gv) (GvGP(gv)->gp_sv)
80 #ifdef PERL_DONT_CREATE_GVSV
81 #define GvSVn(gv) (*(GvGP(gv)->gp_sv ? \
82 &(GvGP(gv)->gp_sv) : \
83 &(GvGP(gv_SVadd(gv))->gp_sv)))
85 #define GvSVn(gv) GvSV(gv)
88 #define GvREFCNT(gv) (GvGP(gv)->gp_refcnt)
89 #define GvIO(gv) ((gv) && SvTYPE((SV*)gv) == SVt_PVGV && GvGP(gv) ? GvIOp(gv) : 0)
90 #define GvIOp(gv) (GvGP(gv)->gp_io)
91 #define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
93 #define GvFORM(gv) (GvGP(gv)->gp_form)
94 #define GvAV(gv) (GvGP(gv)->gp_av)
96 /* This macro is deprecated. Do not use! */
97 #define GvREFCNT_inc(gv) ((GV*)SvREFCNT_inc(gv)) /* DO NOT USE */
99 #define GvAVn(gv) (GvGP(gv)->gp_av ? \
101 GvGP(gv_AVadd(gv))->gp_av)
102 #define GvHV(gv) ((GvGP(gv))->gp_hv)
104 #define GvHVn(gv) (GvGP(gv)->gp_hv ? \
106 GvGP(gv_HVadd(gv))->gp_hv)
108 #define GvCV(gv) (GvGP(gv)->gp_cv)
109 #define GvCVGEN(gv) (GvGP(gv)->gp_cvgen)
110 #define GvCVu(gv) (GvGP(gv)->gp_cvgen ? NULL : GvGP(gv)->gp_cv)
112 #define GvLINE(gv) (GvGP(gv)->gp_line)
113 #define GvFILE(gv) (GvGP(gv)->gp_file)
114 #define GvFILEGV(gv) (gv_fetchfile(GvFILE(gv)))
116 #define GvEGV(gv) (GvGP(gv)->gp_egv)
117 #define GvENAME(gv) GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
118 #define GvESTASH(gv) GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
120 #define GVf_INTRO 0x01
121 #define GVf_MULTI 0x02
122 #define GVf_ASSUMECV 0x04
123 #define GVf_IN_PAD 0x08
124 #define GVf_IMPORTED 0xF0
125 #define GVf_IMPORTED_SV 0x10
126 #define GVf_IMPORTED_AV 0x20
127 #define GVf_IMPORTED_HV 0x40
128 #define GVf_IMPORTED_CV 0x80
130 #define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
131 #define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
132 #define GvINTRO_off(gv) (GvFLAGS(gv) &= ~GVf_INTRO)
134 #define GvMULTI(gv) (GvFLAGS(gv) & GVf_MULTI)
135 #define GvMULTI_on(gv) (GvFLAGS(gv) |= GVf_MULTI)
136 #define GvMULTI_off(gv) (GvFLAGS(gv) &= ~GVf_MULTI)
138 #define GvASSUMECV(gv) (GvFLAGS(gv) & GVf_ASSUMECV)
139 #define GvASSUMECV_on(gv) (GvFLAGS(gv) |= GVf_ASSUMECV)
140 #define GvASSUMECV_off(gv) (GvFLAGS(gv) &= ~GVf_ASSUMECV)
142 #define GvIMPORTED(gv) (GvFLAGS(gv) & GVf_IMPORTED)
143 #define GvIMPORTED_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED)
144 #define GvIMPORTED_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED)
146 #define GvIMPORTED_SV(gv) (GvFLAGS(gv) & GVf_IMPORTED_SV)
147 #define GvIMPORTED_SV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_SV)
148 #define GvIMPORTED_SV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_SV)
150 #define GvIMPORTED_AV(gv) (GvFLAGS(gv) & GVf_IMPORTED_AV)
151 #define GvIMPORTED_AV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_AV)
152 #define GvIMPORTED_AV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_AV)
154 #define GvIMPORTED_HV(gv) (GvFLAGS(gv) & GVf_IMPORTED_HV)
155 #define GvIMPORTED_HV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_HV)
156 #define GvIMPORTED_HV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_HV)
158 #define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV)
159 #define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
160 #define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)
162 #define GvIN_PAD(gv) (GvFLAGS(gv) & GVf_IN_PAD)
163 #define GvIN_PAD_on(gv) (GvFLAGS(gv) |= GVf_IN_PAD)
164 #define GvIN_PAD_off(gv) (GvFLAGS(gv) &= ~GVf_IN_PAD)
166 #define GvUNIQUE(gv) 0
167 #define GvUNIQUE_on(gv)
168 #define GvUNIQUE_off(gv)
171 #define GV_UNIQUE_CHECK
173 #undef GV_UNIQUE_CHECK
176 #define Nullgv Null(GV*)
179 #define DM_RUID 0x001
180 #define DM_EUID 0x002
182 #define DM_RGID 0x010
183 #define DM_EGID 0x020
184 #define DM_DELAY 0x100
187 * symbol creation flags, for use in gv_fetchpv() and get_*v()
189 #define GV_ADD 0x01 /* add, if symbol not already there
190 For gv_name_set, adding a HEK for the first
191 time, so don't try to free what's there. */
192 #define GV_ADDMULTI 0x02 /* add, pretending it has been added already */
193 #define GV_ADDWARN 0x04 /* add, but warn if symbol wasn't already there */
194 #define GV_ADDINEVAL 0x08 /* add, as though we're doing so within an eval */
195 #define GV_NOINIT 0x10 /* add, but don't init symbol, if type != PVGV */
196 /* This is used by toke.c to avoid turing placeholder constants in the symbol
197 table into full PVGVs with attached constant subroutines. */
198 #define GV_NOADD_NOINIT 0x20 /* Don't add the symbol if it's not there.
199 Don't init it if it is there but ! PVGV */
200 #define GV_NOEXPAND 0x40 /* Don't expand SvOK() entries to PVGV */
201 #define GV_NOTQUAL 0x80 /* A plain symbol name, not qualified with a
202 package (so skip checks for :: and ') */
204 /* SVf_UTF8 (more accurately the return value from SvUTF8) is also valid
205 as a flag to gv_fetch_pvn_flags, so ensure it lies outside this range.
207 #define gv_fullname3(sv,gv,prefix) gv_fullname4(sv,gv,prefix,TRUE)
208 #define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE)
209 #define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)