ed8acaa491e227f026c25838ef95dcd8371e986a
[p5sagit/p5-mst-13.2.git] / sv.h
1 /* $RCSfile: sv.h,v $$Revision: 4.1 $$Date: 92/08/07 18:26:57 $
2  *
3  *    Copyright (c) 1991, Larry Wall
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  *
8  * $Log:        sv.h,v $
9  * Revision 4.1  92/08/07  18:26:57  lwall
10  * 
11  * Revision 4.0.1.4  92/06/08  15:41:45  lwall
12  * patch20: fixed confusion between a *var's real name and its effective name
13  * patch20: removed implicit int declarations on functions
14  * 
15  * Revision 4.0.1.3  91/11/05  18:41:47  lwall
16  * patch11: random cleanup
17  * patch11: solitary subroutine references no longer trigger typo warnings
18  * 
19  * Revision 4.0.1.2  91/06/07  11:58:33  lwall
20  * patch4: new copyright notice
21  * 
22  * Revision 4.0.1.1  91/04/12  09:16:12  lwall
23  * patch1: you may now use "die" and "caller" in a signal handler
24  * 
25  * Revision 4.0  91/03/20  01:40:04  lwall
26  * 4.0 baseline.
27  * 
28  */
29
30 typedef enum {
31         SVt_NULL,
32         SVt_IV,
33         SVt_NV,
34         SVt_RV,
35         SVt_PV,
36         SVt_PVIV,
37         SVt_PVNV,
38         SVt_PVMG,
39         SVt_PVBM,
40         SVt_PVLV,
41         SVt_PVAV,
42         SVt_PVHV,
43         SVt_PVCV,
44         SVt_PVGV,
45         SVt_PVFM,
46         SVt_PVIO,
47 } svtype;
48
49 /* Using C's structural equivalence to help emulate C++ inheritance here... */
50
51 struct sv {
52     void*       sv_any;         /* pointer to something */
53     U32         sv_refcnt;      /* how many references to us */
54     U32         sv_flags;       /* what we are */
55 };
56
57 struct gv {
58     XPVGV*      sv_any;         /* pointer to something */
59     U32         sv_refcnt;      /* how many references to us */
60     U32         sv_flags;       /* what we are */
61 };
62
63 struct cv {
64     XPVGV*      sv_any;         /* pointer to something */
65     U32         sv_refcnt;      /* how many references to us */
66     U32         sv_flags;       /* what we are */
67 };
68
69 struct av {
70     XPVAV*      sv_any;         /* pointer to something */
71     U32         sv_refcnt;      /* how many references to us */
72     U32         sv_flags;       /* what we are */
73 };
74
75 struct hv {
76     XPVHV*      sv_any;         /* pointer to something */
77     U32         sv_refcnt;      /* how many references to us */
78     U32         sv_flags;       /* what we are */
79 };
80
81 struct io {
82     XPVIO*      sv_any;         /* pointer to something */
83     U32         sv_refcnt;      /* how many references to us */
84     U32         sv_flags;       /* what we are */
85 };
86
87 #define SvANY(sv)       (sv)->sv_any
88 #define SvFLAGS(sv)     (sv)->sv_flags
89
90 #define SvREFCNT(sv)    (sv)->sv_refcnt
91 #ifdef CRIPPLED_CC
92 #define SvREFCNT_inc(sv)        sv_newref(sv)
93 #define SvREFCNT_dec(sv)        sv_free(sv)
94 #else
95 #define SvREFCNT_inc(sv)        ((Sv = (SV*)(sv)), \
96                                     (Sv && ++SvREFCNT(Sv)), (SV*)Sv)
97 #define SvREFCNT_dec(sv)        sv_free(sv)
98 #endif
99
100 #define SVTYPEMASK      0xff
101 #define SvTYPE(sv)      ((sv)->sv_flags & SVTYPEMASK)
102
103 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
104
105 #define SVs_PADBUSY     0x00000100      /* reserved for tmp or my already */
106 #define SVs_PADTMP      0x00000200      /* in use as tmp */
107 #define SVs_PADMY       0x00000400      /* in use a "my" variable */
108 #define SVs_TEMP        0x00000800      /* string is stealable? */
109 #define SVs_OBJECT      0x00001000      /* is "blessed" */
110 #define SVs_GMG         0x00002000      /* has magical get method */
111 #define SVs_SMG         0x00004000      /* has magical set method */
112 #define SVs_RMG         0x00008000      /* has random magical methods */
113
114 #define SVf_IOK         0x00010000      /* has valid public integer value */
115 #define SVf_NOK         0x00020000      /* has valid public numeric value */
116 #define SVf_POK         0x00040000      /* has valid public pointer value */
117 #define SVf_ROK         0x00080000      /* has a valid reference pointer */
118 #define SVf_OK          0x00100000      /* has defined value */
119 #define SVf_OOK         0x00200000      /* has valid offset value */
120 #define SVf_BREAK       0x00400000      /* refcnt is artificially low */
121 #define SVf_READONLY    0x00800000      /* may not be modified */
122
123 #define SVp_IOK         0x01000000      /* has valid non-public integer value */
124 #define SVp_NOK         0x02000000      /* has valid non-public numeric value */
125 #define SVp_POK         0x04000000      /* has valid non-public pointer value */
126 #define SVp_SCREAM      0x08000000      /* has been studied? */
127
128 #define PRIVSHIFT 8
129
130 /* Some private flags. */
131
132 #define SVpfm_COMPILED  0x80000000
133
134 #define SVpbm_VALID     0x80000000
135 #define SVpbm_CASEFOLD  0x40000000
136 #define SVpbm_TAIL      0x20000000
137
138 #define SVpgv_MULTI     0x80000000
139
140 struct xrv {
141     SV *        xrv_rv;         /* pointer to another SV */
142 };
143
144 struct xpv {
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 */
148 };
149
150 struct xpviv {
151     char *      xpv_pv;         /* pointer to malloced string */
152     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
153     STRLEN      xpv_len;        /* allocated size */
154     I32         xiv_iv;         /* integer value or pv offset */
155 };
156
157 struct xpvnv {
158     char *      xpv_pv;         /* pointer to malloced string */
159     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
160     STRLEN      xpv_len;        /* allocated size */
161     I32         xiv_iv;         /* integer value or pv offset */
162     double      xnv_nv;         /* numeric value, if any */
163 };
164
165 struct xpvmg {
166     char *      xpv_pv;         /* pointer to malloced string */
167     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
168     STRLEN      xpv_len;        /* allocated size */
169     I32         xiv_iv;         /* integer value or pv offset */
170     double      xnv_nv;         /* numeric value, if any */
171     MAGIC*      xmg_magic;      /* linked list of magicalness */
172     HV*         xmg_stash;      /* class package */
173 };
174
175 struct xpvlv {
176     char *      xpv_pv;         /* pointer to malloced string */
177     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
178     STRLEN      xpv_len;        /* allocated size */
179     I32         xiv_iv;         /* integer value or pv offset */
180     double      xnv_nv;         /* numeric value, if any */
181     MAGIC*      xmg_magic;      /* linked list of magicalness */
182     HV*         xmg_stash;      /* class package */
183
184     STRLEN      xlv_targoff;
185     STRLEN      xlv_targlen;
186     SV*         xlv_targ;
187     char        xlv_type;
188 };
189
190 struct xpvgv {
191     char *      xpv_pv;         /* pointer to malloced string */
192     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
193     STRLEN      xpv_len;        /* allocated size */
194     I32         xiv_iv;         /* integer value or pv offset */
195     double      xnv_nv;         /* numeric value, if any */
196     MAGIC*      xmg_magic;      /* linked list of magicalness */
197     HV*         xmg_stash;      /* class package */
198
199     GP*         xgv_gp;
200     char*       xgv_name;
201     STRLEN      xgv_namelen;
202     HV*         xgv_stash;
203 };
204
205 struct xpvbm {
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 */
209     I32         xiv_iv;         /* integer value or pv offset */
210     double      xnv_nv;         /* numeric value, if any */
211     MAGIC*      xmg_magic;      /* linked list of magicalness */
212     HV*         xmg_stash;      /* class package */
213
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
219 struct xpvfm {
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 */
223     I32         xiv_iv;         /* integer value or pv offset */
224     double      xnv_nv;         /* numeric value, if any */
225     MAGIC*      xmg_magic;      /* linked list of magicalness */
226     HV*         xmg_stash;      /* class package */
227
228     HV *        xcv_stash;
229     OP *        xcv_start;
230     OP *        xcv_root;
231     I32       (*xcv_usersub)();
232     I32         xcv_userindex;
233     GV *        xcv_filegv;
234     long        xcv_depth;              /* >= 2 indicates recursive call */
235     AV *        xcv_padlist;
236     bool        xcv_deleted;
237     I32         xfm_lines;
238 };
239
240 struct xpvio {
241     char *      xpv_pv;         /* pointer to malloced string */
242     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
243     STRLEN      xpv_len;        /* allocated size */
244     I32         xiv_iv;         /* integer value or pv offset */
245     double      xnv_nv;         /* numeric value, if any */
246     MAGIC*      xmg_magic;      /* linked list of magicalness */
247     HV*         xmg_stash;      /* class package */
248
249     FILE *      xio_ifp;        /* ifp and ofp are normally the same */
250     FILE *      xio_ofp;        /* but sockets need separate streams */
251     DIR *       xio_dirp;       /* for opendir, readdir, etc */
252     long        xio_lines;      /* $. */
253     long        xio_page;       /* $% */
254     long        xio_page_len;   /* $= */
255     long        xio_lines_left; /* $- */
256     char *      xio_top_name;   /* $^ */
257     GV *        xio_top_gv;     /* $^ */
258     char *      xio_fmt_name;   /* $~ */
259     GV *        xio_fmt_gv;     /* $~ */
260     char *      xio_bottom_name;/* $^B */
261     GV *        xio_bottom_gv;  /* $^B */
262     short       xio_subprocess; /* -| or |- */
263     char        xio_type;
264     char        xio_flags;
265 };
266
267 #define IOf_ARGV 1      /* this fp iterates over ARGV */
268 #define IOf_START 2     /* check for null ARGV and substitute '-' */
269 #define IOf_FLUSH 4     /* this fp wants a flush after write op */
270
271 /* The following macros define implementation-independent predicates on SVs. */
272
273 #define SvNIOK(sv)              (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
274
275 #define SvOK(sv)                (SvFLAGS(sv) & SVf_OK)
276 #define SvOK_on(sv)             (SvFLAGS(sv) |= SVf_OK)
277 #define SvOK_off(sv)            (SvFLAGS(sv) &=                            \
278                                         ~(SVf_IOK|SVf_NOK|SVf_POK|SVf_OK|  \
279                                           SVp_IOK|SVp_NOK|SVp_POK|SVf_ROK),\
280                                         SvOOK_off(sv))
281
282 #define SvOKp(sv)               (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
283 #define SvIOKp(sv)              (SvFLAGS(sv) & SVp_IOK)
284 #define SvIOKp_on(sv)           (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
285 #define SvNOKp(sv)              (SvFLAGS(sv) & SVp_NOK)
286 #define SvNOKp_on(sv)           (SvFLAGS(sv) |= SVp_NOK)
287 #define SvPOKp(sv)              (SvFLAGS(sv) & SVp_POK)
288 #define SvPOKp_on(sv)           (SvFLAGS(sv) |= SVp_POK)
289
290 #define SvIOK(sv)               (SvFLAGS(sv) & SVf_IOK)
291 #define SvIOK_on(sv)            (SvOOK_off(sv), \
292                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK|SVf_OK))
293 #define SvIOK_off(sv)           (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
294 #define SvIOK_only(sv)          (SvOK_off(sv), \
295                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK|SVf_OK))
296
297 #define SvNOK(sv)               (SvFLAGS(sv) & SVf_NOK)
298 #define SvNOK_on(sv)            (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK|SVf_OK))
299 #define SvNOK_off(sv)           (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
300 #define SvNOK_only(sv)          (SvOK_off(sv), \
301                                     SvFLAGS(sv) |= (SVf_NOK|SVp_NOK|SVf_OK))
302
303 #define SvPOK(sv)               (SvFLAGS(sv) & SVf_POK)
304 #define SvPOK_on(sv)            (SvFLAGS(sv) |= (SVf_POK|SVp_POK|SVf_OK))
305 #define SvPOK_off(sv)           (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
306 #define SvPOK_only(sv)          (SvOK_off(sv), \
307                                     SvFLAGS(sv) |= (SVf_POK|SVp_POK|SVf_OK))
308
309 #define SvOOK(sv)               (SvFLAGS(sv) & SVf_OOK)
310 #define SvOOK_on(sv)            (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
311 #define SvOOK_off(sv)           (SvOOK(sv) && sv_backoff(sv))
312
313 #define SvROK(sv)               (SvFLAGS(sv) & SVf_ROK)
314 #define SvROK_on(sv)            (SvFLAGS(sv) |= SVf_ROK|SVf_OK)
315 #define SvROK_off(sv)           (SvFLAGS(sv) &= ~SVf_ROK)
316
317 #define SvMAGICAL(sv)           (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
318 #define SvMAGICAL_on(sv)        (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
319 #define SvMAGICAL_off(sv)       (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
320
321 #define SvGMAGICAL(sv)          (SvFLAGS(sv) & SVs_GMG)
322 #define SvGMAGICAL_on(sv)       (SvFLAGS(sv) |= SVs_GMG)
323 #define SvGMAGICAL_off(sv)      (SvFLAGS(sv) &= ~SVs_GMG)
324
325 #define SvSMAGICAL(sv)          (SvFLAGS(sv) & SVs_SMG)
326 #define SvSMAGICAL_on(sv)       (SvFLAGS(sv) |= SVs_SMG)
327 #define SvSMAGICAL_off(sv)      (SvFLAGS(sv) &= ~SVs_SMG)
328
329 #define SvRMAGICAL(sv)          (SvFLAGS(sv) & SVs_RMG)
330 #define SvRMAGICAL_on(sv)       (SvFLAGS(sv) |= SVs_RMG)
331 #define SvRMAGICAL_off(sv)      (SvFLAGS(sv) &= ~SVs_RMG)
332
333 #define SvTHINKFIRST(sv)        (SvFLAGS(sv) & (SVf_ROK|SVf_READONLY))
334
335 #define SvPADBUSY(sv)           (SvFLAGS(sv) & SVs_PADBUSY)
336
337 #define SvPADTMP(sv)            (SvFLAGS(sv) & SVs_PADTMP)
338 #define SvPADTMP_on(sv)         (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
339 #define SvPADTMP_off(sv)        (SvFLAGS(sv) &= ~SVs_PADTMP)
340
341 #define SvPADMY(sv)             (SvFLAGS(sv) & SVs_PADMY)
342 #define SvPADMY_on(sv)          (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
343
344 #define SvTEMP(sv)              (SvFLAGS(sv) & SVs_TEMP)
345 #define SvTEMP_on(sv)           (SvFLAGS(sv) |= SVs_TEMP)
346 #define SvTEMP_off(sv)          (SvFLAGS(sv) &= ~SVs_TEMP)
347
348 #define SvOBJECT(sv)            (SvFLAGS(sv) & SVs_OBJECT)
349 #define SvOBJECT_on(sv)         (SvFLAGS(sv) |= SVs_OBJECT)
350 #define SvOBJECT_off(sv)        (SvFLAGS(sv) &= ~SVs_OBJECT)
351
352 #define SvREADONLY(sv)          (SvFLAGS(sv) & SVf_READONLY)
353 #define SvREADONLY_on(sv)       (SvFLAGS(sv) |= SVf_READONLY)
354 #define SvREADONLY_off(sv)      (SvFLAGS(sv) &= ~SVf_READONLY)
355
356 #define SvSCREAM(sv)            (SvFLAGS(sv) & SVp_SCREAM)
357 #define SvSCREAM_on(sv)         (SvFLAGS(sv) |= SVp_SCREAM)
358 #define SvSCREAM_off(sv)        (SvFLAGS(sv) &= ~SVp_SCREAM)
359
360 #define SvCOMPILED(sv)          (SvFLAGS(sv) & SVpfm_COMPILED)
361 #define SvCOMPILED_on(sv)       (SvFLAGS(sv) |= SVpfm_COMPILED)
362 #define SvCOMPILED_off(sv)      (SvFLAGS(sv) &= ~SVpfm_COMPILED)
363
364 #define SvTAIL(sv)              (SvFLAGS(sv) & SVpbm_TAIL)
365 #define SvTAIL_on(sv)           (SvFLAGS(sv) |= SVpbm_TAIL)
366 #define SvTAIL_off(sv)          (SvFLAGS(sv) &= ~SVpbm_TAIL)
367
368 #define SvCASEFOLD(sv)          (SvFLAGS(sv) & SVpbm_CASEFOLD)
369 #define SvCASEFOLD_on(sv)       (SvFLAGS(sv) |= SVpbm_CASEFOLD)
370 #define SvCASEFOLD_off(sv)      (SvFLAGS(sv) &= ~SVpbm_CASEFOLD)
371
372 #define SvVALID(sv)             (SvFLAGS(sv) & SVpbm_VALID)
373 #define SvVALID_on(sv)          (SvFLAGS(sv) |= SVpbm_VALID)
374 #define SvVALID_off(sv)         (SvFLAGS(sv) &= ~SVpbm_VALID)
375
376 #define SvMULTI(sv)             (SvFLAGS(sv) & SVpgv_MULTI)
377 #define SvMULTI_on(sv)          (SvFLAGS(sv) |= SVpgv_MULTI)
378 #define SvMULTI_off(sv)         (SvFLAGS(sv) &= ~SVpgv_MULTI)
379
380 #define SvRV(sv) ((XRV*)  SvANY(sv))->xrv_rv
381 #define SvRVx(sv) SvRV(sv)
382
383 #define SvIVX(sv) ((XPVIV*)  SvANY(sv))->xiv_iv
384 #define SvIVXx(sv) SvIVX(sv)
385 #define SvNVX(sv)  ((XPVNV*)SvANY(sv))->xnv_nv
386 #define SvNVXx(sv) SvNVX(sv)
387 #define SvPVX(sv)  ((XPV*)  SvANY(sv))->xpv_pv
388 #define SvPVXx(sv) SvPVX(sv)
389 #define SvCUR(sv) ((XPV*)  SvANY(sv))->xpv_cur
390 #define SvLEN(sv) ((XPV*)  SvANY(sv))->xpv_len
391 #define SvLENx(sv) SvLEN(sv)
392 #define SvEND(sv)(((XPV*)  SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
393 #define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
394 #define SvMAGIC(sv)     ((XPVMG*)  SvANY(sv))->xmg_magic
395 #define SvSTASH(sv)     ((XPVMG*)  SvANY(sv))->xmg_stash
396
397 #define SvIV_set(sv, val) \
398         do { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
399                 (((XPVIV*)  SvANY(sv))->xiv_iv = val); } while (0)
400 #define SvNV_set(sv, val) \
401         do { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
402                 (((XPVNV*)  SvANY(sv))->xnv_nv = val); } while (0)
403 #define SvPV_set(sv, val) \
404         do { assert(SvTYPE(sv) >= SVt_PV); \
405                 (((XPV*)  SvANY(sv))->xpv_pv = val); } while (0)
406 #define SvCUR_set(sv, val) \
407         do { assert(SvTYPE(sv) >= SVt_PV); \
408                 (((XPV*)  SvANY(sv))->xpv_cur = val); } while (0)
409 #define SvLEN_set(sv, val) \
410         do { assert(SvTYPE(sv) >= SVt_PV); \
411                 (((XPV*)  SvANY(sv))->xpv_len = val); } while (0)
412 #define SvEND_set(sv, val) \
413         do { assert(SvTYPE(sv) >= SVt_PV); \
414                 (((XPV*)  SvANY(sv))->xpv_cur = val - SvPVX(sv)); } while (0)
415
416 #define SvCUROK(sv) (SvPOK(sv) ? SvCUR(sv) : 0)
417
418 #define BmRARE(sv)      ((XPVBM*)  SvANY(sv))->xbm_rare
419 #define BmUSEFUL(sv)    ((XPVBM*)  SvANY(sv))->xbm_useful
420 #define BmPREVIOUS(sv)  ((XPVBM*)  SvANY(sv))->xbm_previous
421
422 #define FmLINES(sv)     ((XPVFM*)  SvANY(sv))->xfm_lines
423
424 #define LvTYPE(sv)      ((XPVLV*)  SvANY(sv))->xlv_type
425 #define LvTARG(sv)      ((XPVLV*)  SvANY(sv))->xlv_targ
426 #define LvTARGOFF(sv)   ((XPVLV*)  SvANY(sv))->xlv_targoff
427 #define LvTARGLEN(sv)   ((XPVLV*)  SvANY(sv))->xlv_targlen
428
429 #define IoIFP(sv)       ((XPVIO*)  SvANY(sv))->xio_ifp
430 #define IoOFP(sv)       ((XPVIO*)  SvANY(sv))->xio_ofp
431 #define IoDIRP(sv)      ((XPVIO*)  SvANY(sv))->xio_dirp
432 #define IoLINES(sv)     ((XPVIO*)  SvANY(sv))->xio_lines
433 #define IoPAGE(sv)      ((XPVIO*)  SvANY(sv))->xio_page
434 #define IoPAGE_LEN(sv)  ((XPVIO*)  SvANY(sv))->xio_page_len
435 #define IoLINES_LEFT(sv)((XPVIO*)  SvANY(sv))->xio_lines_left
436 #define IoTOP_NAME(sv)  ((XPVIO*)  SvANY(sv))->xio_top_name
437 #define IoTOP_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_top_gv
438 #define IoFMT_NAME(sv)  ((XPVIO*)  SvANY(sv))->xio_fmt_name
439 #define IoFMT_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_fmt_gv
440 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
441 #define IoBOTTOM_GV(sv) ((XPVIO*)  SvANY(sv))->xio_bottom_gv
442 #define IoSUBPROCESS(sv)((XPVIO*)  SvANY(sv))->xio_subprocess
443 #define IoTYPE(sv)      ((XPVIO*)  SvANY(sv))->xio_type
444 #define IoFLAGS(sv)     ((XPVIO*)  SvANY(sv))->xio_flags
445
446 #define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, 0, 't', 0, 0)
447
448 #ifdef CRIPPLED_CC
449
450 double SvIV();
451 double SvNV();
452 #define SvPV(sv, lp) sv_pvn(sv, &lp)
453 char *sv_pvn();
454 I32 SvTRUE();
455
456 #define SvIVx(sv) SvIV(sv)
457 #define SvNVx(sv) SvNV(sv)
458 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
459 #define SvTRUEx(sv) SvTRUE(sv)
460
461 #else /* !CRIPPLED_CC */
462
463 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
464
465 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
466
467 #define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
468
469 #define SvTRUE(sv) (                                            \
470     !sv                                                         \
471     ? 0                                                         \
472     :    SvPOK(sv)                                              \
473         ?   ((Xpv = (XPV*)SvANY(sv)) &&                         \
474              (*Xpv->xpv_pv > '0' ||                             \
475               Xpv->xpv_cur > 1 ||                               \
476               (Xpv->xpv_cur && *Xpv->xpv_pv != '0'))            \
477              ? 1                                                \
478              : 0)                                               \
479         :                                                       \
480             SvIOK(sv)                                           \
481             ? SvIVX(sv) != 0                                    \
482             :   SvNOK(sv)                                       \
483                 ? SvNVX(sv) != 0.0                              \
484                 : sv_2bool(sv) )
485
486 #define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
487 #define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
488 #define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
489 #define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
490
491 #endif /* CRIPPLED_CC */
492
493 /* the following macro updates any magic values this sv is associated with */
494
495 #define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x)
496
497 #define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
498
499 #define SvPEEK(sv) sv_peek(sv)
500
501 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
502
503 #ifndef DOSISH
504 #  define SvGROW(sv,len) if (SvLEN(sv) < (len)) sv_grow(sv,len)
505 #  define Sv_Grow sv_grow
506 #else
507     /* extra parentheses intentionally NOT placed around "len"! */
508 #  define SvGROW(sv,len) if (SvLEN(sv) < (unsigned long)len) \
509                 sv_grow(sv,(unsigned long)len)
510 #  define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))
511 #endif /* DOSISH */