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