This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
s/Nullcv/NULL/g
[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
834268b8
SH
27/* MSVC++ 6.0 (_MSC_VER == 1200) can't compile pp_hot.c with DEBUGGING enabled
28 * if we include the following assert(). Must be a compiler bug because it
fb9e8e97
SH
29 * works fine with MSVC++ 7.0. Borland (5.5.1) has the same problem. And MinGW
30 * (gcc-3.4.2) has a different problem when compiling win32/perllib.c! */
834268b8 31#if defined(DEBUGGING) && \
fb9e8e97
SH
32 ((!defined(_MSC_VER) || _MSC_VER > 1200) && \
33 !defined(__BORLANDC__) && !defined(__MINGW32__))
f4b190e6
NC
34# define GvGP(gv) (*(assert(SvTYPE(gv) == SVt_PVGV || \
35 SvTYPE(gv) == SVt_PVLV), \
36 &(GvXPVGV(gv)->xgv_gp)))
37#else
38# define GvGP(gv) (GvXPVGV(gv)->xgv_gp)
39#endif
40
a5f75d66
AD
41#define GvNAME(gv) (GvXPVGV(gv)->xgv_name)
42#define GvNAMELEN(gv) (GvXPVGV(gv)->xgv_namelen)
43#define GvSTASH(gv) (GvXPVGV(gv)->xgv_stash)
44#define GvFLAGS(gv) (GvXPVGV(gv)->xgv_flags)
45
954c1994 46/*
ccfc67b7
JH
47=head1 GV Functions
48
954c1994
GS
49=for apidoc Am|SV*|GvSV|GV* gv
50
51Return the SV from the GV.
52
53=cut
54*/
55
79072805 56#define GvSV(gv) (GvGP(gv)->gp_sv)
c69033f2 57#ifdef PERL_DONT_CREATE_GVSV
547f15c3
NC
58#define GvSVn(gv) (*(GvGP(gv)->gp_sv ? \
59 &(GvGP(gv)->gp_sv) : \
60 &(GvGP(gv_SVadd(gv))->gp_sv)))
c69033f2
NC
61#else
62#define GvSVn(gv) GvSV(gv)
63#endif
64
79072805 65#define GvREFCNT(gv) (GvGP(gv)->gp_refcnt)
2035c5e8 66#define GvIO(gv) ((gv) && SvTYPE((SV*)gv) == SVt_PVGV && GvGP(gv) ? GvIOp(gv) : 0)
a0d0e21e
LW
67#define GvIOp(gv) (GvGP(gv)->gp_io)
68#define GvIOn(gv) (GvIO(gv) ? GvIOp(gv) : GvIOp(gv_IOadd(gv)))
79072805
LW
69
70#define GvFORM(gv) (GvGP(gv)->gp_form)
71#define GvAV(gv) (GvGP(gv)->gp_av)
44a8e56a
PP
72
73/* This macro is deprecated. Do not use! */
74#define GvREFCNT_inc(gv) ((GV*)SvREFCNT_inc(gv)) /* DO NOT USE */
79072805 75
79072805
LW
76#define GvAVn(gv) (GvGP(gv)->gp_av ? \
77 GvGP(gv)->gp_av : \
78 GvGP(gv_AVadd(gv))->gp_av)
79072805
LW
79#define GvHV(gv) ((GvGP(gv))->gp_hv)
80
79072805
LW
81#define GvHVn(gv) (GvGP(gv)->gp_hv ? \
82 GvGP(gv)->gp_hv : \
83 GvGP(gv_HVadd(gv))->gp_hv)
79072805
LW
84
85#define GvCV(gv) (GvGP(gv)->gp_cv)
463ee0b2 86#define GvCVGEN(gv) (GvGP(gv)->gp_cvgen)
601f1833 87#define GvCVu(gv) (GvGP(gv)->gp_cvgen ? NULL : GvGP(gv)->gp_cv)
79072805 88
79072805 89#define GvLINE(gv) (GvGP(gv)->gp_line)
b195d487 90#define GvFILE(gv) (GvGP(gv)->gp_file)
57843af0 91#define GvFILEGV(gv) (gv_fetchfile(GvFILE(gv)))
79072805 92
79072805 93#define GvEGV(gv) (GvGP(gv)->gp_egv)
748a9306 94#define GvENAME(gv) GvNAME(GvEGV(gv) ? GvEGV(gv) : gv)
748a9306 95#define GvESTASH(gv) GvSTASH(GvEGV(gv) ? GvEGV(gv) : gv)
79072805 96
a5f75d66
AD
97#define GVf_INTRO 0x01
98#define GVf_MULTI 0x02
99#define GVf_ASSUMECV 0x04
743e66e6 100#define GVf_IN_PAD 0x08
a5f75d66
AD
101#define GVf_IMPORTED 0xF0
102#define GVf_IMPORTED_SV 0x10
103#define GVf_IMPORTED_AV 0x20
104#define GVf_IMPORTED_HV 0x40
105#define GVf_IMPORTED_CV 0x80
106
107#define GvINTRO(gv) (GvFLAGS(gv) & GVf_INTRO)
108#define GvINTRO_on(gv) (GvFLAGS(gv) |= GVf_INTRO)
109#define GvINTRO_off(gv) (GvFLAGS(gv) &= ~GVf_INTRO)
110
111#define GvMULTI(gv) (GvFLAGS(gv) & GVf_MULTI)
112#define GvMULTI_on(gv) (GvFLAGS(gv) |= GVf_MULTI)
113#define GvMULTI_off(gv) (GvFLAGS(gv) &= ~GVf_MULTI)
114
115#define GvASSUMECV(gv) (GvFLAGS(gv) & GVf_ASSUMECV)
116#define GvASSUMECV_on(gv) (GvFLAGS(gv) |= GVf_ASSUMECV)
117#define GvASSUMECV_off(gv) (GvFLAGS(gv) &= ~GVf_ASSUMECV)
118
119#define GvIMPORTED(gv) (GvFLAGS(gv) & GVf_IMPORTED)
120#define GvIMPORTED_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED)
121#define GvIMPORTED_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED)
122
123#define GvIMPORTED_SV(gv) (GvFLAGS(gv) & GVf_IMPORTED_SV)
124#define GvIMPORTED_SV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_SV)
125#define GvIMPORTED_SV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_SV)
126
127#define GvIMPORTED_AV(gv) (GvFLAGS(gv) & GVf_IMPORTED_AV)
128#define GvIMPORTED_AV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_AV)
129#define GvIMPORTED_AV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_AV)
130
131#define GvIMPORTED_HV(gv) (GvFLAGS(gv) & GVf_IMPORTED_HV)
132#define GvIMPORTED_HV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_HV)
133#define GvIMPORTED_HV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_HV)
134
135#define GvIMPORTED_CV(gv) (GvFLAGS(gv) & GVf_IMPORTED_CV)
136#define GvIMPORTED_CV_on(gv) (GvFLAGS(gv) |= GVf_IMPORTED_CV)
137#define GvIMPORTED_CV_off(gv) (GvFLAGS(gv) &= ~GVf_IMPORTED_CV)
138
743e66e6
GS
139#define GvIN_PAD(gv) (GvFLAGS(gv) & GVf_IN_PAD)
140#define GvIN_PAD_on(gv) (GvFLAGS(gv) |= GVf_IN_PAD)
141#define GvIN_PAD_off(gv) (GvFLAGS(gv) &= ~GVf_IN_PAD)
142
49c0300d 143#define GvUNIQUE(gv) 0
40e48b40
DM
144#define GvUNIQUE_on(gv)
145#define GvUNIQUE_off(gv)
5bd07a3d
DM
146
147#ifdef USE_ITHREADS
7fb37951 148#define GV_UNIQUE_CHECK
5bd07a3d 149#else
7fb37951 150#undef GV_UNIQUE_CHECK
5bd07a3d
DM
151#endif
152
79072805
LW
153#define Nullgv Null(GV*)
154
155#define DM_UID 0x003
156#define DM_RUID 0x001
157#define DM_EUID 0x002
158#define DM_GID 0x030
159#define DM_RGID 0x010
160#define DM_EGID 0x020
161#define DM_DELAY 0x100
162
0f303493 163/*
864dbfa3 164 * symbol creation flags, for use in gv_fetchpv() and get_*v()
0f303493
GS
165 */
166#define GV_ADD 0x01 /* add, if symbol not already there */
167#define GV_ADDMULTI 0x02 /* add, pretending it has been added already */
168#define GV_ADDWARN 0x04 /* add, but warn if symbol wasn't already there */
169#define GV_ADDINEVAL 0x08 /* add, as though we're doing so within an eval */
170#define GV_NOINIT 0x10 /* add, but don't init symbol, if type != PVGV */
add2581e
NC
171/* This is used by toke.c to avoid turing placeholder constants in the symbol
172 table into full PVGVs with attached constant subroutines. */
173#define GV_NOADD_NOINIT 0x20 /* Don't add the symbol if it's not there.
174 Don't init it if it is there but ! PVGV */
e26df76a 175#define GV_NOEXPAND 0x40 /* Don't expand SvOK() entries to PVGV */
fafc274c
NC
176#define GV_NOTQUAL 0x80 /* A plain symbol name, not qualified with a
177 package (so skip checks for :: and ') */
add2581e 178
7a5fd60d
NC
179/* SVf_UTF8 (more accurately the return value from SvUTF8) is also valid
180 as a flag to gv_fetch_pvn_flags, so ensure it lies outside this range.
181*/
d9a22066
NC
182#define gv_fullname3(sv,gv,prefix) gv_fullname4(sv,gv,prefix,TRUE)
183#define gv_efullname3(sv,gv,prefix) gv_efullname4(sv,gv,prefix,TRUE)
887986eb 184#define gv_fetchmethod(stash, name) gv_fetchmethod_autoload(stash, name, TRUE)