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