1 /* $RCSfile: sv.h,v $$Revision: 4.1 $$Date: 92/08/07 18:26:57 $
3 * Copyright (c) 1991, Larry Wall
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.
9 * Revision 4.1 92/08/07 18:26:57 lwall
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
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
19 * Revision 4.0.1.2 91/06/07 11:58:33 lwall
20 * patch4: new copyright notice
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
25 * Revision 4.0 91/03/20 01:40:04 lwall
48 /* Compensate for ANSI C misdesign... */
55 /* Using C's structural equivalence to help emulate C++ inheritance here... */
58 void* sv_any; /* pointer to something */
59 U32 sv_refcnt; /* how many references to us */
60 SVTYPE sv_type; /* what sort of thing pointer points to */
61 U8 sv_flags; /* extra flags, some depending on type */
62 U8 sv_storage; /* storage class */
63 U8 sv_private; /* extra value, depending on type */
67 XPVGV* sv_any; /* pointer to something */
68 U32 sv_refcnt; /* how many references to us */
69 SVTYPE sv_type; /* what sort of thing pointer points to */
70 U8 sv_flags; /* extra flags, some depending on type */
71 U8 sv_storage; /* storage class */
72 U8 sv_private; /* extra value, depending on type */
76 XPVGV* sv_any; /* pointer to something */
77 U32 sv_refcnt; /* how many references to us */
78 SVTYPE sv_type; /* what sort of thing pointer points to */
79 U8 sv_flags; /* extra flags, some depending on type */
80 U8 sv_storage; /* storage class */
81 U8 sv_private; /* extra value, depending on type */
85 XPVAV* sv_any; /* pointer to something */
86 U32 sv_refcnt; /* how many references to us */
87 SVTYPE sv_type; /* what sort of thing pointer points to */
88 U8 sv_flags; /* extra flags, some depending on type */
89 U8 sv_storage; /* storage class */
90 U8 sv_private; /* extra value, depending on type */
94 XPVHV* sv_any; /* pointer to something */
95 U32 sv_refcnt; /* how many references to us */
96 SVTYPE sv_type; /* what sort of thing pointer points to */
97 U8 sv_flags; /* extra flags, some depending on type */
98 U8 sv_storage; /* storage class */
99 U8 sv_private; /* extra value, depending on type */
102 #define SvANY(sv) (sv)->sv_any
103 #define SvTYPE(sv) (sv)->sv_type
104 #define SvREFCNT(sv) (sv)->sv_refcnt
105 #define SvFLAGS(sv) (sv)->sv_flags
106 #define SvSTORAGE(sv) (sv)->sv_storage
107 #define SvPRIVATE(sv) (sv)->sv_private
109 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
111 #define SVf_IOK 1 /* has valid integer value */
112 #define SVf_NOK 2 /* has valid numeric value */
113 #define SVf_POK 4 /* has valid pointer value */
114 #define SVf_OOK 8 /* has valid offset value */
115 #define SVf_MAGICAL 16 /* has special methods */
116 #define SVf_OK 32 /* has defined value */
117 #define SVf_TEMP 64 /* eventually in sv_private? */
118 #define SVf_READONLY 128 /* may not be modified */
120 #define SVp_IOK 1 /* has valid non-public integer value */
121 #define SVp_NOK 2 /* has valid non-public numeric value */
122 #define SVp_POK 4 /* has valid non-public pointer value */
123 #define SVp_SCREAM 8 /* has been studied? */
124 #define SVp_TAINTEDDIR 16 /* PATH component is a security risk */
126 #define SVpfm_COMPILED 128
128 #define SVpbm_VALID 128
129 #define SVpbm_CASEFOLD 64
130 #define SVpbm_TAIL 32
132 #define SVpgv_MULTI 128
135 char * xpv_pv; /* pointer to malloced string */
136 STRLEN xpv_cur; /* length of xpv_pv as a C string */
137 STRLEN xpv_len; /* allocated size */
141 char * xpv_pv; /* pointer to malloced string */
142 STRLEN xpv_cur; /* length of xpv_pv as a C string */
143 STRLEN xpv_len; /* allocated size */
144 I32 xiv_iv; /* integer value or pv offset */
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 I32 xiv_iv; /* integer value or pv offset */
152 double xnv_nv; /* numeric value, if any */
156 char * xpv_pv; /* pointer to malloced string */
157 STRLEN xpv_cur; /* length of xpv_pv as a C string */
158 STRLEN xpv_len; /* allocated size */
159 I32 xiv_iv; /* integer value or pv offset */
160 double xnv_nv; /* numeric value, if any */
161 MAGIC* xmg_magic; /* linked list of magicalness */
162 HV* xmg_stash; /* class package */
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 */
180 char * xpv_pv; /* pointer to malloced string */
181 STRLEN xpv_cur; /* length of xpv_pv as a C string */
182 STRLEN xpv_len; /* allocated size */
183 I32 xiv_iv; /* integer value or pv offset */
184 double xnv_nv; /* numeric value, if any */
185 MAGIC* xmg_magic; /* linked list of magicalness */
186 HV* xmg_stash; /* class package */
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 I32 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 I32 xbm_useful; /* is this constant pattern being useful? */
202 U16 xbm_previous; /* how many characters in string before rare? */
203 U8 xbm_rare; /* rarest character in string */
207 char * xpv_pv; /* pointer to malloced string */
208 STRLEN xpv_cur; /* length of xpv_pv as a C string */
209 STRLEN xpv_len; /* allocated size */
210 I32 xiv_iv; /* integer value or pv offset */
211 double xnv_nv; /* numeric value, if any */
212 MAGIC* xmg_magic; /* linked list of magicalness */
213 HV* xmg_stash; /* class package */
217 I32 (*xcv_usersub)();
220 long xcv_depth; /* >= 2 indicates recursive call */
226 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
228 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
229 #define SvOK_on(sv) (SvFLAGS(sv) |= SVf_OK)
230 #define SvOK_off(sv) (SvFLAGS(sv) &= \
231 ~(SVf_IOK|SVf_NOK|SVf_POK|SVf_OK), \
234 #define SvOKp(sv) (SvPRIVATE(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
235 #define SvIOKp(sv) (SvPRIVATE(sv) & SVp_IOK)
236 #define SvIOKp_on(sv) (SvOOK_off(sv), SvPRIVATE(sv) |= SVp_IOK)
237 #define SvNOKp(sv) (SvPRIVATE(sv) & SVp_NOK)
238 #define SvNOKp_on(sv) (SvPRIVATE(sv) |= SVp_NOK)
239 #define SvPOKp(sv) (SvPRIVATE(sv) & SVp_POK)
240 #define SvPOKp_on(sv) (SvPRIVATE(sv) |= SVp_POK)
242 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
243 #define SvIOK_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= (SVf_IOK|SVf_OK))
244 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~SVf_IOK)
245 #define SvIOK_only(sv) (SvOK_off(sv), SvFLAGS(sv) |= (SVf_IOK|SVf_OK))
247 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
248 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVf_OK))
249 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~SVf_NOK)
250 #define SvNOK_only(sv) (SvOK_off(sv), SvFLAGS(sv) |= (SVf_NOK|SVf_OK))
252 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
253 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVf_OK))
254 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~SVf_POK)
255 #define SvPOK_only(sv) (SvOK_off(sv), SvFLAGS(sv) |= (SVf_POK|SVf_OK))
257 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
258 #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
259 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
261 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
262 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
263 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
265 #define SvMAGICAL(sv) (SvFLAGS(sv) & SVf_MAGICAL)
266 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= SVf_MAGICAL)
267 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVf_MAGICAL)
269 #define SvSCREAM(sv) (SvPRIVATE(sv) & SVp_SCREAM)
270 #define SvSCREAM_on(sv) (SvPRIVATE(sv) |= SVp_SCREAM)
271 #define SvSCREAM_off(sv) (SvPRIVATE(sv) &= ~SVp_SCREAM)
273 #define SvTEMP(sv) (SvFLAGS(sv) & SVf_TEMP)
274 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVf_TEMP)
275 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVf_TEMP)
277 #define SvCOMPILED(sv) (SvPRIVATE(sv) & SVpfm_COMPILED)
278 #define SvCOMPILED_on(sv) (SvPRIVATE(sv) |= SVpfm_COMPILED)
279 #define SvCOMPILED_off(sv) (SvPRIVATE(sv) &= ~SVpfm_COMPILED)
281 #define SvTAIL(sv) (SvPRIVATE(sv) & SVpbm_TAIL)
282 #define SvTAIL_on(sv) (SvPRIVATE(sv) |= SVpbm_TAIL)
283 #define SvTAIL_off(sv) (SvPRIVATE(sv) &= ~SVpbm_TAIL)
285 #define SvCASEFOLD(sv) (SvPRIVATE(sv) & SVpbm_CASEFOLD)
286 #define SvCASEFOLD_on(sv) (SvPRIVATE(sv) |= SVpbm_CASEFOLD)
287 #define SvCASEFOLD_off(sv) (SvPRIVATE(sv) &= ~SVpbm_CASEFOLD)
289 #define SvVALID(sv) (SvPRIVATE(sv) & SVpbm_VALID)
290 #define SvVALID_on(sv) (SvPRIVATE(sv) |= SVpbm_VALID)
291 #define SvVALID_off(sv) (SvPRIVATE(sv) &= ~SVpbm_VALID)
293 #define SvMULTI(sv) (SvPRIVATE(sv) & SVpgv_MULTI)
294 #define SvMULTI_on(sv) (SvPRIVATE(sv) |= SVpgv_MULTI)
295 #define SvMULTI_off(sv) (SvPRIVATE(sv) &= ~SVpgv_MULTI)
297 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
298 #define SvIVXx(sv) SvIVX(sv)
299 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
300 #define SvNVXx(sv) SvNVX(sv)
301 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
302 #define SvPVXx(sv) SvPVX(sv)
303 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
304 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
305 #define SvLENx(sv) SvLEN(sv)
306 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
307 #define SvENDx(sv) ((Sv = sv), SvEND(Sv))
308 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
309 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
311 #define SvIV_set(sv, val) \
312 do { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
313 (((XPVIV*) SvANY(sv))->xiv_iv = val); } while (0)
314 #define SvNV_set(sv, val) \
315 do { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
316 (((XPVNV*) SvANY(sv))->xnv_nv = val); } while (0)
317 #define SvPV_set(sv, val) \
318 do { assert(SvTYPE(sv) >= SVt_PV); \
319 (((XPV*) SvANY(sv))->xpv_pv = val); } while (0)
320 #define SvCUR_set(sv, val) \
321 do { assert(SvTYPE(sv) >= SVt_PV); \
322 (((XPV*) SvANY(sv))->xpv_cur = val); } while (0)
323 #define SvLEN_set(sv, val) \
324 do { assert(SvTYPE(sv) >= SVt_PV); \
325 (((XPV*) SvANY(sv))->xpv_len = val); } while (0)
326 #define SvEND_set(sv, val) \
327 do { assert(SvTYPE(sv) >= SVt_PV); \
328 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } while (0)
330 #define SvCUROK(sv) (SvPOK(sv) ? SvCUR(sv) : 0)
332 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
333 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
334 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
336 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
338 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
339 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
340 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
341 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
343 #define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, 0, 't', 0, 0)
349 #define SvPV(sv, lp) sv_pvn(sv, &lp)
353 #define SvIVx(sv) SvIV(sv)
354 #define SvNVx(sv) SvNV(sv)
355 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
356 #define SvTRUEx(sv) SvTRUE(sv)
358 #else /* !CRIPPLED_CC */
360 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
362 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
364 #define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
366 #define SvTRUE(sv) ( \
368 ? ((Xpv = (XPV*)SvANY(sv)) && \
369 (*Xpv->xpv_pv > '0' || \
370 Xpv->xpv_cur > 1 || \
371 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
381 #define SvIVx(sv) ((Sv = sv), SvIV(Sv))
382 #define SvNVx(sv) ((Sv = sv), SvNV(Sv))
383 #define SvPVx(sv, lp) ((Sv = sv), SvPV(Sv, lp))
384 #define SvTRUEx(sv) ((Sv = sv), SvTRUE(Sv))
386 #endif /* CRIPPLED_CC */
388 /* the following macro updates any magic values this sv is associated with */
390 #define SvSETMAGIC(x) if (SvMAGICAL(x)) mg_set(x)
392 #define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
394 #define SvPEEK(sv) sv_peek(sv)
396 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
398 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) pv_grow(pp, lp, (len) * 3 / 2)
401 # define SvGROW(sv,len) if (SvLEN(sv) < (len)) sv_grow(sv,len)
402 # define Sv_Grow sv_grow
404 /* extra parentheses intentionally NOT placed around "len"! */
405 # define SvGROW(sv,len) if (SvLEN(sv) < (unsigned long)len) \
406 sv_grow(sv,(unsigned long)len)
407 # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))