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_ROK 16 /* has a valid reference pointer */
116 #define SVf_OK 32 /* has defined value */
117 #define SVf_MAGICAL 64 /* has special methods */
118 #define SVf_THINKFIRST 128 /* may not be changed without thought */
120 #define SVs_PADBUSY 1 /* reserved for tmp or my already */
121 #define SVs_PADTMP 2 /* in use as tmp */
122 #define SVs_PADMY 4 /* in use a "my" variable */
125 #define SVs_TEMP 32 /* string is stealable? */
126 #define SVs_OBJECT 64 /* is "blessed" */
127 #define SVs_READONLY 128 /* may not be modified */
129 #define SVp_IOK 1 /* has valid non-public integer value */
130 #define SVp_NOK 2 /* has valid non-public numeric value */
131 #define SVp_POK 4 /* has valid non-public pointer value */
132 #define SVp_SCREAM 8 /* has been studied? */
133 #define SVp_TAINTEDDIR 16 /* PATH component is a security risk */
135 #define SVpfm_COMPILED 128
137 #define SVpbm_VALID 128
138 #define SVpbm_CASEFOLD 64
139 #define SVpbm_TAIL 32
141 #define SVpgv_MULTI 128
144 SV * xrv_rv; /* pointer to another SV */
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 */
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 I32 xiv_iv; /* integer value or pv offset */
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 I32 xiv_iv; /* integer value or pv offset */
165 double xnv_nv; /* numeric value, if any */
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 I32 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 */
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 I32 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 */
193 char * xpv_pv; /* pointer to malloced string */
194 STRLEN xpv_cur; /* length of xpv_pv as a C string */
195 STRLEN xpv_len; /* allocated size */
196 I32 xiv_iv; /* integer value or pv offset */
197 double xnv_nv; /* numeric value, if any */
198 MAGIC* xmg_magic; /* linked list of magicalness */
199 HV* xmg_stash; /* class package */
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 */
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 */
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 */
230 I32 (*xcv_usersub)();
233 long xcv_depth; /* >= 2 indicates recursive call */
239 /* The following macros define implementation-independent predicates on SVs. */
241 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
243 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
244 #define SvOK_on(sv) (SvFLAGS(sv) |= SVf_OK)
245 #define SvOK_off(sv) (SvFLAGS(sv) &= \
246 ~(SVf_IOK|SVf_NOK|SVf_POK|SVf_OK), \
249 #define SvOKp(sv) (SvPRIVATE(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
250 #define SvIOKp(sv) (SvPRIVATE(sv) & SVp_IOK)
251 #define SvIOKp_on(sv) (SvOOK_off(sv), SvPRIVATE(sv) |= SVp_IOK)
252 #define SvNOKp(sv) (SvPRIVATE(sv) & SVp_NOK)
253 #define SvNOKp_on(sv) (SvPRIVATE(sv) |= SVp_NOK)
254 #define SvPOKp(sv) (SvPRIVATE(sv) & SVp_POK)
255 #define SvPOKp_on(sv) (SvPRIVATE(sv) |= SVp_POK)
257 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
258 #define SvIOK_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= (SVf_IOK|SVf_OK))
259 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~SVf_IOK)
260 #define SvIOK_only(sv) (SvOK_off(sv), SvFLAGS(sv) |= (SVf_IOK|SVf_OK))
262 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
263 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVf_OK))
264 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~SVf_NOK)
265 #define SvNOK_only(sv) (SvOK_off(sv), SvFLAGS(sv) |= (SVf_NOK|SVf_OK))
267 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
268 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVf_OK))
269 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~SVf_POK)
270 #define SvPOK_only(sv) (SvOK_off(sv), SvFLAGS(sv) |= (SVf_POK|SVf_OK))
272 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
273 #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
274 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
276 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
277 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK|SVf_THINKFIRST|SVf_OK)
278 #define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
280 #define SvMAGICAL(sv) (SvFLAGS(sv) & SVf_MAGICAL)
281 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= SVf_MAGICAL)
282 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVf_MAGICAL)
284 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
285 #define SvTHINKFIRST_on(sv) (SvFLAGS(sv) |= SVf_THINKFIRST)
286 #define SvTHINKFIRST_off(sv) (SvFLAGS(sv) &= ~SVf_THINKFIRST)
288 #define SvPADBUSY(sv) (SvSTORAGE(sv) & SVs_PADBUSY)
290 #define SvPADTMP(sv) (SvSTORAGE(sv) & SVs_PADTMP)
291 #define SvPADTMP_on(sv) (SvSTORAGE(sv) |= SVs_PADTMP|SVs_PADBUSY)
292 #define SvPADTMP_off(sv) (SvSTORAGE(sv) &= ~SVs_PADTMP)
294 #define SvPADMY(sv) (SvSTORAGE(sv) & SVs_PADMY)
295 #define SvPADMY_on(sv) (SvSTORAGE(sv) |= SVs_PADMY|SVs_PADBUSY)
297 #define SvTEMP(sv) (SvSTORAGE(sv) & SVs_TEMP)
298 #define SvTEMP_on(sv) (SvSTORAGE(sv) |= SVs_TEMP)
299 #define SvTEMP_off(sv) (SvSTORAGE(sv) &= ~SVs_TEMP)
301 #define SvOBJECT(sv) (SvSTORAGE(sv) & SVs_OBJECT)
302 #define SvOBJECT_on(sv) (SvSTORAGE(sv) |= SVs_OBJECT)
303 #define SvOBJECT_off(sv) (SvSTORAGE(sv) &= ~SVs_OBJECT)
305 #define SvREADONLY(sv) (SvSTORAGE(sv) & SVs_READONLY)
306 #define SvREADONLY_on(sv) (SvSTORAGE(sv) |= SVs_READONLY, \
308 #define SvREADONLY_off(sv) (SvSTORAGE(sv) &= ~SVs_READONLY)
310 #define SvSCREAM(sv) (SvPRIVATE(sv) & SVp_SCREAM)
311 #define SvSCREAM_on(sv) (SvPRIVATE(sv) |= SVp_SCREAM)
312 #define SvSCREAM_off(sv) (SvPRIVATE(sv) &= ~SVp_SCREAM)
314 #define SvCOMPILED(sv) (SvPRIVATE(sv) & SVpfm_COMPILED)
315 #define SvCOMPILED_on(sv) (SvPRIVATE(sv) |= SVpfm_COMPILED)
316 #define SvCOMPILED_off(sv) (SvPRIVATE(sv) &= ~SVpfm_COMPILED)
318 #define SvTAIL(sv) (SvPRIVATE(sv) & SVpbm_TAIL)
319 #define SvTAIL_on(sv) (SvPRIVATE(sv) |= SVpbm_TAIL)
320 #define SvTAIL_off(sv) (SvPRIVATE(sv) &= ~SVpbm_TAIL)
322 #define SvCASEFOLD(sv) (SvPRIVATE(sv) & SVpbm_CASEFOLD)
323 #define SvCASEFOLD_on(sv) (SvPRIVATE(sv) |= SVpbm_CASEFOLD)
324 #define SvCASEFOLD_off(sv) (SvPRIVATE(sv) &= ~SVpbm_CASEFOLD)
326 #define SvVALID(sv) (SvPRIVATE(sv) & SVpbm_VALID)
327 #define SvVALID_on(sv) (SvPRIVATE(sv) |= SVpbm_VALID)
328 #define SvVALID_off(sv) (SvPRIVATE(sv) &= ~SVpbm_VALID)
330 #define SvMULTI(sv) (SvPRIVATE(sv) & SVpgv_MULTI)
331 #define SvMULTI_on(sv) (SvPRIVATE(sv) |= SVpgv_MULTI)
332 #define SvMULTI_off(sv) (SvPRIVATE(sv) &= ~SVpgv_MULTI)
334 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
335 #define SvRVx(sv) SvRV(sv)
337 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
338 #define SvIVXx(sv) SvIVX(sv)
339 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
340 #define SvNVXx(sv) SvNVX(sv)
341 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
342 #define SvPVXx(sv) SvPVX(sv)
343 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
344 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
345 #define SvLENx(sv) SvLEN(sv)
346 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
347 #define SvENDx(sv) ((Sv = sv), SvEND(Sv))
348 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
349 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
351 #define SvIV_set(sv, val) \
352 do { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
353 (((XPVIV*) SvANY(sv))->xiv_iv = val); } while (0)
354 #define SvNV_set(sv, val) \
355 do { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
356 (((XPVNV*) SvANY(sv))->xnv_nv = val); } while (0)
357 #define SvPV_set(sv, val) \
358 do { assert(SvTYPE(sv) >= SVt_PV); \
359 (((XPV*) SvANY(sv))->xpv_pv = val); } while (0)
360 #define SvCUR_set(sv, val) \
361 do { assert(SvTYPE(sv) >= SVt_PV); \
362 (((XPV*) SvANY(sv))->xpv_cur = val); } while (0)
363 #define SvLEN_set(sv, val) \
364 do { assert(SvTYPE(sv) >= SVt_PV); \
365 (((XPV*) SvANY(sv))->xpv_len = val); } while (0)
366 #define SvEND_set(sv, val) \
367 do { assert(SvTYPE(sv) >= SVt_PV); \
368 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } while (0)
370 #define SvCUROK(sv) (SvPOK(sv) ? SvCUR(sv) : 0)
372 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
373 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
374 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
376 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
378 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
379 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
380 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
381 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
383 #define SvTAINT(sv) if (tainting && tainted) sv_magic(sv, 0, 't', 0, 0)
389 #define SvPV(sv, lp) sv_pvn(sv, &lp)
393 #define SvIVx(sv) SvIV(sv)
394 #define SvNVx(sv) SvNV(sv)
395 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
396 #define SvTRUEx(sv) SvTRUE(sv)
398 #else /* !CRIPPLED_CC */
400 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
402 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
404 #define SvPV(sv, lp) (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
406 #define SvTRUE(sv) ( \
408 ? ((Xpv = (XPV*)SvANY(sv)) && \
409 (*Xpv->xpv_pv > '0' || \
410 Xpv->xpv_cur > 1 || \
411 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
421 #define SvIVx(sv) ((Sv = sv), SvIV(Sv))
422 #define SvNVx(sv) ((Sv = sv), SvNV(Sv))
423 #define SvPVx(sv, lp) ((Sv = sv), SvPV(Sv, lp))
424 #define SvTRUEx(sv) ((Sv = sv), SvTRUE(Sv))
426 #endif /* CRIPPLED_CC */
428 /* the following macro updates any magic values this sv is associated with */
430 #define SvSETMAGIC(x) if (SvMAGICAL(x)) mg_set(x)
432 #define SvSetSV(dst,src) if (dst != src) sv_setsv(dst,src)
434 #define SvPEEK(sv) sv_peek(sv)
436 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
438 #define GROWSTR(pp,lp,len) if (*(lp) < (len)) pv_grow(pp, lp, (len) * 3 / 2)
441 # define SvGROW(sv,len) if (SvLEN(sv) < (len)) sv_grow(sv,len)
442 # define Sv_Grow sv_grow
444 /* extra parentheses intentionally NOT placed around "len"! */
445 # define SvGROW(sv,len) if (SvLEN(sv) < (unsigned long)len) \
446 sv_grow(sv,(unsigned long)len)
447 # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))