This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.003_01: [changes beteween cumulative patches and tarball release]
[perl5.git] / sv.h
CommitLineData
a0d0e21e 1/* sv.h
79072805 2 *
a0d0e21e 3 * Copyright (c) 1991-1994, 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
8990e307
LW
73
74#define SvREFCNT(sv) (sv)->sv_refcnt
75#ifdef CRIPPLED_CC
2304df62
AD
76#define SvREFCNT_inc(sv) sv_newref((SV*)sv)
77#define SvREFCNT_dec(sv) sv_free((SV*)sv)
8990e307
LW
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
LW
82#endif
83
84#define SVTYPEMASK 0xff
85#define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
79072805
LW
86
87#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
88
8990e307
LW
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
LW
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
LW
108#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK)
109
8990e307
LW
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
LW
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
LW
122#define PRIVSHIFT 8
123
124/* Some private flags. */
125
126#define SVpfm_COMPILED 0x80000000
127
128#define SVpbm_VALID 0x80000000
129#define SVpbm_CASEFOLD 0x40000000
130#define SVpbm_TAIL 0x20000000
131
bf6bd887
PP
132#define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
133
a0d0e21e
LW
134#ifdef OVERLOAD
135#define SVpgv_AM 0x40000000
136/* #define SVpgv_badAM 0x20000000 */
137#endif /* OVERLOAD */
138
ed6116ce
LW
139struct xrv {
140 SV * xrv_rv; /* pointer to another SV */
141};
142
79072805 143struct xpv {
ed6116ce
LW
144 char * xpv_pv; /* pointer to malloced string */
145 STRLEN xpv_cur; /* length of xpv_pv as a C string */
146 STRLEN xpv_len; /* allocated size */
79072805
LW
147};
148
149struct xpviv {
ed6116ce
LW
150 char * xpv_pv; /* pointer to malloced string */
151 STRLEN xpv_cur; /* length of xpv_pv as a C string */
152 STRLEN xpv_len; /* allocated size */
a0d0e21e 153 IV xiv_iv; /* integer value or pv offset */
79072805
LW
154};
155
156struct xpvnv {
ed6116ce
LW
157 char * xpv_pv; /* pointer to malloced string */
158 STRLEN xpv_cur; /* length of xpv_pv as a C string */
159 STRLEN xpv_len; /* allocated size */
a0d0e21e 160 IV xiv_iv; /* integer value or pv offset */
ed6116ce 161 double xnv_nv; /* numeric value, if any */
79072805
LW
162};
163
164struct xpvmg {
ed6116ce
LW
165 char * xpv_pv; /* pointer to malloced string */
166 STRLEN xpv_cur; /* length of xpv_pv as a C string */
167 STRLEN xpv_len; /* allocated size */
a0d0e21e 168 IV xiv_iv; /* integer value or pv offset */
ed6116ce 169 double xnv_nv; /* numeric value, if any */
79072805
LW
170 MAGIC* xmg_magic; /* linked list of magicalness */
171 HV* xmg_stash; /* class package */
172};
173
174struct xpvlv {
ed6116ce
LW
175 char * xpv_pv; /* pointer to malloced string */
176 STRLEN xpv_cur; /* length of xpv_pv as a C string */
177 STRLEN xpv_len; /* allocated size */
a0d0e21e 178 IV xiv_iv; /* integer value or pv offset */
ed6116ce 179 double xnv_nv; /* numeric value, if any */
79072805
LW
180 MAGIC* xmg_magic; /* linked list of magicalness */
181 HV* xmg_stash; /* class package */
8990e307 182
79072805
LW
183 STRLEN xlv_targoff;
184 STRLEN xlv_targlen;
185 SV* xlv_targ;
186 char xlv_type;
187};
188
189struct xpvgv {
ed6116ce
LW
190 char * xpv_pv; /* pointer to malloced string */
191 STRLEN xpv_cur; /* length of xpv_pv as a C string */
192 STRLEN xpv_len; /* allocated size */
a0d0e21e 193 IV xiv_iv; /* integer value or pv offset */
ed6116ce 194 double xnv_nv; /* numeric value, if any */
79072805
LW
195 MAGIC* xmg_magic; /* linked list of magicalness */
196 HV* xmg_stash; /* class package */
8990e307 197
79072805
LW
198 GP* xgv_gp;
199 char* xgv_name;
200 STRLEN xgv_namelen;
201 HV* xgv_stash;
a5f75d66 202 U8 xgv_flags;
79072805
LW
203};
204
205struct xpvbm {
ed6116ce
LW
206 char * xpv_pv; /* pointer to malloced string */
207 STRLEN xpv_cur; /* length of xpv_pv as a C string */
208 STRLEN xpv_len; /* allocated size */
a0d0e21e 209 IV xiv_iv; /* integer value or pv offset */
ed6116ce 210 double xnv_nv; /* numeric value, if any */
79072805
LW
211 MAGIC* xmg_magic; /* linked list of magicalness */
212 HV* xmg_stash; /* class package */
8990e307 213
79072805
LW
214 I32 xbm_useful; /* is this constant pattern being useful? */
215 U16 xbm_previous; /* how many characters in string before rare? */
216 U8 xbm_rare; /* rarest character in string */
217};
218
219struct xpvfm {
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 */
ed6116ce 224 double 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 HV * xcv_stash;
229 OP * xcv_start;
230 OP * xcv_root;
a0d0e21e
LW
231 void (*xcv_xsub)_((CV*));
232 ANY xcv_xsubany;
233 GV * xcv_gv;
79072805
LW
234 GV * xcv_filegv;
235 long xcv_depth; /* >= 2 indicates recursive call */
236 AV * xcv_padlist;
748a9306 237 CV * xcv_outside;
79072805
LW
238 I32 xfm_lines;
239};
240
8990e307
LW
241struct xpvio {
242 char * xpv_pv; /* pointer to malloced string */
243 STRLEN xpv_cur; /* length of xpv_pv as a C string */
244 STRLEN xpv_len; /* allocated size */
a0d0e21e 245 IV xiv_iv; /* integer value or pv offset */
8990e307
LW
246 double xnv_nv; /* numeric value, if any */
247 MAGIC* xmg_magic; /* linked list of magicalness */
248 HV* xmg_stash; /* class package */
249
250 FILE * xio_ifp; /* ifp and ofp are normally the same */
251 FILE * xio_ofp; /* but sockets need separate streams */
252 DIR * xio_dirp; /* for opendir, readdir, etc */
253 long xio_lines; /* $. */
254 long xio_page; /* $% */
255 long xio_page_len; /* $= */
256 long xio_lines_left; /* $- */
257 char * xio_top_name; /* $^ */
258 GV * xio_top_gv; /* $^ */
259 char * xio_fmt_name; /* $~ */
260 GV * xio_fmt_gv; /* $~ */
261 char * xio_bottom_name;/* $^B */
262 GV * xio_bottom_gv; /* $^B */
263 short xio_subprocess; /* -| or |- */
264 char xio_type;
265 char xio_flags;
266};
267
268#define IOf_ARGV 1 /* this fp iterates over ARGV */
269#define IOf_START 2 /* check for null ARGV and substitute '-' */
270#define IOf_FLUSH 4 /* this fp wants a flush after write op */
748a9306 271#define IOf_DIDTOP 8 /* just did top of form */
8990e307 272
ed6116ce
LW
273/* The following macros define implementation-independent predicates on SVs. */
274
79072805 275#define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
748a9306 276#define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
a0d0e21e
LW
277#define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
278 SVp_IOK|SVp_NOK))
79072805 279
463ee0b2 280#define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
a0d0e21e
LW
281
282#ifdef OVERLOAD
283#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
284 SvOOK_off(sv))
285#else
286#define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv))
287#endif /* OVERLOAD */
79072805 288
8990e307
LW
289#define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
290#define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
291#define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
292#define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
293#define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
294#define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
295#define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
463ee0b2 296
79072805 297#define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
8990e307 298#define SvIOK_on(sv) (SvOOK_off(sv), \
a0d0e21e 299 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
8990e307 300#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
a5f75d66 301#define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \
a0d0e21e 302 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
79072805
LW
303
304#define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
a0d0e21e 305#define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
8990e307
LW
306#define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
307#define SvNOK_only(sv) (SvOK_off(sv), \
a0d0e21e 308 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
79072805
LW
309
310#define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
a0d0e21e 311#define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
8990e307 312#define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
c07a80fd
PP
313
314#ifdef OVERLOAD
315#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
a0d0e21e 316 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
c07a80fd
PP
317#else
318#define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \
319 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
320#endif /* OVERLOAD */
79072805
LW
321
322#define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
323#define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
324#define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
79072805 325
a0d0e21e
LW
326#define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
327#define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
328#define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
329
ed6116ce 330#define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
a0d0e21e
LW
331#define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
332
333#ifdef OVERLOAD
334#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
335#else
ed6116ce 336#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
a0d0e21e 337#endif /* OVERLOAD */
79072805 338
8990e307
LW
339#define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
340#define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
341#define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
79072805 342
8990e307
LW
343#define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
344#define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
345#define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
ed6116ce 346
8990e307
LW
347#define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
348#define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
349#define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
ed6116ce 350
8990e307
LW
351#define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
352#define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
353#define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
ed6116ce 354
a0d0e21e
LW
355#ifdef OVERLOAD
356#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
357#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
358#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
359
360/*
361#define Gv_AMG(stash) \
362 (HV_AMAGICmb(stash) && \
363 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
364*/
365#define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash))
366#endif /* OVERLOAD */
367
368#define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
ed6116ce 369
8990e307 370#define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
ed6116ce 371
8990e307
LW
372#define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
373#define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
374#define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
ed6116ce 375
8990e307
LW
376#define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
377#define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
ed6116ce 378
8990e307
LW
379#define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
380#define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
381#define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
79072805 382
8990e307
LW
383#define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
384#define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
385#define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
79072805 386
8990e307
LW
387#define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
388#define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
389#define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
79072805 390
8990e307
LW
391#define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
392#define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
393#define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
79072805 394
8990e307
LW
395#define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
396#define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
397#define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
79072805 398
8990e307
LW
399#define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
400#define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
401#define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
402
403#define SvCASEFOLD(sv) (SvFLAGS(sv) & SVpbm_CASEFOLD)
404#define SvCASEFOLD_on(sv) (SvFLAGS(sv) |= SVpbm_CASEFOLD)
405#define SvCASEFOLD_off(sv) (SvFLAGS(sv) &= ~SVpbm_CASEFOLD)
406
407#define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
408#define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
409#define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
410
ed6116ce
LW
411#define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
412#define SvRVx(sv) SvRV(sv)
413
463ee0b2
LW
414#define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
415#define SvIVXx(sv) SvIVX(sv)
416#define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
417#define SvNVXx(sv) SvNVX(sv)
418#define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
419#define SvPVXx(sv) SvPVX(sv)
79072805 420#define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
79072805
LW
421#define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
422#define SvLENx(sv) SvLEN(sv)
423#define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
8990e307 424#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
79072805
LW
425#define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
426#define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
427
428#define SvIV_set(sv, val) \
80b92232
PP
429 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
430 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
79072805 431#define SvNV_set(sv, val) \
80b92232
PP
432 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
433 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
79072805 434#define SvPV_set(sv, val) \
80b92232
PP
435 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
436 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
79072805 437#define SvCUR_set(sv, val) \
80b92232
PP
438 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
439 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
79072805 440#define SvLEN_set(sv, val) \
80b92232
PP
441 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
442 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
79072805 443#define SvEND_set(sv, val) \
80b92232
PP
444 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
445 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
79072805
LW
446
447#define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
448#define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
449#define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
450
451#define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
452
453#define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
454#define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
455#define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
456#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
457
8990e307
LW
458#define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
459#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
460#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
461#define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
462#define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
463#define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
464#define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
465#define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
466#define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
467#define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
468#define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
469#define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
470#define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
471#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
472#define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
473#define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
474
a0d0e21e 475#define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, Nullsv, 't', Nullch, 0)
79072805
LW
476
477#ifdef CRIPPLED_CC
478
a0d0e21e
LW
479IV SvIV _((SV* sv));
480double SvNV _((SV* sv));
481#define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
463ee0b2 482#define SvPV(sv, lp) sv_pvn(sv, &lp)
a0d0e21e
LW
483char *sv_pvn _((SV *, STRLEN *));
484I32 SvTRUE _((SV *));
79072805 485
463ee0b2
LW
486#define SvIVx(sv) SvIV(sv)
487#define SvNVx(sv) SvNV(sv)
488#define SvPVx(sv, lp) sv_pvn(sv, &lp)
a0d0e21e 489#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
79072805
LW
490#define SvTRUEx(sv) SvTRUE(sv)
491
492#else /* !CRIPPLED_CC */
493
463ee0b2 494#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
79072805 495
463ee0b2 496#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
79072805 497
463ee0b2 498#define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
79072805 499
a0d0e21e
LW
500#define SvPV_force(sv, lp) ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
501
463ee0b2 502#define SvTRUE(sv) ( \
8990e307
LW
503 !sv \
504 ? 0 \
505 : SvPOK(sv) \
79072805
LW
506 ? ((Xpv = (XPV*)SvANY(sv)) && \
507 (*Xpv->xpv_pv > '0' || \
508 Xpv->xpv_cur > 1 || \
509 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
510 ? 1 \
511 : 0) \
512 : \
513 SvIOK(sv) \
463ee0b2 514 ? SvIVX(sv) != 0 \
79072805 515 : SvNOK(sv) \
463ee0b2
LW
516 ? SvNVX(sv) != 0.0 \
517 : sv_2bool(sv) )
79072805 518
8990e307
LW
519#define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
520#define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
521#define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
522#define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
79072805
LW
523
524#endif /* CRIPPLED_CC */
525
526/* the following macro updates any magic values this sv is associated with */
527
8990e307 528#define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
79072805
LW
529
530#define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
531
532#define SvPEEK(sv) sv_peek(sv)
533
534#define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
535
79072805 536#ifndef DOSISH
a0d0e21e 537# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
79072805
LW
538# define Sv_Grow sv_grow
539#else
540 /* extra parentheses intentionally NOT placed around "len"! */
a0d0e21e
LW
541# define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
542 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
79072805
LW
543# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
544#endif /* DOSISH */