This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
remove bogus < in B<> formatting code
[perl5.git] / gv.h
CommitLineData
a0d0e21e 1/* gv.h
79072805 2 *
1129b882
NC
3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 * 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others
79072805
LW
5 *
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.
8 *
79072805
LW
9 */
10
11struct gp {
12 SV * gp_sv; /* scalar value */
79072805 13 struct io * gp_io; /* filehandle value */
79072805 14 CV * gp_cv; /* subroutine value */
463ee0b2 15 U32 gp_cvgen; /* generational validity of cached gv_cv */
9bd87817
NC
16 U32 gp_refcnt; /* how many globs point to this? */
17 HV * gp_hv; /* hash value */
18 AV * gp_av; /* array value */
19 CV * gp_form; /* format value */
20 GV * gp_egv; /* effective gv, if *glob */
79072805 21 line_t gp_line; /* line first declared at (for -w) */
f4890806 22 HEK * gp_file_hek; /* file first declared in (for -w) */
79072805
LW
23};
24
79072805
LW
25#define GvXPVGV(gv) ((XPVGV*)SvANY(gv))
26
a5f75d66 27
e51a6fb1 28#if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__INTEL_COMPILER)
dedf8e73 29# define GvGP(gv) \
c43ae56f 30 (0+(*({GV *const _gvgp = (GV *) (gv); \
603aa20d
RU
31 assert(SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV); \
32 assert(isGV_with_GP(_gvgp)); \
c43ae56f
DM
33 &((_gvgp)->sv_u.svu_gp);})))
34# define GvGP_set(gv,gp) \
35 {GV *const _gvgp = (GV *) (gv); \
36 assert(SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV); \
37 assert(isGV_with_GP(_gvgp)); \
38 (_gvgp)->sv_u.svu_gp = (gp); }
dedf8e73 39# define GvFLAGS(gv) \
603aa20d
RU
40 (*({GV *const _gvflags = (GV *) (gv); \
41 assert(SvTYPE(_gvflags) == SVt_PVGV || SvTYPE(_gvflags) == SVt_PVLV); \
42 assert(isGV_with_GP(_gvflags)); \
43 &(GvXPVGV(_gvflags)->xpv_cur);}))
c72c5e99 44# define GvSTASH(gv) \
603aa20d
RU
45 (*({ GV * const _gvstash = (GV *) (gv); \
46 assert(isGV_with_GP(_gvstash)); \
47 assert(SvTYPE(_gvstash) == SVt_PVGV || SvTYPE(_gvstash) >= SVt_PVLV); \
48 &(GvXPVGV(_gvstash)->xnv_u.xgv_stash); \
c72c5e99 49 }))
acda4c6a 50# define GvNAME_HEK(gv) \
603aa20d
RU
51 (*({ GV * const _gvname_hek = (GV *) (gv); \
52 assert(isGV_with_GP(_gvname_hek)); \
53 assert(SvTYPE(_gvname_hek) == SVt_PVGV || SvTYPE(_gvname_hek) >= SVt_PVLV); \
54 assert(!SvVALID(_gvname_hek)); \
55 &(GvXPVGV(_gvname_hek)->xiv_u.xivu_namehek); \
acda4c6a 56 }))
1404b487 57# define GvNAME_get(gv) ({ assert(GvNAME_HEK(gv)); (char *)HEK_KEY(GvNAME_HEK(gv)); })
9f616d01 58# define GvNAMELEN_get(gv) ({ assert(GvNAME_HEK(gv)); HEK_LEN(GvNAME_HEK(gv)); })
c72c5e99 59#else
c43ae56f
DM
60# define GvGP(gv) (0+(gv)->sv_u.svu_gp)
61# define GvGP_set(gv,gp) ((gv)->sv_u.svu_gp = (gp))
5526b5b3 62# define GvFLAGS(gv) (GvXPVGV(gv)->xpv_cur)
58430790 63# define GvSTASH(gv) (GvXPVGV(gv)->xnv_u.xgv_stash)
274ac62a 64# define GvNAME_HEK(gv) (GvXPVGV(gv)->xiv_u.xivu_namehek)
9f616d01
MHM
65# define GvNAME_get(gv) HEK_KEY(GvNAME_HEK(gv))
66# define GvNAMELEN_get(gv) HEK_LEN(GvNAME_HEK(gv))
c72c5e99 67#endif
dedf8e73 68
f5c1e807
NC
69#define GvNAME(gv) GvNAME_get(gv)
70#define GvNAMELEN(gv) GvNAMELEN_get(gv)
71
08002bbf 72#define GvASSIGN_GENERATION(gv) (0 + ((XPV*) SvANY(gv))->xpv_len)
169d2d72
NC
73#define GvASSIGN_GENERATION_set(gv,val) \
74 STMT_START { assert(SvTYPE(gv) == SVt_PVGV); \
08002bbf 75 (((XPV*) SvANY(gv))->xpv_len = (val)); } STMT_END
169d2d72 76
954c1994 77/*
ccfc67b7
JH
78=head1 GV Functions
79
954c1994
GS
80=for apidoc Am|SV*|GvSV|GV* gv
81
82Return the SV from the GV.
83
84=cut
85*/
86
79072805 87#define GvSV(gv) (GvGP(gv)->gp_sv)
c69033f2 88#ifdef PERL_DONT_CREATE_GVSV
547f15c3
NC
89#define GvSVn(gv) (*(GvGP(gv)->gp_sv ? \
90 &(GvGP(gv)->gp_sv) : \
91 &(GvGP(gv_SVadd(gv))->gp_sv)))
c69033f2
NC
92#else
93#define GvSVn(gv) GvSV(gv)
94#endif
95
79072805 96#define GvREFCNT(gv) (GvGP(gv)->gp_refcnt)
13be902c
FC
97#define GvIO(gv) \
98 ( \
99 (gv) \
100 && ( \
101 SvTYPE((const SV*)(gv)) == SVt_PVGV \
102 || SvTYPE((const SV*)(gv)) == SVt_PVLV \
103 ) \
104 && GvGP(gv) \
105 ? GvIOp(gv) \
106 : NULL \
107 )
a0d0e21e
LW
108#define GvIOp(gv) (GvGP(gv)->gp_io)
109#define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
79072805
LW
110
111#define GvFORM(gv) (GvGP(gv)->gp_form)
112#define GvAV(gv) (GvGP(gv)->gp_av)
44a8e56a 113
79072805
LW
114#define GvAVn(gv) (GvGP(gv)->gp_av ? \
115 GvGP(gv)->gp_av : \
116 GvGP(gv_AVadd(gv))->gp_av)
79072805
LW
117#define GvHV(gv) ((GvGP(gv))->gp_hv)
118
79072805
LW
119#define GvHVn(gv) (GvGP(gv)->gp_hv ? \
120 GvGP(gv)->gp_hv : \
121 GvGP(gv_HVadd(gv))->gp_hv)
79072805 122
c43ae56f
DM
123#define GvCV(gv) (0+GvGP(gv)->gp_cv)
124#define GvCV_set(gv,cv) (GvGP(gv)->gp_cv = (cv))
463ee0b2 125#define GvCVGEN(gv) (GvGP(gv)->gp_cvgen)
601f1833 126#define GvCVu(gv) (GvGP(gv)->gp_cvgen ? NULL : GvGP(gv)->gp_cv)
79072805 127
79072805 128#define GvLINE(gv) (GvGP(gv)->gp_line)
f4890806 129#define GvFILE_HEK(gv) (GvGP(gv)->gp_file_hek)
5be41be4 130#define GvFILE(gv) (GvFILE_HEK(gv) ? HEK_KEY(GvFILE_HEK(gv)) : NULL)
57843af0 131#define GvFILEGV(gv) (gv_fetchfile(GvFILE(gv)))
79072805 132
79072805 133#define GvEGV(gv) (GvGP(gv)->gp_egv)
099be4f1 134#define GvEGVx(gv) (isGV_with_GP(gv) ? GvEGV(gv) : NULL)
748a9306 135#define GvENAME(gv) GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
748a9306 136#define GvESTASH(gv) GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
79072805 137
a5f75d66
AD
138#define GVf_INTRO 0x01
139#define GVf_MULTI 0x02
140#define GVf_ASSUMECV 0x04
743e66e6 141#define GVf_IN_PAD 0x08
a5f75d66
AD
142#define GVf_IMPORTED 0xF0
143#define GVf_IMPORTED_SV 0x10
144#define GVf_IMPORTED_AV 0x20
145#define GVf_IMPORTED_HV 0x40
146#define GVf_IMPORTED_CV 0x80
147
148#define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
149#define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
150#define GvINTRO_off(gv) (GvFLAGS(gv) &= ~GVf_INTRO)
151
152#define GvMULTI(gv) (GvFLAGS(gv) & GVf_MULTI)
153#define GvMULTI_on(gv) (GvFLAGS(gv) |= GVf_MULTI)
154#define GvMULTI_off(gv) (GvFLAGS(gv) &= ~GVf_MULTI)
155
156#define GvASSUMECV(gv) (GvFLAGS(gv) & GVf_ASSUMECV)
157#define GvASSUMECV_on(gv) (GvFLAGS(gv) |= GVf_ASSUMECV)
158#define GvASSUMECV_off(gv) (GvFLAGS(gv) &= ~GVf_ASSUMECV)
159
160#define GvIMPORTED(gv) (GvFLAGS(gv) & GVf_IMPORTED)
161#define GvIMPORTED_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED)
162#define GvIMPORTED_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED)
163
164#define GvIMPORTED_SV(gv) (GvFLAGS(gv) & GVf_IMPORTED_SV)
165#define GvIMPORTED_SV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_SV)
166#define GvIMPORTED_SV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_SV)
167
168#define GvIMPORTED_AV(gv) (GvFLAGS(gv) & GVf_IMPORTED_AV)
169#define GvIMPORTED_AV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_AV)
170#define GvIMPORTED_AV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_AV)
171
172#define GvIMPORTED_HV(gv) (GvFLAGS(gv) & GVf_IMPORTED_HV)
173#define GvIMPORTED_HV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_HV)
174#define GvIMPORTED_HV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_HV)
175
176#define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV)
177#define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
178#define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)
179
743e66e6
GS
180#define GvIN_PAD(gv) (GvFLAGS(gv) & GVf_IN_PAD)
181#define GvIN_PAD_on(gv) (GvFLAGS(gv) |= GVf_IN_PAD)
182#define GvIN_PAD_off(gv) (GvFLAGS(gv) &= ~GVf_IN_PAD)
183
3ae1b226
NC
184#ifndef PERL_CORE
185# define Nullgv Null(GV*)
186#endif
79072805 187
613a9ec2
DM
188#define DM_RUID 0x001
189#define DM_EUID 0x002
6ca8229d 190#define DM_UID (DM_RUID|DM_EUID)
354b0578 191#define DM_ARRAY_ISA 0x004
613a9ec2
DM
192#define DM_RGID 0x010
193#define DM_EGID 0x020
6ca8229d 194#define DM_GID (DM_RGID|DM_EGID)
613a9ec2 195#define DM_DELAY 0x100
79072805 196
0f303493 197/*
864dbfa3 198 * symbol creation flags, for use in gv_fetchpv() and get_*v()
0f303493 199 */
ae8cc45f
NC
200#define GV_ADD 0x01 /* add, if symbol not already there
201 For gv_name_set, adding a HEK for the first
202 time, so don't try to free what's there. */
0f303493
GS
203#define GV_ADDMULTI 0x02 /* add, pretending it has been added already */
204#define GV_ADDWARN 0x04 /* add, but warn if symbol wasn't already there */
205#define GV_ADDINEVAL 0x08 /* add, as though we're doing so within an eval */
206#define GV_NOINIT 0x10 /* add, but don't init symbol, if type != PVGV */
add2581e
NC
207/* This is used by toke.c to avoid turing placeholder constants in the symbol
208 table into full PVGVs with attached constant subroutines. */
209#define GV_NOADD_NOINIT 0x20 /* Don't add the symbol if it's not there.
210 Don't init it if it is there but ! PVGV */
e26df76a 211#define GV_NOEXPAND 0x40 /* Don't expand SvOK() entries to PVGV */
fafc274c
NC
212#define GV_NOTQUAL 0x80 /* A plain symbol name, not qualified with a
213 package (so skip checks for :: and ') */
256d1bb2
NC
214#define GV_AUTOLOAD 0x100 /* gv_fetchmethod_flags() should AUTOLOAD */
215#define GV_CROAK 0x200 /* gv_fetchmethod_flags() should croak */
23496c6e 216#define GV_ADDMG 0x400 /* add if magical */
add2581e 217
7a5fd60d
NC
218/* SVf_UTF8 (more accurately the return value from SvUTF8) is also valid
219 as a flag to gv_fetch_pvn_flags, so ensure it lies outside this range.
220*/
780a5241 221
23496c6e
FC
222#define GV_NOADD_MASK \
223 (SVf_UTF8|GV_NOADD_NOINIT|GV_NOEXPAND|GV_NOTQUAL|GV_ADDMG)
224/* The bit flags that don't cause gv_fetchpv() to add a symbol if not
225 found (with the exception GV_ADDMG, which *might* cause the symbol
226 to be added) */
780a5241 227
d9a22066
NC
228#define gv_fullname3(sv,gv,prefix) gv_fullname4(sv,gv,prefix,TRUE)
229#define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE)
887986eb 230#define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)
f4890806 231
d5713896
NC
232#define gv_AVadd(gv) gv_add_by_type((gv), SVt_PVAV)
233#define gv_HVadd(gv) gv_add_by_type((gv), SVt_PVHV)
bb85b28a 234#define gv_IOadd(gv) gv_add_by_type((gv), SVt_PVIO)
d5713896
NC
235#define gv_SVadd(gv) gv_add_by_type((gv), SVt_NULL)
236
f4890806
NC
237/*
238 * Local variables:
239 * c-indentation-style: bsd
240 * c-basic-offset: 4
241 * indent-tabs-mode: t
242 * End:
243 *
244 * ex: set ts=8 sts=4 sw=4 noet:
245 */