This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix argument grouping for some macros
[perl5.git] / gv.h
CommitLineData
a0d0e21e 1/* gv.h
79072805 2 *
4bb101f2 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
acde74e1 4 * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 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 */
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 */
aa689395 17 HV * gp_hv; /* hash value */
79072805
LW
18 GV * gp_egv; /* effective gv, if *glob */
19 CV * gp_cv; /* subroutine value */
463ee0b2 20 U32 gp_cvgen; /* generational validity of cached gv_cv */
79072805 21 line_t gp_line; /* line first declared at (for -w) */
1cb0ed9b 22 char * gp_file; /* file first declared in (for -w) */
79072805
LW
23};
24
79072805
LW
25#define GvXPVGV(gv) ((XPVGV*)SvANY(gv))
26
a5f75d66 27
c72c5e99 28#if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)
dedf8e73 29# define GvGP(gv) \
76f523e8 30 (*({GV *const shplep = (GV *) (gv); \
dedf8e73
NC
31 assert(SvTYPE(shplep) == SVt_PVGV || \
32 SvTYPE(shplep) == SVt_PVLV); \
33 assert(isGV_with_GP(shplep)); \
34 &((shplep)->sv_u.svu_gp);}))
35# define GvFLAGS(gv) \
76f523e8 36 (*({GV *const yaah = (GV *) (gv); \
dedf8e73
NC
37 assert(SvTYPE(yaah) == SVt_PVGV || SvTYPE(yaah) == SVt_PVLV); \
38 assert(isGV_with_GP(yaah)); \
5526b5b3 39 &(GvXPVGV(yaah)->xpv_cur);}))
c72c5e99 40# define GvSTASH(gv) \
76f523e8 41 (*({ GV *_gv = (GV *) (gv); \
dedf8e73 42 assert(isGV_with_GP(_gv)); \
c72c5e99 43 assert(SvTYPE(_gv) == SVt_PVGV || SvTYPE(_gv) >= SVt_PVLV); \
58430790 44 &(GvXPVGV(_gv)->xnv_u.xgv_stash); \
c72c5e99 45 }))
dedf8e73 46# define GvNAME(gv) \
76f523e8 47 (*({ GV *zzzz = (GV *) (gv); \
dedf8e73
NC
48 assert(isGV_with_GP(zzzz)); \
49 assert(SvTYPE(zzzz) == SVt_PVGV || SvTYPE(zzzz) >= SVt_PVLV); \
50 &(GvXPVGV(zzzz)->xgv_name); \
51 }))
52# define GvNAMELEN(gv) \
76f523e8 53 (*({ GV *glank = (GV *) (gv); \
dedf8e73
NC
54 assert(isGV_with_GP(glank)); \
55 assert(SvTYPE(glank) == SVt_PVGV || SvTYPE(glank) >= SVt_PVLV); \
56 &(GvXPVGV(glank)->xgv_namelen); \
57 }))
c72c5e99 58#else
dedf8e73 59# define GvGP(gv) ((gv)->sv_u.svu_gp)
5526b5b3 60# define GvFLAGS(gv) (GvXPVGV(gv)->xpv_cur)
58430790 61# define GvSTASH(gv) (GvXPVGV(gv)->xnv_u.xgv_stash)
dedf8e73
NC
62# define GvNAME(gv) (GvXPVGV(gv)->xgv_name)
63# define GvNAMELEN(gv) (GvXPVGV(gv)->xgv_namelen)
c72c5e99 64#endif
dedf8e73 65
08002bbf 66#define GvASSIGN_GENERATION(gv) (0 + ((XPV*) SvANY(gv))->xpv_len)
169d2d72
NC
67#define GvASSIGN_GENERATION_set(gv,val) \
68 STMT_START { assert(SvTYPE(gv) == SVt_PVGV); \
08002bbf 69 (((XPV*) SvANY(gv))->xpv_len = (val)); } STMT_END
169d2d72 70
954c1994 71/*
ccfc67b7
JH
72=head1 GV Functions
73
954c1994
GS
74=for apidoc Am|SV*|GvSV|GV* gv
75
76Return the SV from the GV.
77
78=cut
79*/
80
79072805 81#define GvSV(gv) (GvGP(gv)->gp_sv)
c69033f2 82#ifdef PERL_DONT_CREATE_GVSV
547f15c3
NC
83#define GvSVn(gv) (*(GvGP(gv)->gp_sv ? \
84 &(GvGP(gv)->gp_sv) : \
85 &(GvGP(gv_SVadd(gv))->gp_sv)))
c69033f2
NC
86#else
87#define GvSVn(gv) GvSV(gv)
88#endif
89
79072805 90#define GvREFCNT(gv) (GvGP(gv)->gp_refcnt)
2035c5e8 91#define GvIO(gv) ((gv) && SvTYPE((SV*)gv) == SVt_PVGV && GvGP(gv) ? GvIOp(gv) : 0)
a0d0e21e
LW
92#define GvIOp(gv) (GvGP(gv)->gp_io)
93#define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
79072805
LW
94
95#define GvFORM(gv) (GvGP(gv)->gp_form)
96#define GvAV(gv) (GvGP(gv)->gp_av)
44a8e56a
PP
97
98/* This macro is deprecated. Do not use! */
99#define GvREFCNT_inc(gv) ((GV*)SvREFCNT_inc(gv)) /* DO NOT USE */
79072805 100
79072805
LW
101#define GvAVn(gv) (GvGP(gv)->gp_av ? \
102 GvGP(gv)->gp_av : \
103 GvGP(gv_AVadd(gv))->gp_av)
79072805
LW
104#define GvHV(gv) ((GvGP(gv))->gp_hv)
105
79072805
LW
106#define GvHVn(gv) (GvGP(gv)->gp_hv ? \
107 GvGP(gv)->gp_hv : \
108 GvGP(gv_HVadd(gv))->gp_hv)
79072805
LW
109
110#define GvCV(gv) (GvGP(gv)->gp_cv)
463ee0b2 111#define GvCVGEN(gv) (GvGP(gv)->gp_cvgen)
601f1833 112#define GvCVu(gv) (GvGP(gv)->gp_cvgen ? NULL : GvGP(gv)->gp_cv)
79072805 113
79072805 114#define GvLINE(gv) (GvGP(gv)->gp_line)
b195d487 115#define GvFILE(gv) (GvGP(gv)->gp_file)
57843af0 116#define GvFILEGV(gv) (gv_fetchfile(GvFILE(gv)))
79072805 117
79072805 118#define GvEGV(gv) (GvGP(gv)->gp_egv)
748a9306 119#define GvENAME(gv) GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
748a9306 120#define GvESTASH(gv) GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
79072805 121
a5f75d66
AD
122#define GVf_INTRO 0x01
123#define GVf_MULTI 0x02
124#define GVf_ASSUMECV 0x04
743e66e6 125#define GVf_IN_PAD 0x08
a5f75d66
AD
126#define GVf_IMPORTED 0xF0
127#define GVf_IMPORTED_SV 0x10
128#define GVf_IMPORTED_AV 0x20
129#define GVf_IMPORTED_HV 0x40
130#define GVf_IMPORTED_CV 0x80
131
132#define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
133#define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
134#define GvINTRO_off(gv) (GvFLAGS(gv) &= ~GVf_INTRO)
135
136#define GvMULTI(gv) (GvFLAGS(gv) & GVf_MULTI)
137#define GvMULTI_on(gv) (GvFLAGS(gv) |= GVf_MULTI)
138#define GvMULTI_off(gv) (GvFLAGS(gv) &= ~GVf_MULTI)
139
140#define GvASSUMECV(gv) (GvFLAGS(gv) & GVf_ASSUMECV)
141#define GvASSUMECV_on(gv) (GvFLAGS(gv) |= GVf_ASSUMECV)
142#define GvASSUMECV_off(gv) (GvFLAGS(gv) &= ~GVf_ASSUMECV)
143
144#define GvIMPORTED(gv) (GvFLAGS(gv) & GVf_IMPORTED)
145#define GvIMPORTED_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED)
146#define GvIMPORTED_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED)
147
148#define GvIMPORTED_SV(gv) (GvFLAGS(gv) & GVf_IMPORTED_SV)
149#define GvIMPORTED_SV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_SV)
150#define GvIMPORTED_SV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_SV)
151
152#define GvIMPORTED_AV(gv) (GvFLAGS(gv) & GVf_IMPORTED_AV)
153#define GvIMPORTED_AV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_AV)
154#define GvIMPORTED_AV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_AV)
155
156#define GvIMPORTED_HV(gv) (GvFLAGS(gv) & GVf_IMPORTED_HV)
157#define GvIMPORTED_HV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_HV)
158#define GvIMPORTED_HV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_HV)
159
160#define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV)
161#define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
162#define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)
163
743e66e6
GS
164#define GvIN_PAD(gv) (GvFLAGS(gv) & GVf_IN_PAD)
165#define GvIN_PAD_on(gv) (GvFLAGS(gv) |= GVf_IN_PAD)
166#define GvIN_PAD_off(gv) (GvFLAGS(gv) &= ~GVf_IN_PAD)
167
49c0300d 168#define GvUNIQUE(gv) 0
40e48b40
DM
169#define GvUNIQUE_on(gv)
170#define GvUNIQUE_off(gv)
5bd07a3d
DM
171
172#ifdef USE_ITHREADS
7fb37951 173#define GV_UNIQUE_CHECK
5bd07a3d 174#else
7fb37951 175#undef GV_UNIQUE_CHECK
5bd07a3d
DM
176#endif
177
79072805
LW
178#define Nullgv Null(GV*)
179
180#define DM_UID 0x003
181#define DM_RUID 0x001
182#define DM_EUID 0x002
183#define DM_GID 0x030
184#define DM_RGID 0x010
185#define DM_EGID 0x020
186#define DM_DELAY 0x100
187
0f303493 188/*
864dbfa3 189 * symbol creation flags, for use in gv_fetchpv() and get_*v()
0f303493
GS
190 */
191#define GV_ADD 0x01 /* add, if symbol not already 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 */
add2581e
NC
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 */
e26df76a 200#define GV_NOEXPAND 0x40 /* Don't expand SvOK() entries to PVGV */
fafc274c
NC
201#define GV_NOTQUAL 0x80 /* A plain symbol name, not qualified with a
202 package (so skip checks for :: and ') */
add2581e 203
7a5fd60d
NC
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.
206*/
d9a22066
NC
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)
887986eb 209#define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)