This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / gv.h
CommitLineData
a0d0e21e 1/* gv.h
79072805 2 *
e6906430 3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2c351e65 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 */
f4c556ac 21 U32 gp_flags; /* XXX unused */
79072805 22 line_t gp_line; /* line first declared at (for -w) */
ec6f298e 23 char * gp_file; /* file first declared in (for -w) */
79072805
LW
24};
25
79072805
LW
26#define GvXPVGV(gv) ((XPVGV*)SvANY(gv))
27
a5f75d66
AD
28#define GvGP(gv) (GvXPVGV(gv)->xgv_gp)
29#define GvNAME(gv) (GvXPVGV(gv)->xgv_name)
30#define GvNAMELEN(gv) (GvXPVGV(gv)->xgv_namelen)
31#define GvSTASH(gv) (GvXPVGV(gv)->xgv_stash)
32#define GvFLAGS(gv) (GvXPVGV(gv)->xgv_flags)
33
954c1994 34/*
ccfc67b7
JH
35=head1 GV Functions
36
954c1994
GS
37=for apidoc Am|SV*|GvSV|GV* gv
38
39Return the SV from the GV.
40
41=cut
42*/
43
79072805 44#define GvSV(gv) (GvGP(gv)->gp_sv)
83fd6193
NC
45#ifdef PERL_DONT_CREATE_GVSV
46#define GvSVn(gv) (*(GvGP(gv)->gp_sv ? \
47 &(GvGP(gv)->gp_sv) : \
48 &(GvGP(gv_SVadd(gv))->gp_sv)))
49#else
50#define GvSVn(gv) GvSV(gv)
51#endif
52
79072805 53#define GvREFCNT(gv) (GvGP(gv)->gp_refcnt)
2035c5e8 54#define GvIO(gv) ((gv) && SvTYPE((SV*)gv) == SVt_PVGV && GvGP(gv) ? GvIOp(gv) : 0)
a0d0e21e
LW
55#define GvIOp(gv) (GvGP(gv)->gp_io)
56#define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
79072805
LW
57
58#define GvFORM(gv) (GvGP(gv)->gp_form)
59#define GvAV(gv) (GvGP(gv)->gp_av)
44a8e56a
PP
60
61/* This macro is deprecated. Do not use! */
62#define GvREFCNT_inc(gv) ((GV*)SvREFCNT_inc(gv)) /* DO NOT USE */
79072805 63
79072805
LW
64#define GvAVn(gv) (GvGP(gv)->gp_av ? \
65 GvGP(gv)->gp_av : \
66 GvGP(gv_AVadd(gv))->gp_av)
79072805
LW
67#define GvHV(gv) ((GvGP(gv))->gp_hv)
68
79072805
LW
69#define GvHVn(gv) (GvGP(gv)->gp_hv ? \
70 GvGP(gv)->gp_hv : \
71 GvGP(gv_HVadd(gv))->gp_hv)
79072805
LW
72
73#define GvCV(gv) (GvGP(gv)->gp_cv)
463ee0b2 74#define GvCVGEN(gv) (GvGP(gv)->gp_cvgen)
8ebc5c01 75#define GvCVu(gv) (GvGP(gv)->gp_cvgen ? Nullcv : GvGP(gv)->gp_cv)
79072805 76
f4c556ac 77#define GvGPFLAGS(gv) (GvGP(gv)->gp_flags)
79072805
LW
78
79#define GvLINE(gv) (GvGP(gv)->gp_line)
b195d487 80#define GvFILE(gv) (GvGP(gv)->gp_file)
57843af0 81#define GvFILEGV(gv) (gv_fetchfile(GvFILE(gv)))
79072805 82
79072805 83#define GvEGV(gv) (GvGP(gv)->gp_egv)
748a9306 84#define GvENAME(gv) GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
748a9306 85#define GvESTASH(gv) GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
79072805 86
a5f75d66
AD
87#define GVf_INTRO 0x01
88#define GVf_MULTI 0x02
89#define GVf_ASSUMECV 0x04
743e66e6 90#define GVf_IN_PAD 0x08
a5f75d66
AD
91#define GVf_IMPORTED 0xF0
92#define GVf_IMPORTED_SV 0x10
93#define GVf_IMPORTED_AV 0x20
94#define GVf_IMPORTED_HV 0x40
95#define GVf_IMPORTED_CV 0x80
96
97#define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
98#define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
99#define GvINTRO_off(gv) (GvFLAGS(gv) &= ~GVf_INTRO)
100
101#define GvMULTI(gv) (GvFLAGS(gv) & GVf_MULTI)
102#define GvMULTI_on(gv) (GvFLAGS(gv) |= GVf_MULTI)
103#define GvMULTI_off(gv) (GvFLAGS(gv) &= ~GVf_MULTI)
104
105#define GvASSUMECV(gv) (GvFLAGS(gv) & GVf_ASSUMECV)
106#define GvASSUMECV_on(gv) (GvFLAGS(gv) |= GVf_ASSUMECV)
107#define GvASSUMECV_off(gv) (GvFLAGS(gv) &= ~GVf_ASSUMECV)
108
109#define GvIMPORTED(gv) (GvFLAGS(gv) & GVf_IMPORTED)
110#define GvIMPORTED_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED)
111#define GvIMPORTED_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED)
112
113#define GvIMPORTED_SV(gv) (GvFLAGS(gv) & GVf_IMPORTED_SV)
114#define GvIMPORTED_SV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_SV)
115#define GvIMPORTED_SV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_SV)
116
117#define GvIMPORTED_AV(gv) (GvFLAGS(gv) & GVf_IMPORTED_AV)
118#define GvIMPORTED_AV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_AV)
119#define GvIMPORTED_AV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_AV)
120
121#define GvIMPORTED_HV(gv) (GvFLAGS(gv) & GVf_IMPORTED_HV)
122#define GvIMPORTED_HV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_HV)
123#define GvIMPORTED_HV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_HV)
124
125#define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV)
126#define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
127#define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)
128
743e66e6
GS
129#define GvIN_PAD(gv) (GvFLAGS(gv) & GVf_IN_PAD)
130#define GvIN_PAD_on(gv) (GvFLAGS(gv) |= GVf_IN_PAD)
131#define GvIN_PAD_off(gv) (GvFLAGS(gv) &= ~GVf_IN_PAD)
132
5bd07a3d
DM
133/* XXX: all GvFLAGS options are used, borrowing GvGPFLAGS for the moment */
134
7fb37951
AMS
135#define GVf_UNIQUE 0x0001
136#define GvUNIQUE(gv) (GvGP(gv) && (GvGPFLAGS(gv) & GVf_UNIQUE))
137#define GvUNIQUE_on(gv) (GvGPFLAGS(gv) |= GVf_UNIQUE)
138#define GvUNIQUE_off(gv) (GvGPFLAGS(gv) &= ~GVf_UNIQUE)
5bd07a3d
DM
139
140#ifdef USE_ITHREADS
7fb37951 141#define GV_UNIQUE_CHECK
5bd07a3d 142#else
7fb37951 143#undef GV_UNIQUE_CHECK
5bd07a3d
DM
144#endif
145
79072805
LW
146#define Nullgv Null(GV*)
147
148#define DM_UID 0x003
149#define DM_RUID 0x001
150#define DM_EUID 0x002
151#define DM_GID 0x030
152#define DM_RGID 0x010
153#define DM_EGID 0x020
154#define DM_DELAY 0x100
155
0f303493 156/*
864dbfa3 157 * symbol creation flags, for use in gv_fetchpv() and get_*v()
0f303493
GS
158 */
159#define GV_ADD 0x01 /* add, if symbol not already there */
160#define GV_ADDMULTI 0x02 /* add, pretending it has been added already */
161#define GV_ADDWARN 0x04 /* add, but warn if symbol wasn't already there */
162#define GV_ADDINEVAL 0x08 /* add, as though we're doing so within an eval */
163#define GV_NOINIT 0x10 /* add, but don't init symbol, if type != PVGV */
a92f283d
NC
164/* This is used by toke.c to avoid turing placeholder constants in the symbol
165 table into full PVGVs with attached constant subroutines. */
166#define GV_NOADD_NOINIT 0x20 /* Don't add the symbol if it's not there.
167 Don't init it if it is there but ! PVGV */
6aa01a30 168#define GV_NOEXPAND 0x40 /* Don't expand SvOK() entries to PVGV */
b977d03a
NC
169#define GV_NOTQUAL 0x80 /* A plain symbol name, not qualified with a
170 package (so skip checks for :: and ') */
a92f283d 171
057b822e
NC
172/* SVf_UTF8 (more accurately the return value from SvUTF8) is also valid
173 as a flag to gv_fetch_pvn_flags, so ensure it lies outside this range.
174*/
3c71ae1e
NC
175#define gv_fullname3(sv,gv,prefix) gv_fullname4(sv,gv,prefix,TRUE)
176#define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE)
5082993f 177#define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)