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