This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] fix MakeMaker installbin problem
[perl5.git] / sv.h
CommitLineData
a0d0e21e 1/* sv.h
79072805 2 *
9607fc9c 3 * Copyright (c) 1991-1997, Larry Wall
79072805
LW
4 *
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
7 *
79072805
LW
8 */
9
a0d0e21e
LW
10#ifdef sv_flags
11#undef sv_flags /* Convex has this in <signal.h> for sigvec() */
12#endif
13
79072805 14typedef enum {
a0d0e21e
LW
15 SVt_NULL, /* 0 */
16 SVt_IV, /* 1 */
17 SVt_NV, /* 2 */
18 SVt_RV, /* 3 */
19 SVt_PV, /* 4 */
20 SVt_PVIV, /* 5 */
21 SVt_PVNV, /* 6 */
22 SVt_PVMG, /* 7 */
23 SVt_PVBM, /* 8 */
24 SVt_PVLV, /* 9 */
25 SVt_PVAV, /* 10 */
26 SVt_PVHV, /* 11 */
27 SVt_PVCV, /* 12 */
28 SVt_PVGV, /* 13 */
29 SVt_PVFM, /* 14 */
30 SVt_PVIO /* 15 */
79072805
LW
31} svtype;
32
79072805
LW
33/* Using C's structural equivalence to help emulate C++ inheritance here... */
34
35struct sv {
463ee0b2 36 void* sv_any; /* pointer to something */
79072805 37 U32 sv_refcnt; /* how many references to us */
8990e307 38 U32 sv_flags; /* what we are */
79072805
LW
39};
40
41struct gv {
463ee0b2 42 XPVGV* sv_any; /* pointer to something */
79072805 43 U32 sv_refcnt; /* how many references to us */
8990e307 44 U32 sv_flags; /* what we are */
79072805
LW
45};
46
47struct cv {
232e078e 48 XPVCV* sv_any; /* pointer to something */
79072805 49 U32 sv_refcnt; /* how many references to us */
8990e307 50 U32 sv_flags; /* what we are */
79072805
LW
51};
52
53struct av {
463ee0b2 54 XPVAV* sv_any; /* pointer to something */
79072805 55 U32 sv_refcnt; /* how many references to us */
8990e307 56 U32 sv_flags; /* what we are */
79072805
LW
57};
58
59struct hv {
463ee0b2 60 XPVHV* sv_any; /* pointer to something */
79072805 61 U32 sv_refcnt; /* how many references to us */
8990e307
LW
62 U32 sv_flags; /* what we are */
63};
64
65struct io {
66 XPVIO* sv_any; /* pointer to something */
67 U32 sv_refcnt; /* how many references to us */
68 U32 sv_flags; /* what we are */
79072805
LW
69};
70
463ee0b2 71#define SvANY(sv) (sv)->sv_any
79072805 72#define SvFLAGS(sv) (sv)->sv_flags
aeea060c 73#define SvREFCNT(sv) (sv)->sv_refcnt
a863c7d1
MB
74
75#ifdef __GNUC__
199100c8 76# define SvREFCNT_inc(sv) ({SV* nsv=(SV*)(sv); if(nsv) ++SvREFCNT(nsv); nsv;})
8990e307 77#else
a863c7d1 78# if defined(CRIPPLED_CC) || defined(USE_THREADS)
199100c8 79# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
a863c7d1 80# else
199100c8 81# define SvREFCNT_inc(sv) ((Sv=(SV*)(sv)), (Sv && ++SvREFCNT(Sv)), (SV*)Sv)
a863c7d1 82# endif
8990e307
LW
83#endif
84
a863c7d1
MB
85#define SvREFCNT_dec(sv) sv_free((SV*)sv)
86
8990e307
LW
87#define SVTYPEMASK 0xff
88#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805
LW
89
90#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
91
8990e307
LW
92#define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
93#define SVs_PADTMP 0x00000200 /* in use as tmp */
94#define SVs_PADMY 0x00000400 /* in use a "my" variable */
95#define SVs_TEMP 0x00000800 /* string is stealable? */
96#define SVs_OBJECT 0x00001000 /* is "blessed" */
97#define SVs_GMG 0x00002000 /* has magical get method */
98#define SVs_SMG 0x00004000 /* has magical set method */
99#define SVs_RMG 0x00008000 /* has random magical methods */
100
101#define SVf_IOK 0x00010000 /* has valid public integer value */
102#define SVf_NOK 0x00020000 /* has valid public numeric value */
103#define SVf_POK 0x00040000 /* has valid public pointer value */
104#define SVf_ROK 0x00080000 /* has a valid reference pointer */
a0d0e21e 105
748a9306 106#define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
8990e307
LW
107#define SVf_OOK 0x00200000 /* has valid offset value */
108#define SVf_BREAK 0x00400000 /* refcnt is artificially low */
109#define SVf_READONLY 0x00800000 /* may not be modified */
110
a0d0e21e
LW
111#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK)
112
8990e307
LW
113#define SVp_IOK 0x01000000 /* has valid non-public integer value */
114#define SVp_NOK 0x02000000 /* has valid non-public numeric value */
115#define SVp_POK 0x04000000 /* has valid non-public pointer value */
116#define SVp_SCREAM 0x08000000 /* has been studied? */
117
a0d0e21e
LW
118#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
119 SVp_IOK|SVp_NOK|SVp_POK)
120
121#ifdef OVERLOAD
122#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
123#endif /* OVERLOAD */
124
8990e307
LW
125#define PRIVSHIFT 8
126
127/* Some private flags. */
128
129#define SVpfm_COMPILED 0x80000000
130
131#define SVpbm_VALID 0x80000000
bbce6d69 132#define SVpbm_TAIL 0x40000000
8990e307 133
bf6bd887 134#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
51594c39 135#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
bf6bd887 136
ed6116ce
LW
137struct xrv {
138 SV * xrv_rv; /* pointer to another SV */
139};
140
79072805 141struct xpv {
ed6116ce
LW
142 char * xpv_pv; /* pointer to malloced string */
143 STRLEN xpv_cur; /* length of xpv_pv as a C string */
144 STRLEN xpv_len; /* allocated size */
79072805
LW
145};
146
147struct xpviv {
ed6116ce
LW
148 char * xpv_pv; /* pointer to malloced string */
149 STRLEN xpv_cur; /* length of xpv_pv as a C string */
150 STRLEN xpv_len; /* allocated size */
a0d0e21e 151 IV xiv_iv; /* integer value or pv offset */
79072805
LW
152};
153
ff68c719
PP
154struct xpvuv {
155 char * xpv_pv; /* pointer to malloced string */
156 STRLEN xpv_cur; /* length of xpv_pv as a C string */
157 STRLEN xpv_len; /* allocated size */
158 UV xuv_uv; /* unsigned value or pv offset */
159};
160
79072805 161struct xpvnv {
ed6116ce
LW
162 char * xpv_pv; /* pointer to malloced string */
163 STRLEN xpv_cur; /* length of xpv_pv as a C string */
164 STRLEN xpv_len; /* allocated size */
a0d0e21e 165 IV xiv_iv; /* integer value or pv offset */
ed6116ce 166 double xnv_nv; /* numeric value, if any */
79072805
LW
167};
168
169struct xpvmg {
ed6116ce
LW
170 char * xpv_pv; /* pointer to malloced string */
171 STRLEN xpv_cur; /* length of xpv_pv as a C string */
172 STRLEN xpv_len; /* allocated size */
a0d0e21e 173 IV xiv_iv; /* integer value or pv offset */
ed6116ce 174 double xnv_nv; /* numeric value, if any */
79072805
LW
175 MAGIC* xmg_magic; /* linked list of magicalness */
176 HV* xmg_stash; /* class package */
177};
178
179struct xpvlv {
ed6116ce
LW
180 char * xpv_pv; /* pointer to malloced string */
181 STRLEN xpv_cur; /* length of xpv_pv as a C string */
182 STRLEN xpv_len; /* allocated size */
a0d0e21e 183 IV xiv_iv; /* integer value or pv offset */
ed6116ce 184 double xnv_nv; /* numeric value, if any */
79072805
LW
185 MAGIC* xmg_magic; /* linked list of magicalness */
186 HV* xmg_stash; /* class package */
8990e307 187
79072805
LW
188 STRLEN xlv_targoff;
189 STRLEN xlv_targlen;
190 SV* xlv_targ;
191 char xlv_type;
192};
193
194struct xpvgv {
ed6116ce
LW
195 char * xpv_pv; /* pointer to malloced string */
196 STRLEN xpv_cur; /* length of xpv_pv as a C string */
197 STRLEN xpv_len; /* allocated size */
a0d0e21e 198 IV xiv_iv; /* integer value or pv offset */
ed6116ce 199 double xnv_nv; /* numeric value, if any */
79072805
LW
200 MAGIC* xmg_magic; /* linked list of magicalness */
201 HV* xmg_stash; /* class package */
8990e307 202
79072805
LW
203 GP* xgv_gp;
204 char* xgv_name;
205 STRLEN xgv_namelen;
206 HV* xgv_stash;
a5f75d66 207 U8 xgv_flags;
79072805
LW
208};
209
210struct xpvbm {
ed6116ce
LW
211 char * xpv_pv; /* pointer to malloced string */
212 STRLEN xpv_cur; /* length of xpv_pv as a C string */
213 STRLEN xpv_len; /* allocated size */
a0d0e21e 214 IV xiv_iv; /* integer value or pv offset */
ed6116ce 215 double xnv_nv; /* numeric value, if any */
79072805
LW
216 MAGIC* xmg_magic; /* linked list of magicalness */
217 HV* xmg_stash; /* class package */
8990e307 218
79072805
LW
219 I32 xbm_useful; /* is this constant pattern being useful? */
220 U16 xbm_previous; /* how many characters in string before rare? */
221 U8 xbm_rare; /* rarest character in string */
222};
223
44a8e56a
PP
224/* This structure much match XPVCV */
225
77a005ab
MB
226typedef U16 cv_flags_t;
227
79072805 228struct xpvfm {
ed6116ce
LW
229 char * xpv_pv; /* pointer to malloced string */
230 STRLEN xpv_cur; /* length of xpv_pv as a C string */
231 STRLEN xpv_len; /* allocated size */
a0d0e21e 232 IV xiv_iv; /* integer value or pv offset */
ed6116ce 233 double xnv_nv; /* numeric value, if any */
79072805
LW
234 MAGIC* xmg_magic; /* linked list of magicalness */
235 HV* xmg_stash; /* class package */
8990e307 236
79072805
LW
237 HV * xcv_stash;
238 OP * xcv_start;
239 OP * xcv_root;
a0d0e21e
LW
240 void (*xcv_xsub)_((CV*));
241 ANY xcv_xsubany;
242 GV * xcv_gv;
79072805
LW
243 GV * xcv_filegv;
244 long xcv_depth; /* >= 2 indicates recursive call */
245 AV * xcv_padlist;
748a9306 246 CV * xcv_outside;
e858de61 247#ifdef USE_THREADS
f6d98b14 248 perl_mutex *xcv_mutexp; /* protects xcv_owner */
52e1cb5e 249 struct perl_thread *xcv_owner; /* current owner thread */
e858de61 250#endif /* USE_THREADS */
77a005ab 251 cv_flags_t xcv_flags;
44a8e56a 252
79072805
LW
253 I32 xfm_lines;
254};
255
8990e307
LW
256struct xpvio {
257 char * xpv_pv; /* pointer to malloced string */
258 STRLEN xpv_cur; /* length of xpv_pv as a C string */
259 STRLEN xpv_len; /* allocated size */
a0d0e21e 260 IV xiv_iv; /* integer value or pv offset */
8990e307
LW
261 double xnv_nv; /* numeric value, if any */
262 MAGIC* xmg_magic; /* linked list of magicalness */
263 HV* xmg_stash; /* class package */
264
760ac839
LW
265 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
266 PerlIO * xio_ofp; /* but sockets need separate streams */
8990e307
LW
267 DIR * xio_dirp; /* for opendir, readdir, etc */
268 long xio_lines; /* $. */
269 long xio_page; /* $% */
270 long xio_page_len; /* $= */
271 long xio_lines_left; /* $- */
272 char * xio_top_name; /* $^ */
273 GV * xio_top_gv; /* $^ */
274 char * xio_fmt_name; /* $~ */
275 GV * xio_fmt_gv; /* $~ */
276 char * xio_bottom_name;/* $^B */
277 GV * xio_bottom_gv; /* $^B */
278 short xio_subprocess; /* -| or |- */
279 char xio_type;
280 char xio_flags;
281};
282
283#define IOf_ARGV 1 /* this fp iterates over ARGV */
284#define IOf_START 2 /* check for null ARGV and substitute '-' */
285#define IOf_FLUSH 4 /* this fp wants a flush after write op */
748a9306 286#define IOf_DIDTOP 8 /* just did top of form */
51594c39 287#define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */
8990e307 288
ed6116ce
LW
289/* The following macros define implementation-independent predicates on SVs. */
290
79072805 291#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 292#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e
LW
293#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
294 SVp_IOK|SVp_NOK))
79072805 295
463ee0b2 296#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
a0d0e21e
LW
297
298#ifdef OVERLOAD
299#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
300 SvOOK_off(sv))
301#else
302#define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv))
303#endif /* OVERLOAD */
79072805 304
8990e307
LW
305#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
306#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
307#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
308#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
309#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
310#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
311#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 312
79072805 313#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 314#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 315 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
8990e307 316#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
a5f75d66 317#define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \
a0d0e21e 318 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
79072805
LW
319
320#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 321#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307
LW
322#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
323#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 324 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805
LW
325
326#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 327#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 328#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
c07a80fd
PP
329
330#ifdef OVERLOAD
331#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 332 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
c07a80fd
PP
333#else
334#define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \
335 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
336#endif /* OVERLOAD */
79072805
LW
337
338#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
339#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
340#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 341
a0d0e21e
LW
342#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
343#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
344#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
345
ed6116ce 346#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e
LW
347#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
348
349#ifdef OVERLOAD
350#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
351#else
ed6116ce 352#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
a0d0e21e 353#endif /* OVERLOAD */
79072805 354
8990e307
LW
355#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
356#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
357#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 358
8990e307
LW
359#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
360#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
361#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 362
8990e307
LW
363#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
364#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
365#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 366
8990e307
LW
367#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
368#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
369#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 370
a0d0e21e
LW
371#ifdef OVERLOAD
372#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
373#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
374#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
375
376/*
377#define Gv_AMG(stash) \
378 (HV_AMAGICmb(stash) && \
379 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
380*/
381#define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash))
382#endif /* OVERLOAD */
383
384#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 385
8990e307 386#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 387
8990e307
LW
388#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
389#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
390#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 391
8990e307
LW
392#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
393#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 394
8990e307
LW
395#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
396#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
397#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 398
8990e307
LW
399#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
400#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
401#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 402
8990e307
LW
403#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
404#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
405#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 406
8990e307
LW
407#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
408#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
409#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 410
8990e307
LW
411#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
412#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
413#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 414
8990e307
LW
415#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
416#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
417#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
418
8990e307
LW
419#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
420#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
421#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
422
ed6116ce
LW
423#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
424#define SvRVx(sv) SvRV(sv)
425
463ee0b2
LW
426#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
427#define SvIVXx(sv) SvIVX(sv)
ff68c719
PP
428#define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
429#define SvUVXx(sv) SvUVX(sv)
463ee0b2
LW
430#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
431#define SvNVXx(sv) SvNVX(sv)
432#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
433#define SvPVXx(sv) SvPVX(sv)
79072805 434#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805
LW
435#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
436#define SvLENx(sv) SvLEN(sv)
437#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
8990e307 438#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
79072805
LW
439#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
440#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
441
442#define SvIV_set(sv, val) \
80b92232
PP
443 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
444 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 445#define SvNV_set(sv, val) \
80b92232
PP
446 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
447 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 448#define SvPV_set(sv, val) \
80b92232
PP
449 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
450 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 451#define SvCUR_set(sv, val) \
80b92232
PP
452 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
453 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 454#define SvLEN_set(sv, val) \
80b92232
PP
455 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
456 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 457#define SvEND_set(sv, val) \
80b92232
PP
458 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
459 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805
LW
460
461#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
462#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
463#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
464
465#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
466
467#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
468#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
469#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
470#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
471
8990e307
LW
472#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
473#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
474#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
475#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
476#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
477#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
478#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
479#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
480#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
481#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
482#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
483#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
484#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
485#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
486#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
487#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
488
bbce6d69
PP
489#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
490#define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END
491#define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END
492
c6ee37c5
MB
493#define SvTAINT(sv) \
494 STMT_START { \
495 if (tainting) { \
496 dTHR; \
497 if (tainted) \
498 SvTAINTED_on(sv); \
499 } \
500 } STMT_END
79072805 501
a0d0e21e 502#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 503#define SvPV(sv, lp) sv_pvn(sv, &lp)
4e35701f
NIS
504#define SvIVx(sv) sv_iv(sv)
505#define SvUVx(sv) sv_uv(sv)
506#define SvNVx(sv) sv_nv(sv)
463ee0b2 507#define SvPVx(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 508#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
4e35701f
NIS
509#define SvTRUEx(sv) sv_true(sv)
510
511#define SvIV(sv) SvIVx(sv)
512#define SvNV(sv) SvNVx(sv)
513#define SvUV(sv) SvIVx(sv)
514#define SvTRUE(sv) SvTRUEx(sv)
79072805 515
a80f87c4
GS
516#ifndef CRIPPLED_CC
517/* redefine some things to more efficient inlined versions */
79072805 518
ff68c719 519#undef SvIV
463ee0b2 520#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 521
ff68c719
PP
522#undef SvUV
523#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
524
525#undef SvNV
463ee0b2 526#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 527
ff68c719
PP
528#undef SvPV
529#define SvPV(sv, lp) \
530 (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
79072805 531
ff68c719
PP
532#undef SvPV_force
533#define SvPV_force(sv, lp) \
534 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
535 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
a0d0e21e 536
a80f87c4
GS
537#ifdef __GNUC__
538# undef SvIVx
539# undef SvUVx
540# undef SvNVx
541# undef SvPVx
542# undef SvTRUE
543# undef SvTRUEx
544# define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
545# define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
546# define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
547# define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
548# define SvTRUE(sv) ( \
8990e307
LW
549 !sv \
550 ? 0 \
551 : SvPOK(sv) \
a80f87c4
GS
552 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
553 nxpv && \
554 (*nxpv->xpv_pv > '0' || \
555 nxpv->xpv_cur > 1 || \
556 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
79072805
LW
557 ? 1 \
558 : 0) \
559 : \
560 SvIOK(sv) \
463ee0b2 561 ? SvIVX(sv) != 0 \
79072805 562 : SvNOK(sv) \
463ee0b2
LW
563 ? SvNVX(sv) != 0.0 \
564 : sv_2bool(sv) )
a80f87c4
GS
565# define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
566#else /* __GNUC__ */
567#ifndef USE_THREADS
568/* These inlined macros use globals, which will require a thread
569 * declaration in user code, so we avoid them under threads */
570
571# undef SvIVx
572# undef SvUVx
573# undef SvNVx
574# undef SvPVx
575# undef SvTRUE
576# undef SvTRUEx
aeea060c
NIS
577# define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
578# define SvUVx(sv) ((Sv = (sv)), SvUV(Sv))
579# define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
580# define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
a80f87c4
GS
581# define SvTRUE(sv) ( \
582 !sv \
583 ? 0 \
584 : SvPOK(sv) \
585 ? ((Xpv = (XPV*)SvANY(sv)) && \
586 (*Xpv->xpv_pv > '0' || \
587 Xpv->xpv_cur > 1 || \
588 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
589 ? 1 \
590 : 0) \
591 : \
592 SvIOK(sv) \
593 ? SvIVX(sv) != 0 \
594 : SvNOK(sv) \
595 ? SvNVX(sv) != 0.0 \
596 : sv_2bool(sv) )
597# define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
598#endif /* !USE_THREADS */
599#endif /* !__GNU__ */
600#endif /* !CRIPPLED_CC */
79072805 601
5f05dabc 602#define newRV_inc(sv) newRV(sv)
aeea060c
NIS
603#ifdef __GNUC__
604# undef newRV_noinc
605# define newRV_noinc(sv) ({SV *nsv=newRV((sv)); --SvREFCNT(SvRV(nsv)); nsv;})
606#else
607# if defined(CRIPPLED_CC) || defined(USE_THREADS)
608# else
609# undef newRV_noinc
610# define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv)
611# endif
612#endif /* __GNUC__ */
5f05dabc 613
79072805
LW
614/* the following macro updates any magic values this sv is associated with */
615
8990e307 616#define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
79072805 617
54310121
PP
618#define SvSetSV_and(dst,src,finally) \
619 if ((dst) != (src)) { \
620 sv_setsv(dst, src); \
621 finally; \
622 }
623#define SvSetSV_nosteal_and(dst,src,finally) \
8ebc5c01
PP
624 if ((dst) != (src)) { \
625 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
626 SvTEMP_off(src); \
627 sv_setsv(dst, src); \
628 SvFLAGS(src) |= tMpF; \
54310121 629 finally; \
8ebc5c01 630 }
79072805 631
54310121 632#define SvSetSV(dst,src) \
c9d716f7 633 SvSetSV_and(dst,src,/*nothing*/;)
54310121 634#define SvSetSV_nosteal(dst,src) \
c9d716f7 635 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
54310121
PP
636
637#define SvSetMagicSV(dst,src) \
638 SvSetSV_and(dst,src,SvSETMAGIC(dst))
639#define SvSetMagicSV_nosteal(dst,src) \
640 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
641
79072805
LW
642#define SvPEEK(sv) sv_peek(sv)
643
36477c24
PP
644#define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no)
645
54310121
PP
646#define boolSV(b) ((b) ? &sv_yes : &sv_no)
647
79072805
LW
648#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
649
79072805 650#ifndef DOSISH
a0d0e21e 651# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
79072805
LW
652# define Sv_Grow sv_grow
653#else
654 /* extra parentheses intentionally NOT placed around "len"! */
a0d0e21e
LW
655# define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
656 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
79072805
LW
657# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
658#endif /* DOSISH */