3 * Copyright (c) 1991-1999, 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.
11 #undef sv_flags /* Convex has this in <signal.h> for sigvec() */
33 /* Using C's structural equivalence to help emulate C++ inheritance here... */
36 void* sv_any; /* pointer to something */
37 U32 sv_refcnt; /* how many references to us */
38 U32 sv_flags; /* what we are */
42 XPVGV* sv_any; /* pointer to something */
43 U32 sv_refcnt; /* how many references to us */
44 U32 sv_flags; /* what we are */
48 XPVCV* sv_any; /* pointer to something */
49 U32 sv_refcnt; /* how many references to us */
50 U32 sv_flags; /* what we are */
54 XPVAV* sv_any; /* pointer to something */
55 U32 sv_refcnt; /* how many references to us */
56 U32 sv_flags; /* what we are */
60 XPVHV* sv_any; /* pointer to something */
61 U32 sv_refcnt; /* how many references to us */
62 U32 sv_flags; /* what we are */
66 XPVIO* sv_any; /* pointer to something */
67 U32 sv_refcnt; /* how many references to us */
68 U32 sv_flags; /* what we are */
71 #define SvANY(sv) (sv)->sv_any
72 #define SvFLAGS(sv) (sv)->sv_flags
73 #define SvREFCNT(sv) (sv)->sv_refcnt
77 # ifdef EMULATE_ATOMIC_REFCOUNTS
78 # define ATOMIC_INC(count) STMT_START { \
79 MUTEX_LOCK(&PL_svref_mutex); \
81 MUTEX_UNLOCK(&PL_svref_mutex); \
83 # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
84 MUTEX_LOCK(&PL_svref_mutex); \
85 res = (--count == 0); \
86 MUTEX_UNLOCK(&PL_svref_mutex); \
89 # define ATOMIC_INC(count) atomic_inc(&count)
90 # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
91 # endif /* EMULATE_ATOMIC_REFCOUNTS */
93 # define ATOMIC_INC(count) (++count)
94 # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
95 #endif /* USE_THREADS */
98 # define SvREFCNT_inc(sv) \
100 SV *nsv = (SV*)(sv); \
102 ATOMIC_INC(SvREFCNT(nsv)); \
106 # if defined(CRIPPLED_CC) || defined(USE_THREADS)
107 # define SvREFCNT_inc(sv) sv_newref((SV*)sv)
109 # define SvREFCNT_inc(sv) \
110 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
114 #define SvREFCNT_dec(sv) sv_free((SV*)sv)
116 #define SVTYPEMASK 0xff
117 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
119 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
121 #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
122 #define SVs_PADTMP 0x00000200 /* in use as tmp */
123 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
124 #define SVs_TEMP 0x00000800 /* string is stealable? */
125 #define SVs_OBJECT 0x00001000 /* is "blessed" */
126 #define SVs_GMG 0x00002000 /* has magical get method */
127 #define SVs_SMG 0x00004000 /* has magical set method */
128 #define SVs_RMG 0x00008000 /* has random magical methods */
130 #define SVf_IOK 0x00010000 /* has valid public integer value */
131 #define SVf_NOK 0x00020000 /* has valid public numeric value */
132 #define SVf_POK 0x00040000 /* has valid public pointer value */
133 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
135 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
136 #define SVf_OOK 0x00200000 /* has valid offset value */
137 #define SVf_BREAK 0x00400000 /* refcnt is artificially low */
138 #define SVf_READONLY 0x00800000 /* may not be modified */
141 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
142 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
143 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
144 #define SVp_SCREAM 0x08000000 /* has been studied? */
146 #define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
148 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE|SVf_UTF8)
150 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
151 SVp_IOK|SVp_NOK|SVp_POK)
153 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
157 /* Some private flags. */
159 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
161 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
163 #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
165 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
167 #define SVpbm_VALID 0x80000000
168 #define SVpbm_TAIL 0x40000000
170 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
172 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
173 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
175 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
178 SV * xrv_rv; /* pointer to another SV */
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 */
188 char * xpv_pv; /* pointer to malloced string */
189 STRLEN xpv_cur; /* length of xpv_pv as a C string */
190 STRLEN xpv_len; /* allocated size */
191 IV xiv_iv; /* integer value or pv offset */
195 char * xpv_pv; /* pointer to malloced string */
196 STRLEN xpv_cur; /* length of xpv_pv as a C string */
197 STRLEN xpv_len; /* allocated size */
198 UV xuv_uv; /* unsigned value or pv offset */
202 char * xpv_pv; /* pointer to malloced string */
203 STRLEN xpv_cur; /* length of xpv_pv as a C string */
204 STRLEN xpv_len; /* allocated size */
205 IV xiv_iv; /* integer value or pv offset */
206 NV xnv_nv; /* numeric value, if any */
209 /* These structure must match the beginning of struct xpvhv in hv.h. */
211 char * xpv_pv; /* pointer to malloced string */
212 STRLEN xpv_cur; /* length of xpv_pv as a C string */
213 STRLEN xpv_len; /* allocated size */
214 IV xiv_iv; /* integer value or pv offset */
215 NV xnv_nv; /* numeric value, if any */
216 MAGIC* xmg_magic; /* linked list of magicalness */
217 HV* xmg_stash; /* class package */
221 char * xpv_pv; /* pointer to malloced string */
222 STRLEN xpv_cur; /* length of xpv_pv as a C string */
223 STRLEN xpv_len; /* allocated size */
224 IV xiv_iv; /* integer value or pv offset */
225 NV xnv_nv; /* numeric value, if any */
226 MAGIC* xmg_magic; /* linked list of magicalness */
227 HV* xmg_stash; /* class package */
236 char * xpv_pv; /* pointer to malloced string */
237 STRLEN xpv_cur; /* length of xpv_pv as a C string */
238 STRLEN xpv_len; /* allocated size */
239 IV xiv_iv; /* integer value or pv offset */
240 NV xnv_nv; /* numeric value, if any */
241 MAGIC* xmg_magic; /* linked list of magicalness */
242 HV* xmg_stash; /* class package */
252 char * xpv_pv; /* pointer to malloced string */
253 STRLEN xpv_cur; /* length of xpv_pv as a C string */
254 STRLEN xpv_len; /* allocated size */
255 IV xiv_iv; /* integer value or pv offset */
256 NV xnv_nv; /* numeric value, if any */
257 MAGIC* xmg_magic; /* linked list of magicalness */
258 HV* xmg_stash; /* class package */
260 I32 xbm_useful; /* is this constant pattern being useful? */
261 U16 xbm_previous; /* how many characters in string before rare? */
262 U8 xbm_rare; /* rarest character in string */
265 /* This structure much match XPVCV in cv.h */
267 typedef U16 cv_flags_t;
270 char * xpv_pv; /* pointer to malloced string */
271 STRLEN xpv_cur; /* length of xpv_pv as a C string */
272 STRLEN xpv_len; /* allocated size */
273 IV xiv_iv; /* integer value or pv offset */
274 NV xnv_nv; /* numeric value, if any */
275 MAGIC* xmg_magic; /* linked list of magicalness */
276 HV* xmg_stash; /* class package */
281 void (*xcv_xsub)(pTHXo_ CV*);
285 long xcv_depth; /* >= 2 indicates recursive call */
289 perl_mutex *xcv_mutexp; /* protects xcv_owner */
290 struct perl_thread *xcv_owner; /* current owner thread */
291 #endif /* USE_THREADS */
292 cv_flags_t xcv_flags;
298 char * xpv_pv; /* pointer to malloced string */
299 STRLEN xpv_cur; /* length of xpv_pv as a C string */
300 STRLEN xpv_len; /* allocated size */
301 IV xiv_iv; /* integer value or pv offset */
302 NV xnv_nv; /* numeric value, if any */
303 MAGIC* xmg_magic; /* linked list of magicalness */
304 HV* xmg_stash; /* class package */
306 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
307 PerlIO * xio_ofp; /* but sockets need separate streams */
308 DIR * xio_dirp; /* for opendir, readdir, etc */
309 long xio_lines; /* $. */
310 long xio_page; /* $% */
311 long xio_page_len; /* $= */
312 long xio_lines_left; /* $- */
313 char * xio_top_name; /* $^ */
314 GV * xio_top_gv; /* $^ */
315 char * xio_fmt_name; /* $~ */
316 GV * xio_fmt_gv; /* $~ */
317 char * xio_bottom_name;/* $^B */
318 GV * xio_bottom_gv; /* $^B */
319 short xio_subprocess; /* -| or |- */
324 #define IOf_ARGV 1 /* this fp iterates over ARGV */
325 #define IOf_START 2 /* check for null ARGV and substitute '-' */
326 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
327 #define IOf_DIDTOP 8 /* just did top of form */
328 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
329 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
330 #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
332 /* The following macros define implementation-independent predicates on SVs. */
334 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
335 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
336 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
337 SVp_IOK|SVp_NOK|SVf_IVisUV))
339 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
340 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
343 #define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
346 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
347 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
348 #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
349 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
350 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
351 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
352 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
354 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
355 #define SvIOK_on(sv) (SvOOK_off(sv), \
356 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
357 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
358 #define SvIOK_only(sv) (SvOK_off(sv), \
359 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
360 #define SvIOK_only_UV(sv) (SvOK_off_exc_UV(sv), \
361 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
363 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
364 == (SVf_IOK|SVf_IVisUV))
365 #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
368 #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
369 #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
370 #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
372 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
373 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
374 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
375 #define SvNOK_only(sv) (SvOK_off(sv), \
376 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
378 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
379 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
380 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
382 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
383 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
384 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
385 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|SVf_IVisUV), \
386 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
388 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
389 #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
390 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
392 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
393 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
394 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
396 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
397 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
398 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
400 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
401 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
402 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
404 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
405 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
406 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
408 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
409 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
410 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
412 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
413 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
414 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
416 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
417 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
418 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
421 #define Gv_AMG(stash) \
422 (HV_AMAGICmb(stash) && \
423 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
425 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
427 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
428 == (SVf_ROK|SVprv_WEAKREF))
429 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
430 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
432 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
434 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
436 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
437 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
438 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
440 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
441 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
443 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
444 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
445 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
447 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
448 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
449 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
451 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
452 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
453 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
455 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
456 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
457 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
459 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
460 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
461 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
463 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
464 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
465 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
467 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
468 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
469 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
471 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
472 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
473 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
475 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
476 #define SvRVx(sv) SvRV(sv)
478 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
479 #define SvIVXx(sv) SvIVX(sv)
480 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
481 #define SvUVXx(sv) SvUVX(sv)
482 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
483 #define SvNVXx(sv) SvNVX(sv)
484 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
485 #define SvPVXx(sv) SvPVX(sv)
486 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
487 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
488 #define SvLENx(sv) SvLEN(sv)
489 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
490 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
491 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
492 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
494 #define SvIV_set(sv, val) \
495 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
496 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
497 #define SvNV_set(sv, val) \
498 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
499 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
500 #define SvPV_set(sv, val) \
501 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
502 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
503 #define SvCUR_set(sv, val) \
504 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
505 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
506 #define SvLEN_set(sv, val) \
507 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
508 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
509 #define SvEND_set(sv, val) \
510 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
511 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
513 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
514 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
515 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
517 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
519 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
520 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
521 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
522 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
524 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
525 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
526 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
527 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
528 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
529 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
530 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
531 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
532 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
533 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
534 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
535 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
536 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
537 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
538 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
539 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
541 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
542 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
543 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
545 #define SvTAINT(sv) \
554 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
555 #define SvPV(sv, lp) sv_pvn(sv, &lp)
556 #define SvPV_nolen(sv) sv_pv(sv)
558 #define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
559 #define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
560 #define SvPVutf8_nolen(sv) sv_pvutf8(sv)
562 #define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
563 #define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
564 #define SvPVbyte_nolen(sv) sv_pvbyte(sv)
566 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
567 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
568 #define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
569 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
570 #define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
571 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
573 #define SvIVx(sv) sv_iv(sv)
574 #define SvUVx(sv) sv_uv(sv)
575 #define SvNVx(sv) sv_nv(sv)
577 #define SvTRUEx(sv) sv_true(sv)
579 #define SvIV(sv) SvIVx(sv)
580 #define SvNV(sv) SvNVx(sv)
581 #define SvUV(sv) SvUVx(sv)
582 #define SvTRUE(sv) SvTRUEx(sv)
585 /* redefine some things to more efficient inlined versions */
587 /* Let us hope that bitmaps for UV and IV are the same */
589 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
592 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
595 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
598 #define SvPV(sv, lp) \
599 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
600 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
604 #define SvPV_force(sv, lp) \
605 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
606 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
609 #define SvPV_nolen(sv) \
610 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
611 ? SvPVX(sv) : sv_2pv_nolen(sv))
614 #define SvPVutf8(sv, lp) \
615 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
616 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
618 #undef SvPVutf8_force
619 #define SvPVutf8_force(sv, lp) \
620 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
621 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
623 #undef SvPVutf8_nolen
624 #define SvPVutf8_nolen(sv) \
625 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
626 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
629 #define SvPVutf8(sv, lp) \
630 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
631 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
633 #undef SvPVutf8_force
634 #define SvPVutf8_force(sv, lp) \
635 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
636 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
638 #undef SvPVutf8_nolen
639 #define SvPVutf8_nolen(sv) \
640 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
641 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
644 #define SvPVbyte(sv, lp) \
645 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
646 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
648 #undef SvPVbyte_force
649 #define SvPVbyte_force(sv, lp) \
650 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
651 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
653 #undef SvPVbyte_nolen
654 #define SvPVbyte_nolen(sv) \
655 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
656 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
668 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
669 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
670 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
671 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
672 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
673 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
674 # define SvTRUE(sv) ( \
678 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
680 (*nxpv->xpv_pv > '0' || \
681 nxpv->xpv_cur > 1 || \
682 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
691 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
694 /* These inlined macros use globals, which will require a thread
695 * declaration in user code, so we avoid them under threads */
705 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
706 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
707 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
708 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
709 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
710 # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
711 # define SvTRUE(sv) ( \
715 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
716 (*PL_Xpv->xpv_pv > '0' || \
717 PL_Xpv->xpv_cur > 1 || \
718 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
727 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
728 #endif /* !USE_THREADS */
729 #endif /* !__GNU__ */
730 #endif /* !CRIPPLED_CC */
732 #define newRV_inc(sv) newRV(sv)
734 /* the following macros update any magic values this sv is associated with */
736 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
737 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
739 #define SvSetSV_and(dst,src,finally) \
741 if ((dst) != (src)) { \
742 sv_setsv(dst, src); \
746 #define SvSetSV_nosteal_and(dst,src,finally) \
748 if ((dst) != (src)) { \
749 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
751 sv_setsv(dst, src); \
752 SvFLAGS(src) |= tMpF; \
757 #define SvSetSV(dst,src) \
758 SvSetSV_and(dst,src,/*nothing*/;)
759 #define SvSetSV_nosteal(dst,src) \
760 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
762 #define SvSetMagicSV(dst,src) \
763 SvSetSV_and(dst,src,SvSETMAGIC(dst))
764 #define SvSetMagicSV_nosteal(dst,src) \
765 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
768 #define SvPEEK(sv) sv_peek(sv)
770 #define SvPEEK(sv) ""
773 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
775 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
777 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
779 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
780 #define Sv_Grow sv_grow