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