Remove xcv_condp CV field which is no longer used.
[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
f6d98b14 245 perl_mutex *xcv_mutexp; /* protects xcv_owner */
12ca11f6 246 struct thread *xcv_owner; /* current owner thread */
e858de61 247#endif /* USE_THREADS */
77a005ab 248 cv_flags_t xcv_flags;
44a8e56a 249
79072805 250 I32 xfm_lines;
251};
252
8990e307 253struct xpvio {
254 char * xpv_pv; /* pointer to malloced string */
255 STRLEN xpv_cur; /* length of xpv_pv as a C string */
256 STRLEN xpv_len; /* allocated size */
a0d0e21e 257 IV xiv_iv; /* integer value or pv offset */
8990e307 258 double xnv_nv; /* numeric value, if any */
259 MAGIC* xmg_magic; /* linked list of magicalness */
260 HV* xmg_stash; /* class package */
261
760ac839 262 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
263 PerlIO * xio_ofp; /* but sockets need separate streams */
8990e307 264 DIR * xio_dirp; /* for opendir, readdir, etc */
265 long xio_lines; /* $. */
266 long xio_page; /* $% */
267 long xio_page_len; /* $= */
268 long xio_lines_left; /* $- */
269 char * xio_top_name; /* $^ */
270 GV * xio_top_gv; /* $^ */
271 char * xio_fmt_name; /* $~ */
272 GV * xio_fmt_gv; /* $~ */
273 char * xio_bottom_name;/* $^B */
274 GV * xio_bottom_gv; /* $^B */
275 short xio_subprocess; /* -| or |- */
276 char xio_type;
277 char xio_flags;
278};
279
280#define IOf_ARGV 1 /* this fp iterates over ARGV */
281#define IOf_START 2 /* check for null ARGV and substitute '-' */
282#define IOf_FLUSH 4 /* this fp wants a flush after write op */
748a9306 283#define IOf_DIDTOP 8 /* just did top of form */
51594c39 284#define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */
8990e307 285
ed6116ce 286/* The following macros define implementation-independent predicates on SVs. */
287
79072805 288#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 289#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e 290#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
291 SVp_IOK|SVp_NOK))
79072805 292
463ee0b2 293#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
a0d0e21e 294
295#ifdef OVERLOAD
296#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
297 SvOOK_off(sv))
298#else
299#define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv))
300#endif /* OVERLOAD */
79072805 301
8990e307 302#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
303#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
304#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
305#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
306#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
307#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
308#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 309
79072805 310#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 311#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 312 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
8990e307 313#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
a5f75d66 314#define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \
a0d0e21e 315 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
79072805 316
317#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 318#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307 319#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
320#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 321 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805 322
323#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 324#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 325#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
c07a80fd 326
327#ifdef OVERLOAD
328#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 329 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
c07a80fd 330#else
331#define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \
332 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
333#endif /* OVERLOAD */
79072805 334
335#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
336#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
337#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 338
a0d0e21e 339#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
340#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
341#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
342
ed6116ce 343#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e 344#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
345
346#ifdef OVERLOAD
347#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
348#else
ed6116ce 349#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
a0d0e21e 350#endif /* OVERLOAD */
79072805 351
8990e307 352#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
353#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
354#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 355
8990e307 356#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
357#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
358#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 359
8990e307 360#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
361#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
362#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 363
8990e307 364#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
365#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
366#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 367
a0d0e21e 368#ifdef OVERLOAD
369#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
370#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
371#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
372
373/*
374#define Gv_AMG(stash) \
375 (HV_AMAGICmb(stash) && \
376 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
377*/
378#define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash))
379#endif /* OVERLOAD */
380
381#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 382
8990e307 383#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 384
8990e307 385#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
386#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
387#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 388
8990e307 389#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
390#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 391
8990e307 392#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
393#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
394#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 395
8990e307 396#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
397#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
398#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 399
8990e307 400#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
401#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
402#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 403
8990e307 404#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
405#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
406#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 407
8990e307 408#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
409#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
410#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 411
8990e307 412#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
413#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
414#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
415
8990e307 416#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
417#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
418#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
419
ed6116ce 420#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
421#define SvRVx(sv) SvRV(sv)
422
463ee0b2 423#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
424#define SvIVXx(sv) SvIVX(sv)
ff68c719 425#define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
426#define SvUVXx(sv) SvUVX(sv)
463ee0b2 427#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
428#define SvNVXx(sv) SvNVX(sv)
429#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
430#define SvPVXx(sv) SvPVX(sv)
79072805 431#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805 432#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
433#define SvLENx(sv) SvLEN(sv)
434#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
8990e307 435#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
79072805 436#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
437#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
438
439#define SvIV_set(sv, val) \
80b92232 440 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
441 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 442#define SvNV_set(sv, val) \
80b92232 443 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
444 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 445#define SvPV_set(sv, val) \
80b92232 446 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
447 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 448#define SvCUR_set(sv, val) \
80b92232 449 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
450 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 451#define SvLEN_set(sv, val) \
80b92232 452 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
453 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 454#define SvEND_set(sv, val) \
80b92232 455 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
456 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805 457
458#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
459#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
460#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
461
462#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
463
464#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
465#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
466#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
467#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
468
8990e307 469#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
470#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
471#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
472#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
473#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
474#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
475#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
476#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
477#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
478#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
479#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
480#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
481#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
482#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
483#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
484#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
485
bbce6d69 486#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
487#define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END
488#define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END
489
490#define SvTAINT(sv) STMT_START{ if(tainted){SvTAINTED_on(sv);} }STMT_END
79072805 491
492#ifdef CRIPPLED_CC
493
a0d0e21e 494IV SvIV _((SV* sv));
ff68c719 495UV SvUV _((SV* sv));
a0d0e21e 496double SvNV _((SV* sv));
497#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 498#define SvPV(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 499char *sv_pvn _((SV *, STRLEN *));
500I32 SvTRUE _((SV *));
79072805 501
463ee0b2 502#define SvIVx(sv) SvIV(sv)
ff68c719 503#define SvUVx(sv) SvUV(sv)
463ee0b2 504#define SvNVx(sv) SvNV(sv)
505#define SvPVx(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 506#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
79072805 507#define SvTRUEx(sv) SvTRUE(sv)
508
509#else /* !CRIPPLED_CC */
510
ff68c719 511#undef SvIV
463ee0b2 512#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 513
ff68c719 514#undef SvUV
515#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
516
517#undef SvNV
463ee0b2 518#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 519
ff68c719 520#undef SvPV
521#define SvPV(sv, lp) \
522 (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
79072805 523
ff68c719 524#undef SvPV_force
525#define SvPV_force(sv, lp) \
526 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
527 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
a0d0e21e 528
ff68c719 529#undef SvTRUE
463ee0b2 530#define SvTRUE(sv) ( \
8990e307 531 !sv \
532 ? 0 \
533 : SvPOK(sv) \
79072805 534 ? ((Xpv = (XPV*)SvANY(sv)) && \
535 (*Xpv->xpv_pv > '0' || \
536 Xpv->xpv_cur > 1 || \
537 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
538 ? 1 \
539 : 0) \
540 : \
541 SvIOK(sv) \
463ee0b2 542 ? SvIVX(sv) != 0 \
79072805 543 : SvNOK(sv) \
463ee0b2 544 ? SvNVX(sv) != 0.0 \
545 : sv_2bool(sv) )
79072805 546
8990e307 547#define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
ff68c719 548#define SvUVx(sv) ((Sv = (sv)), SvUV(Sv))
8990e307 549#define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
550#define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
551#define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
79072805 552
553#endif /* CRIPPLED_CC */
554
5f05dabc 555#define newRV_inc(sv) newRV(sv)
556#ifdef CRIPPLED_CC
557SV *newRV_noinc _((SV *));
558#else
559#define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv)
560#endif
561
79072805 562/* the following macro updates any magic values this sv is associated with */
563
8990e307 564#define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
79072805 565
54310121 566#define SvSetSV_and(dst,src,finally) \
567 if ((dst) != (src)) { \
568 sv_setsv(dst, src); \
569 finally; \
570 }
571#define SvSetSV_nosteal_and(dst,src,finally) \
8ebc5c01 572 if ((dst) != (src)) { \
573 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
574 SvTEMP_off(src); \
575 sv_setsv(dst, src); \
576 SvFLAGS(src) |= tMpF; \
54310121 577 finally; \
8ebc5c01 578 }
79072805 579
54310121 580#define SvSetSV(dst,src) \
c9d716f7 581 SvSetSV_and(dst,src,/*nothing*/;)
54310121 582#define SvSetSV_nosteal(dst,src) \
c9d716f7 583 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
54310121 584
585#define SvSetMagicSV(dst,src) \
586 SvSetSV_and(dst,src,SvSETMAGIC(dst))
587#define SvSetMagicSV_nosteal(dst,src) \
588 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
589
79072805 590#define SvPEEK(sv) sv_peek(sv)
591
36477c24 592#define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no)
593
54310121 594#define boolSV(b) ((b) ? &sv_yes : &sv_no)
595
79072805 596#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
597
79072805 598#ifndef DOSISH
a0d0e21e 599# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
79072805 600# define Sv_Grow sv_grow
601#else
602 /* extra parentheses intentionally NOT placed around "len"! */
a0d0e21e 603# define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
604 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
79072805 605# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
606#endif /* DOSISH */