This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
document unimplemented status of forking pipe open() on windows
[perl5.git] / sv.h
CommitLineData
a0d0e21e 1/* sv.h
79072805 2 *
4eb8286e 3 * Copyright (c) 1991-1999, 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 74
dce16143
MB
75#ifdef USE_THREADS
76
dce16143
MB
77# ifdef EMULATE_ATOMIC_REFCOUNTS
78# define ATOMIC_INC(count) STMT_START { \
533c011a 79 MUTEX_LOCK(&PL_svref_mutex); \
dce16143 80 ++count; \
533c011a 81 MUTEX_UNLOCK(&PL_svref_mutex); \
dce16143 82 } STMT_END
0bfcb09d 83# define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
533c011a 84 MUTEX_LOCK(&PL_svref_mutex); \
0bfcb09d 85 res = (--count == 0); \
533c011a 86 MUTEX_UNLOCK(&PL_svref_mutex); \
dce16143
MB
87 } STMT_END
88# else
89# define ATOMIC_INC(count) atomic_inc(&count)
90# define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
91# endif /* EMULATE_ATOMIC_REFCOUNTS */
92#else
93# define ATOMIC_INC(count) (++count)
83b0a010 94# define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
dce16143
MB
95#endif /* USE_THREADS */
96
a863c7d1 97#ifdef __GNUC__
dce16143
MB
98# define SvREFCNT_inc(sv) \
99 ({ \
100 SV *nsv = (SV*)(sv); \
101 if (nsv) \
102 ATOMIC_INC(SvREFCNT(nsv)); \
103 nsv; \
104 })
8990e307 105#else
a863c7d1 106# if defined(CRIPPLED_CC) || defined(USE_THREADS)
199100c8 107# define SvREFCNT_inc(sv) sv_newref((SV*)sv)
a863c7d1 108# else
dce16143 109# define SvREFCNT_inc(sv) \
6b88bc9c 110 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
a863c7d1 111# endif
8990e307
LW
112#endif
113
a863c7d1
MB
114#define SvREFCNT_dec(sv) sv_free((SV*)sv)
115
8990e307
LW
116#define SVTYPEMASK 0xff
117#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805
LW
118
119#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
120
8990e307
LW
121#define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
122#define SVs_PADTMP 0x00000200 /* in use as tmp */
123#define SVs_PADMY 0x00000400 /* in use a "my" variable */
124#define SVs_TEMP 0x00000800 /* string is stealable? */
125#define SVs_OBJECT 0x00001000 /* is "blessed" */
126#define SVs_GMG 0x00002000 /* has magical get method */
127#define SVs_SMG 0x00004000 /* has magical set method */
128#define SVs_RMG 0x00008000 /* has random magical methods */
129
130#define SVf_IOK 0x00010000 /* has valid public integer value */
131#define SVf_NOK 0x00020000 /* has valid public numeric value */
132#define SVf_POK 0x00040000 /* has valid public pointer value */
133#define SVf_ROK 0x00080000 /* has a valid reference pointer */
a0d0e21e 134
748a9306 135#define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
8990e307
LW
136#define SVf_OOK 0x00200000 /* has valid offset value */
137#define SVf_BREAK 0x00400000 /* refcnt is artificially low */
138#define SVf_READONLY 0x00800000 /* may not be modified */
139
a0d0e21e 140
8990e307
LW
141#define SVp_IOK 0x01000000 /* has valid non-public integer value */
142#define SVp_NOK 0x02000000 /* has valid non-public numeric value */
143#define SVp_POK 0x04000000 /* has valid non-public pointer value */
144#define SVp_SCREAM 0x08000000 /* has been studied? */
145
5bc28da9
NIS
146#define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
147
148#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE|SVf_UTF8)
149
a0d0e21e
LW
150#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
151 SVp_IOK|SVp_NOK|SVp_POK)
152
9e7bc3e8 153#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
a0d0e21e 154
8990e307
LW
155#define PRIVSHIFT 8
156
157/* Some private flags. */
158
f472eb5c 159/* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
032d6771
GS
160#define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
161
25da4f38
IZ
162#define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
163
164#define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
8990e307
LW
165
166#define SVpbm_VALID 0x80000000
bbce6d69 167#define SVpbm_TAIL 0x40000000
8990e307 168
25da4f38
IZ
169#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
170
bf6bd887 171#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
51594c39 172#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
bf6bd887 173
810b8aa5
GS
174#define SVprv_WEAKREF 0x80000000 /* Weak reference */
175
ed6116ce
LW
176struct xrv {
177 SV * xrv_rv; /* pointer to another SV */
178};
179
79072805 180struct xpv {
ed6116ce
LW
181 char * xpv_pv; /* pointer to malloced string */
182 STRLEN xpv_cur; /* length of xpv_pv as a C string */
183 STRLEN xpv_len; /* allocated size */
79072805
LW
184};
185
186struct xpviv {
ed6116ce
LW
187 char * xpv_pv; /* pointer to malloced string */
188 STRLEN xpv_cur; /* length of xpv_pv as a C string */
189 STRLEN xpv_len; /* allocated size */
a0d0e21e 190 IV xiv_iv; /* integer value or pv offset */
79072805
LW
191};
192
ff68c719
PP
193struct xpvuv {
194 char * xpv_pv; /* pointer to malloced string */
195 STRLEN xpv_cur; /* length of xpv_pv as a C string */
196 STRLEN xpv_len; /* allocated size */
197 UV xuv_uv; /* unsigned value or pv offset */
198};
199
79072805 200struct xpvnv {
ed6116ce
LW
201 char * xpv_pv; /* pointer to malloced string */
202 STRLEN xpv_cur; /* length of xpv_pv as a C string */
203 STRLEN xpv_len; /* allocated size */
a0d0e21e 204 IV xiv_iv; /* integer value or pv offset */
65202027 205 NV xnv_nv; /* numeric value, if any */
79072805
LW
206};
207
6ee623d5 208/* These structure must match the beginning of struct xpvhv in hv.h. */
79072805 209struct xpvmg {
ed6116ce
LW
210 char * xpv_pv; /* pointer to malloced string */
211 STRLEN xpv_cur; /* length of xpv_pv as a C string */
212 STRLEN xpv_len; /* allocated size */
a0d0e21e 213 IV xiv_iv; /* integer value or pv offset */
65202027 214 NV xnv_nv; /* numeric value, if any */
79072805
LW
215 MAGIC* xmg_magic; /* linked list of magicalness */
216 HV* xmg_stash; /* class package */
217};
218
219struct xpvlv {
ed6116ce
LW
220 char * xpv_pv; /* pointer to malloced string */
221 STRLEN xpv_cur; /* length of xpv_pv as a C string */
222 STRLEN xpv_len; /* allocated size */
a0d0e21e 223 IV xiv_iv; /* integer value or pv offset */
65202027 224 NV xnv_nv; /* numeric value, if any */
79072805
LW
225 MAGIC* xmg_magic; /* linked list of magicalness */
226 HV* xmg_stash; /* class package */
8990e307 227
79072805
LW
228 STRLEN xlv_targoff;
229 STRLEN xlv_targlen;
230 SV* xlv_targ;
231 char xlv_type;
232};
233
234struct xpvgv {
ed6116ce
LW
235 char * xpv_pv; /* pointer to malloced string */
236 STRLEN xpv_cur; /* length of xpv_pv as a C string */
237 STRLEN xpv_len; /* allocated size */
a0d0e21e 238 IV xiv_iv; /* integer value or pv offset */
65202027 239 NV xnv_nv; /* numeric value, if any */
79072805
LW
240 MAGIC* xmg_magic; /* linked list of magicalness */
241 HV* xmg_stash; /* class package */
8990e307 242
79072805
LW
243 GP* xgv_gp;
244 char* xgv_name;
245 STRLEN xgv_namelen;
246 HV* xgv_stash;
a5f75d66 247 U8 xgv_flags;
79072805
LW
248};
249
250struct xpvbm {
ed6116ce
LW
251 char * xpv_pv; /* pointer to malloced string */
252 STRLEN xpv_cur; /* length of xpv_pv as a C string */
253 STRLEN xpv_len; /* allocated size */
a0d0e21e 254 IV xiv_iv; /* integer value or pv offset */
65202027 255 NV xnv_nv; /* numeric value, if any */
79072805
LW
256 MAGIC* xmg_magic; /* linked list of magicalness */
257 HV* xmg_stash; /* class package */
8990e307 258
79072805
LW
259 I32 xbm_useful; /* is this constant pattern being useful? */
260 U16 xbm_previous; /* how many characters in string before rare? */
261 U8 xbm_rare; /* rarest character in string */
262};
263
57843af0 264/* This structure much match XPVCV in cv.h */
44a8e56a 265
77a005ab
MB
266typedef U16 cv_flags_t;
267
79072805 268struct xpvfm {
ed6116ce
LW
269 char * xpv_pv; /* pointer to malloced string */
270 STRLEN xpv_cur; /* length of xpv_pv as a C string */
271 STRLEN xpv_len; /* allocated size */
a0d0e21e 272 IV xiv_iv; /* integer value or pv offset */
65202027 273 NV xnv_nv; /* numeric value, if any */
79072805
LW
274 MAGIC* xmg_magic; /* linked list of magicalness */
275 HV* xmg_stash; /* class package */
8990e307 276
79072805
LW
277 HV * xcv_stash;
278 OP * xcv_start;
279 OP * xcv_root;
0cb96387 280 void (*xcv_xsub)(pTHXo_ CV*);
a0d0e21e
LW
281 ANY xcv_xsubany;
282 GV * xcv_gv;
57843af0 283 char * xcv_file;
b195d487 284 long xcv_depth; /* >= 2 indicates recursive call */
79072805 285 AV * xcv_padlist;
748a9306 286 CV * xcv_outside;
e858de61 287#ifdef USE_THREADS
f6d98b14 288 perl_mutex *xcv_mutexp; /* protects xcv_owner */
52e1cb5e 289 struct perl_thread *xcv_owner; /* current owner thread */
e858de61 290#endif /* USE_THREADS */
77a005ab 291 cv_flags_t xcv_flags;
44a8e56a 292
79072805
LW
293 I32 xfm_lines;
294};
295
8990e307
LW
296struct xpvio {
297 char * xpv_pv; /* pointer to malloced string */
298 STRLEN xpv_cur; /* length of xpv_pv as a C string */
299 STRLEN xpv_len; /* allocated size */
a0d0e21e 300 IV xiv_iv; /* integer value or pv offset */
65202027 301 NV xnv_nv; /* numeric value, if any */
8990e307
LW
302 MAGIC* xmg_magic; /* linked list of magicalness */
303 HV* xmg_stash; /* class package */
304
760ac839
LW
305 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
306 PerlIO * xio_ofp; /* but sockets need separate streams */
8990e307
LW
307 DIR * xio_dirp; /* for opendir, readdir, etc */
308 long xio_lines; /* $. */
309 long xio_page; /* $% */
310 long xio_page_len; /* $= */
311 long xio_lines_left; /* $- */
312 char * xio_top_name; /* $^ */
313 GV * xio_top_gv; /* $^ */
314 char * xio_fmt_name; /* $~ */
315 GV * xio_fmt_gv; /* $~ */
316 char * xio_bottom_name;/* $^B */
317 GV * xio_bottom_gv; /* $^B */
318 short xio_subprocess; /* -| or |- */
319 char xio_type;
320 char xio_flags;
321};
322
e0c19803
GS
323#define IOf_ARGV 1 /* this fp iterates over ARGV */
324#define IOf_START 2 /* check for null ARGV and substitute '-' */
325#define IOf_FLUSH 4 /* this fp wants a flush after write op */
326#define IOf_DIDTOP 8 /* just did top of form */
327#define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
328#define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
329#define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
8990e307 330
ed6116ce
LW
331/* The following macros define implementation-independent predicates on SVs. */
332
79072805 333#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 334#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e 335#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
25da4f38 336 SVp_IOK|SVp_NOK|SVf_IVisUV))
79072805 337
463ee0b2 338#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
25da4f38
IZ
339#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
340 SVf_IVisUV), \
341 SvOOK_off(sv))
342#define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 343 SvOOK_off(sv))
79072805 344
8990e307
LW
345#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
346#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
347#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
348#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
349#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
350#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
351#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 352
79072805 353#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 354#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 355 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
25da4f38 356#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
827b7e14 357#define SvIOK_only(sv) (SvOK_off(sv), \
a0d0e21e 358 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
25da4f38
IZ
359#define SvIOK_only_UV(sv) (SvOK_off_exc_UV(sv), \
360 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
70401c6b 361
25da4f38
IZ
362#define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
363 == (SVf_IOK|SVf_IVisUV))
364#define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
365 == SVf_IOK)
366
367#define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
368#define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
369#define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
79072805
LW
370
371#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 372#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307
LW
373#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
374#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 375 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805 376
a7cb1f99
GS
377#define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
378#define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
379#define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
5bc28da9 380
79072805 381#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 382#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 383#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
25da4f38 384#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|SVf_IVisUV), \
a0d0e21e 385 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
79072805
LW
386
387#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
388#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
389#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 390
a0d0e21e
LW
391#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
392#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
393#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
394
ed6116ce 395#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e 396#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
a0d0e21e 397#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
79072805 398
8990e307
LW
399#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
400#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
401#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 402
8990e307
LW
403#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
404#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
405#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 406
8990e307
LW
407#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
408#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
409#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 410
8990e307
LW
411#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
412#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
413#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 414
9e7bc3e8
JD
415#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
416#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
417#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
a0d0e21e
LW
418
419/*
420#define Gv_AMG(stash) \
421 (HV_AMAGICmb(stash) && \
422 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
423*/
3280af22 424#define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
a0d0e21e 425
810b8aa5
GS
426#define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
427 == (SVf_ROK|SVprv_WEAKREF))
428#define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
429#define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
430
a0d0e21e 431#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 432
8990e307 433#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 434
8990e307
LW
435#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
436#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
437#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 438
8990e307
LW
439#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
440#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 441
8990e307
LW
442#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
443#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
444#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 445
8990e307
LW
446#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
447#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
448#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 449
8990e307
LW
450#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
451#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
452#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 453
8990e307
LW
454#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
455#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
456#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 457
8990e307
LW
458#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
459#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
460#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 461
25da4f38
IZ
462#define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
463#define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
464#define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
465
8990e307
LW
466#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
467#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
468#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
469
8990e307
LW
470#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
471#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
472#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
473
ed6116ce
LW
474#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
475#define SvRVx(sv) SvRV(sv)
476
463ee0b2
LW
477#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
478#define SvIVXx(sv) SvIVX(sv)
ff68c719
PP
479#define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
480#define SvUVXx(sv) SvUVX(sv)
463ee0b2
LW
481#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
482#define SvNVXx(sv) SvNVX(sv)
483#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
484#define SvPVXx(sv) SvPVX(sv)
79072805 485#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805
LW
486#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
487#define SvLENx(sv) SvLEN(sv)
488#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
6b88bc9c 489#define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
79072805
LW
490#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
491#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
492
493#define SvIV_set(sv, val) \
80b92232
PP
494 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
495 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 496#define SvNV_set(sv, val) \
80b92232
PP
497 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
498 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 499#define SvPV_set(sv, val) \
80b92232
PP
500 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
501 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 502#define SvCUR_set(sv, val) \
80b92232
PP
503 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
504 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 505#define SvLEN_set(sv, val) \
80b92232
PP
506 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
507 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 508#define SvEND_set(sv, val) \
80b92232
PP
509 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
510 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805
LW
511
512#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
513#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
514#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
515
516#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
517
518#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
519#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
520#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
521#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
522
8990e307
LW
523#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
524#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
525#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
526#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
527#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
528#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
529#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
530#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
531#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
532#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
533#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
534#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
535#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
536#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
537#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
538#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
539
bbce6d69 540#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
3280af22
NIS
541#define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
542#define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
bbce6d69 543
c6ee37c5
MB
544#define SvTAINT(sv) \
545 STMT_START { \
3280af22 546 if (PL_tainting) { \
c6ee37c5 547 dTHR; \
3280af22 548 if (PL_tainted) \
c6ee37c5
MB
549 SvTAINTED_on(sv); \
550 } \
551 } STMT_END
79072805 552
a0d0e21e 553#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 554#define SvPV(sv, lp) sv_pvn(sv, &lp)
1fa8b10d 555#define SvPV_nolen(sv) sv_pv(sv)
5bc28da9
NIS
556
557#define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
558#define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
559#define SvPVutf8_nolen(sv) sv_pvutf8(sv)
560
561#define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
562#define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
563#define SvPVbyte_nolen(sv) sv_pvbyte(sv)
564
565#define SvPVx(sv, lp) sv_pvn(sv, &lp)
566#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
567#define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
568#define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
569#define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
570#define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
571
4e35701f
NIS
572#define SvIVx(sv) sv_iv(sv)
573#define SvUVx(sv) sv_uv(sv)
574#define SvNVx(sv) sv_nv(sv)
5bc28da9 575
4e35701f
NIS
576#define SvTRUEx(sv) sv_true(sv)
577
578#define SvIV(sv) SvIVx(sv)
579#define SvNV(sv) SvNVx(sv)
25da4f38 580#define SvUV(sv) SvUVx(sv)
4e35701f 581#define SvTRUE(sv) SvTRUEx(sv)
79072805 582
a80f87c4
GS
583#ifndef CRIPPLED_CC
584/* redefine some things to more efficient inlined versions */
79072805 585
25da4f38 586/* Let us hope that bitmaps for UV and IV are the same */
ff68c719 587#undef SvIV
463ee0b2 588#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 589
ff68c719
PP
590#undef SvUV
591#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
592
593#undef SvNV
463ee0b2 594#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 595
ff68c719
PP
596#undef SvPV
597#define SvPV(sv, lp) \
5bc28da9
NIS
598 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
599 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
70401c6b 600
79072805 601
ff68c719
PP
602#undef SvPV_force
603#define SvPV_force(sv, lp) \
604 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
605 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
a0d0e21e 606
1fa8b10d
JD
607#undef SvPV_nolen
608#define SvPV_nolen(sv) \
5bc28da9
NIS
609 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
610 ? SvPVX(sv) : sv_2pv_nolen(sv))
70401c6b 611
5bc28da9
NIS
612#undef SvPVutf8
613#define SvPVutf8(sv, lp) \
614 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
615 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
70401c6b 616
5bc28da9
NIS
617#undef SvPVutf8_force
618#define SvPVutf8_force(sv, lp) \
70401c6b 619 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
5bc28da9
NIS
620 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
621
622#undef SvPVutf8_nolen
623#define SvPVutf8_nolen(sv) \
70401c6b 624 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
5bc28da9 625 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
70401c6b 626
5bc28da9
NIS
627#undef SvPVutf8
628#define SvPVutf8(sv, lp) \
629 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
630 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
70401c6b 631
5bc28da9
NIS
632#undef SvPVutf8_force
633#define SvPVutf8_force(sv, lp) \
70401c6b 634 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
5bc28da9
NIS
635 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
636
637#undef SvPVutf8_nolen
638#define SvPVutf8_nolen(sv) \
639 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
640 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
70401c6b 641
5bc28da9
NIS
642#undef SvPVbyte
643#define SvPVbyte(sv, lp) \
644 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
645 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
70401c6b 646
5bc28da9
NIS
647#undef SvPVbyte_force
648#define SvPVbyte_force(sv, lp) \
649 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
650 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
651
652#undef SvPVbyte_nolen
653#define SvPVbyte_nolen(sv) \
654 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
655 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
70401c6b 656
1fa8b10d 657
a80f87c4
GS
658#ifdef __GNUC__
659# undef SvIVx
660# undef SvUVx
661# undef SvNVx
662# undef SvPVx
5bc28da9
NIS
663# undef SvPVutf8x
664# undef SvPVbytex
a80f87c4
GS
665# undef SvTRUE
666# undef SvTRUEx
667# define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
668# define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
669# define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
670# define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
5bc28da9
NIS
671# define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
672# define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
a80f87c4 673# define SvTRUE(sv) ( \
8990e307
LW
674 !sv \
675 ? 0 \
676 : SvPOK(sv) \
a80f87c4
GS
677 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
678 nxpv && \
c2f1de04 679 (nxpv->xpv_cur > 1 || \
a80f87c4 680 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
79072805
LW
681 ? 1 \
682 : 0) \
683 : \
684 SvIOK(sv) \
463ee0b2 685 ? SvIVX(sv) != 0 \
79072805 686 : SvNOK(sv) \
463ee0b2
LW
687 ? SvNVX(sv) != 0.0 \
688 : sv_2bool(sv) )
a80f87c4
GS
689# define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
690#else /* __GNUC__ */
691#ifndef USE_THREADS
692/* These inlined macros use globals, which will require a thread
693 * declaration in user code, so we avoid them under threads */
694
695# undef SvIVx
696# undef SvUVx
697# undef SvNVx
698# undef SvPVx
5bc28da9
NIS
699# undef SvPVutf8x
700# undef SvPVbytex
a80f87c4
GS
701# undef SvTRUE
702# undef SvTRUEx
6b88bc9c
GS
703# define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
704# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
705# define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
706# define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
5bc28da9 707# define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
f83ee824 708# define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
a80f87c4
GS
709# define SvTRUE(sv) ( \
710 !sv \
711 ? 0 \
712 : SvPOK(sv) \
6b88bc9c 713 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
c2f1de04 714 (PL_Xpv->xpv_cur > 1 || \
6b88bc9c 715 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
a80f87c4
GS
716 ? 1 \
717 : 0) \
718 : \
719 SvIOK(sv) \
720 ? SvIVX(sv) != 0 \
721 : SvNOK(sv) \
722 ? SvNVX(sv) != 0.0 \
723 : sv_2bool(sv) )
6b88bc9c 724# define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
a80f87c4
GS
725#endif /* !USE_THREADS */
726#endif /* !__GNU__ */
727#endif /* !CRIPPLED_CC */
79072805 728
5f05dabc 729#define newRV_inc(sv) newRV(sv)
5f05dabc 730
ef50df4b 731/* the following macros update any magic values this sv is associated with */
79072805 732
189b2af5
GS
733#define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
734#define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
79072805 735
54310121 736#define SvSetSV_and(dst,src,finally) \
189b2af5 737 STMT_START { \
54310121
PP
738 if ((dst) != (src)) { \
739 sv_setsv(dst, src); \
740 finally; \
189b2af5
GS
741 } \
742 } STMT_END
54310121 743#define SvSetSV_nosteal_and(dst,src,finally) \
189b2af5 744 STMT_START { \
8ebc5c01
PP
745 if ((dst) != (src)) { \
746 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
747 SvTEMP_off(src); \
748 sv_setsv(dst, src); \
749 SvFLAGS(src) |= tMpF; \
54310121 750 finally; \
189b2af5
GS
751 } \
752 } STMT_END
79072805 753
54310121 754#define SvSetSV(dst,src) \
c9d716f7 755 SvSetSV_and(dst,src,/*nothing*/;)
54310121 756#define SvSetSV_nosteal(dst,src) \
c9d716f7 757 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
54310121
PP
758
759#define SvSetMagicSV(dst,src) \
760 SvSetSV_and(dst,src,SvSETMAGIC(dst))
761#define SvSetMagicSV_nosteal(dst,src) \
762 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
763
3967c732 764#ifdef DEBUGGING
79072805 765#define SvPEEK(sv) sv_peek(sv)
3967c732
JD
766#else
767#define SvPEEK(sv) ""
768#endif
79072805 769
3280af22 770#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
36477c24 771
3280af22 772#define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
54310121 773
79072805
LW
774#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
775
933fea7f
GS
776#define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
777#define Sv_Grow sv_grow