This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
eliminate SVpbm_VALID flag
[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 */
5d855216 15 U32 gp_cvgen; /* generational validity of cached gp_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 */
e12ab2f2
FC
21 PERL_BITFIELD32 gp_line:31; /* line first declared at (for -w) */
22 PERL_BITFIELD32 gp_flags:1;
f4890806 23 HEK * gp_file_hek; /* file first declared in (for -w) */
79072805
LW
24};
25
79072805
LW
26#define GvXPVGV(gv) ((XPVGV*)SvANY(gv))
27
a5f75d66 28
e51a6fb1 29#if defined (DEBUGGING) && defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__INTEL_COMPILER)
dedf8e73 30# define GvGP(gv) \
c43ae56f 31 (0+(*({GV *const _gvgp = (GV *) (gv); \
603aa20d
RU
32 assert(SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV); \
33 assert(isGV_with_GP(_gvgp)); \
c43ae56f
DM
34 &((_gvgp)->sv_u.svu_gp);})))
35# define GvGP_set(gv,gp) \
36 {GV *const _gvgp = (GV *) (gv); \
37 assert(SvTYPE(_gvgp) == SVt_PVGV || SvTYPE(_gvgp) == SVt_PVLV); \
38 assert(isGV_with_GP(_gvgp)); \
39 (_gvgp)->sv_u.svu_gp = (gp); }
dedf8e73 40# define GvFLAGS(gv) \
603aa20d
RU
41 (*({GV *const _gvflags = (GV *) (gv); \
42 assert(SvTYPE(_gvflags) == SVt_PVGV || SvTYPE(_gvflags) == SVt_PVLV); \
43 assert(isGV_with_GP(_gvflags)); \
44 &(GvXPVGV(_gvflags)->xpv_cur);}))
c72c5e99 45# define GvSTASH(gv) \
603aa20d
RU
46 (*({ GV * const _gvstash = (GV *) (gv); \
47 assert(isGV_with_GP(_gvstash)); \
48 assert(SvTYPE(_gvstash) == SVt_PVGV || SvTYPE(_gvstash) >= SVt_PVLV); \
49 &(GvXPVGV(_gvstash)->xnv_u.xgv_stash); \
c72c5e99 50 }))
acda4c6a 51# define GvNAME_HEK(gv) \
603aa20d
RU
52 (*({ GV * const _gvname_hek = (GV *) (gv); \
53 assert(isGV_with_GP(_gvname_hek)); \
54 assert(SvTYPE(_gvname_hek) == SVt_PVGV || SvTYPE(_gvname_hek) >= SVt_PVLV); \
a5c7cb08 55 assert(!SvVALID((SV*)_gvname_hek)); \
603aa20d 56 &(GvXPVGV(_gvname_hek)->xiv_u.xivu_namehek); \
acda4c6a 57 }))
1404b487 58# define GvNAME_get(gv) ({ assert(GvNAME_HEK(gv)); (char *)HEK_KEY(GvNAME_HEK(gv)); })
9f616d01 59# define GvNAMELEN_get(gv) ({ assert(GvNAME_HEK(gv)); HEK_LEN(GvNAME_HEK(gv)); })
b2c03ebd 60# define GvNAMEUTF8(gv) ({ assert(GvNAME_HEK(gv)); HEK_UTF8(GvNAME_HEK(gv)); })
c72c5e99 61#else
c43ae56f
DM
62# define GvGP(gv) (0+(gv)->sv_u.svu_gp)
63# define GvGP_set(gv,gp) ((gv)->sv_u.svu_gp = (gp))
5526b5b3 64# define GvFLAGS(gv) (GvXPVGV(gv)->xpv_cur)
58430790 65# define GvSTASH(gv) (GvXPVGV(gv)->xnv_u.xgv_stash)
274ac62a 66# define GvNAME_HEK(gv) (GvXPVGV(gv)->xiv_u.xivu_namehek)
9f616d01
MHM
67# define GvNAME_get(gv) HEK_KEY(GvNAME_HEK(gv))
68# define GvNAMELEN_get(gv) HEK_LEN(GvNAME_HEK(gv))
b2c03ebd 69# define GvNAMEUTF8(gv) HEK_UTF8(GvNAME_HEK(gv))
c72c5e99 70#endif
dedf8e73 71
f5c1e807
NC
72#define GvNAME(gv) GvNAME_get(gv)
73#define GvNAMELEN(gv) GvNAMELEN_get(gv)
74
954c1994 75/*
ccfc67b7
JH
76=head1 GV Functions
77
954c1994
GS
78=for apidoc Am|SV*|GvSV|GV* gv
79
80Return the SV from the GV.
81
b019ef6e
JL
82=for apidoc Am|AV*|GvAV|GV* gv
83
84Return the AV from the GV.
85
86=for apidoc Am|HV*|GvHV|GV* gv
87
88Return the HV from the GV.
89
90=for apidoc Am|CV*|GvCV|GV* gv
91
92Return the CV from the GV.
93
954c1994
GS
94=cut
95*/
96
79072805 97#define GvSV(gv) (GvGP(gv)->gp_sv)
c69033f2 98#ifdef PERL_DONT_CREATE_GVSV
13c59d41
MH
99#define GvSVn(gv) (*(GvGP(gv)->gp_sv ? \
100 &(GvGP(gv)->gp_sv) : \
101 &(GvGP(gv_SVadd(gv))->gp_sv)))
c69033f2
NC
102#else
103#define GvSVn(gv) GvSV(gv)
104#endif
105
79072805 106#define GvREFCNT(gv) (GvGP(gv)->gp_refcnt)
13be902c
FC
107#define GvIO(gv) \
108 ( \
109 (gv) \
110 && ( \
111 SvTYPE((const SV*)(gv)) == SVt_PVGV \
112 || SvTYPE((const SV*)(gv)) == SVt_PVLV \
113 ) \
114 && GvGP(gv) \
115 ? GvIOp(gv) \
116 : NULL \
117 )
a0d0e21e 118#define GvIOp(gv) (GvGP(gv)->gp_io)
13c59d41 119#define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
79072805
LW
120
121#define GvFORM(gv) (GvGP(gv)->gp_form)
122#define GvAV(gv) (GvGP(gv)->gp_av)
44a8e56a 123
79072805
LW
124#define GvAVn(gv) (GvGP(gv)->gp_av ? \
125 GvGP(gv)->gp_av : \
13c59d41 126 GvGP(gv_AVadd(gv))->gp_av)
79072805
LW
127#define GvHV(gv) ((GvGP(gv))->gp_hv)
128
79072805
LW
129#define GvHVn(gv) (GvGP(gv)->gp_hv ? \
130 GvGP(gv)->gp_hv : \
13c59d41 131 GvGP(gv_HVadd(gv))->gp_hv)
79072805 132
c43ae56f
DM
133#define GvCV(gv) (0+GvGP(gv)->gp_cv)
134#define GvCV_set(gv,cv) (GvGP(gv)->gp_cv = (cv))
463ee0b2 135#define GvCVGEN(gv) (GvGP(gv)->gp_cvgen)
601f1833 136#define GvCVu(gv) (GvGP(gv)->gp_cvgen ? NULL : GvGP(gv)->gp_cv)
79072805 137
4a8cd1ba
FC
138#define GvGPFLAGS(gv) (GvGP(gv)->gp_flags)
139
79072805 140#define GvLINE(gv) (GvGP(gv)->gp_line)
f4890806 141#define GvFILE_HEK(gv) (GvGP(gv)->gp_file_hek)
c835650e
DM
142#define GvFILEx(gv) HEK_KEY(GvFILE_HEK(gv))
143#define GvFILE(gv) (GvFILE_HEK(gv) ? GvFILEx(gv) : NULL)
144#define GvFILEGV(gv) (GvFILE_HEK(gv) ? gv_fetchfile(GvFILEx(gv)) : NULL)
79072805 145
79072805 146#define GvEGV(gv) (GvGP(gv)->gp_egv)
099be4f1 147#define GvEGVx(gv) (isGV_with_GP(gv) ? GvEGV(gv) : NULL)
748a9306 148#define GvENAME(gv) GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
f2462604
BF
149#define GvENAMELEN(gv) GvNAMELEN(GvEGV(gv) ? GvEGV(gv) : gv)
150#define GvENAMEUTF8(gv) GvNAMEUTF8(GvEGV(gv) ? GvEGV(gv) : gv)
151#define GvENAME_HEK(gv) GvNAME_HEK(GvEGV(gv) ? GvEGV(gv) : gv)
748a9306 152#define GvESTASH(gv) GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
79072805 153
364bbfa4
TC
154/* GVf_INTRO is one-shot flag which indicates that the next assignment
155 of a reference to the glob is to be localised; it distinguishes
156 'local *g = $ref' from '*g = $ref'.
157*/
a5f75d66
AD
158#define GVf_INTRO 0x01
159#define GVf_MULTI 0x02
160#define GVf_ASSUMECV 0x04
a5bc03e9 161/* UNUSED 0x08 */
a5f75d66
AD
162#define GVf_IMPORTED 0xF0
163#define GVf_IMPORTED_SV 0x10
164#define GVf_IMPORTED_AV 0x20
165#define GVf_IMPORTED_HV 0x40
166#define GVf_IMPORTED_CV 0x80
167
168#define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
169#define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
170#define GvINTRO_off(gv) (GvFLAGS(gv) &= ~GVf_INTRO)
171
172#define GvMULTI(gv) (GvFLAGS(gv) & GVf_MULTI)
173#define GvMULTI_on(gv) (GvFLAGS(gv) |= GVf_MULTI)
174#define GvMULTI_off(gv) (GvFLAGS(gv) &= ~GVf_MULTI)
175
176#define GvASSUMECV(gv) (GvFLAGS(gv) & GVf_ASSUMECV)
177#define GvASSUMECV_on(gv) (GvFLAGS(gv) |= GVf_ASSUMECV)
178#define GvASSUMECV_off(gv) (GvFLAGS(gv) &= ~GVf_ASSUMECV)
179
180#define GvIMPORTED(gv) (GvFLAGS(gv) & GVf_IMPORTED)
181#define GvIMPORTED_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED)
182#define GvIMPORTED_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED)
183
184#define GvIMPORTED_SV(gv) (GvFLAGS(gv) & GVf_IMPORTED_SV)
185#define GvIMPORTED_SV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_SV)
186#define GvIMPORTED_SV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_SV)
187
188#define GvIMPORTED_AV(gv) (GvFLAGS(gv) & GVf_IMPORTED_AV)
189#define GvIMPORTED_AV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_AV)
190#define GvIMPORTED_AV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_AV)
191
192#define GvIMPORTED_HV(gv) (GvFLAGS(gv) & GVf_IMPORTED_HV)
193#define GvIMPORTED_HV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_HV)
194#define GvIMPORTED_HV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_HV)
195
196#define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV)
197#define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
198#define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)
199
3ae1b226 200#ifndef PERL_CORE
a5bc03e9
FC
201# define GvIN_PAD(gv) 0
202# define GvIN_PAD_on(gv) NOOP
203# define GvIN_PAD_off(gv) NOOP
3ae1b226
NC
204# define Nullgv Null(GV*)
205#endif
79072805 206
613a9ec2
DM
207#define DM_RUID 0x001
208#define DM_EUID 0x002
6ca8229d 209#define DM_UID (DM_RUID|DM_EUID)
354b0578 210#define DM_ARRAY_ISA 0x004
613a9ec2
DM
211#define DM_RGID 0x010
212#define DM_EGID 0x020
6ca8229d 213#define DM_GID (DM_RGID|DM_EGID)
613a9ec2 214#define DM_DELAY 0x100
79072805 215
0f303493 216/*
864dbfa3 217 * symbol creation flags, for use in gv_fetchpv() and get_*v()
0f303493 218 */
ae8cc45f
NC
219#define GV_ADD 0x01 /* add, if symbol not already there
220 For gv_name_set, adding a HEK for the first
221 time, so don't try to free what's there. */
04ec7e59
FC
222#define GV_ADDMULTI 0x02 /* add, pretending it has been added
223 already; used also by gv_init_* */
0f303493 224#define GV_ADDWARN 0x04 /* add, but warn if symbol wasn't already there */
4bff32c5 225 /* 0x08 UNUSED */
0f303493 226#define GV_NOINIT 0x10 /* add, but don't init symbol, if type != PVGV */
add2581e
NC
227/* This is used by toke.c to avoid turing placeholder constants in the symbol
228 table into full PVGVs with attached constant subroutines. */
229#define GV_NOADD_NOINIT 0x20 /* Don't add the symbol if it's not there.
230 Don't init it if it is there but ! PVGV */
e26df76a 231#define GV_NOEXPAND 0x40 /* Don't expand SvOK() entries to PVGV */
fafc274c
NC
232#define GV_NOTQUAL 0x80 /* A plain symbol name, not qualified with a
233 package (so skip checks for :: and ') */
256d1bb2
NC
234#define GV_AUTOLOAD 0x100 /* gv_fetchmethod_flags() should AUTOLOAD */
235#define GV_CROAK 0x200 /* gv_fetchmethod_flags() should croak */
23496c6e 236#define GV_ADDMG 0x400 /* add if magical */
77cb3b01
FC
237#define GV_NO_SVGMAGIC 0x800 /* Skip get-magic on an SV argument;
238 used only by gv_fetchsv(_nomg) */
d283e876 239#define GV_CACHE_ONLY 0x1000 /* return stash only if found in cache;
240 used only in flags parameter to gv_stash* family */
add2581e 241
aae43805
FC
242/* Flags for gv_fetchmeth_pvn and gv_autoload_pvn*/
243#define GV_SUPER 0x1000 /* SUPER::method */
244
0eeb01b9
FC
245/* Flags for gv_autoload_*/
246#define GV_AUTOLOAD_ISMETHOD 1 /* autoloading a method? */
247
7a5fd60d 248/* SVf_UTF8 (more accurately the return value from SvUTF8) is also valid
04ec7e59 249 as a flag to various gv_* functions, so ensure it lies
0eeb01b9 250 outside this range.
7a5fd60d 251*/
780a5241 252
23496c6e 253#define GV_NOADD_MASK \
77cb3b01 254 (SVf_UTF8|GV_NOADD_NOINIT|GV_NOEXPAND|GV_NOTQUAL|GV_ADDMG|GV_NO_SVGMAGIC)
23496c6e
FC
255/* The bit flags that don't cause gv_fetchpv() to add a symbol if not
256 found (with the exception GV_ADDMG, which *might* cause the symbol
257 to be added) */
780a5241 258
d9a22066
NC
259#define gv_fullname3(sv,gv,prefix) gv_fullname4(sv,gv,prefix,TRUE)
260#define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE)
887986eb 261#define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)
77cb3b01 262#define gv_fetchsv_nomg(n,f,t) gv_fetchsv(n,(f)|GV_NO_SVGMAGIC,t)
04ec7e59
FC
263#define gv_init(gv,stash,name,len,multi) \
264 gv_init_pvn(gv,stash,name,len,GV_ADDMULTI*!!(multi))
d21989ed
BF
265#define gv_fetchmeth(stash,name,len,level) gv_fetchmeth_pvn(stash, name, len, level, 0)
266#define gv_fetchmeth_autoload(stash,name,len,level) gv_fetchmeth_pvn_autoload(stash, name, len, level, 0)
44130a26 267#define gv_fetchmethod_flags(stash,name,flags) gv_fetchmethod_pv_flags(stash, name, flags)
0eeb01b9
FC
268#define gv_autoload4(stash, name, len, method) \
269 gv_autoload_pvn(stash, name, len, !!(method))
9cc50d5b 270#define newGVgen(pack) newGVgen_flags(pack, 0)
978a498e
FC
271#define gv_method_changed(gv) \
272 ( \
273 assert_(isGV_with_GP(gv)) \
274 GvREFCNT(gv) > 1 \
275 ? (void)++PL_sub_generation \
276 : mro_method_changed_in(GvSTASH(gv)) \
277 )
f4890806 278
13c59d41
MH
279#define gv_AVadd(gv) gv_add_by_type((gv), SVt_PVAV)
280#define gv_HVadd(gv) gv_add_by_type((gv), SVt_PVHV)
281#define gv_IOadd(gv) gv_add_by_type((gv), SVt_PVIO)
282#define gv_SVadd(gv) gv_add_by_type((gv), SVt_NULL)
d5713896 283
f4890806 284/*
14d04a33 285 * ex: set ts=8 sts=4 sw=4 et:
f4890806 286 */