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