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 SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
161 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
163 #define SVpbm_VALID 0x80000000
164 #define SVpbm_TAIL 0x40000000
166 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
168 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
169 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
171 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
174 SV * xrv_rv; /* pointer to another SV */
178 char * xpv_pv; /* pointer to malloced string */
179 STRLEN xpv_cur; /* length of xpv_pv as a C string */
180 STRLEN xpv_len; /* allocated size */
184 char * xpv_pv; /* pointer to malloced string */
185 STRLEN xpv_cur; /* length of xpv_pv as a C string */
186 STRLEN xpv_len; /* allocated size */
187 IV xiv_iv; /* integer value or pv offset */
191 char * xpv_pv; /* pointer to malloced string */
192 STRLEN xpv_cur; /* length of xpv_pv as a C string */
193 STRLEN xpv_len; /* allocated size */
194 UV xuv_uv; /* unsigned value or pv offset */
198 char * xpv_pv; /* pointer to malloced string */
199 STRLEN xpv_cur; /* length of xpv_pv as a C string */
200 STRLEN xpv_len; /* allocated size */
201 IV xiv_iv; /* integer value or pv offset */
202 NV xnv_nv; /* numeric value, if any */
205 /* These structure must match the beginning of struct xpvhv in hv.h. */
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 IV xiv_iv; /* integer value or pv offset */
211 NV xnv_nv; /* numeric value, if any */
212 MAGIC* xmg_magic; /* linked list of magicalness */
213 HV* xmg_stash; /* class package */
217 char * xpv_pv; /* pointer to malloced string */
218 STRLEN xpv_cur; /* length of xpv_pv as a C string */
219 STRLEN xpv_len; /* allocated size */
220 IV xiv_iv; /* integer value or pv offset */
221 NV xnv_nv; /* numeric value, if any */
222 MAGIC* xmg_magic; /* linked list of magicalness */
223 HV* xmg_stash; /* class package */
232 char * xpv_pv; /* pointer to malloced string */
233 STRLEN xpv_cur; /* length of xpv_pv as a C string */
234 STRLEN xpv_len; /* allocated size */
235 IV xiv_iv; /* integer value or pv offset */
236 NV xnv_nv; /* numeric value, if any */
237 MAGIC* xmg_magic; /* linked list of magicalness */
238 HV* xmg_stash; /* class package */
248 char * xpv_pv; /* pointer to malloced string */
249 STRLEN xpv_cur; /* length of xpv_pv as a C string */
250 STRLEN xpv_len; /* allocated size */
251 IV xiv_iv; /* integer value or pv offset */
252 NV xnv_nv; /* numeric value, if any */
253 MAGIC* xmg_magic; /* linked list of magicalness */
254 HV* xmg_stash; /* class package */
256 I32 xbm_useful; /* is this constant pattern being useful? */
257 U16 xbm_previous; /* how many characters in string before rare? */
258 U8 xbm_rare; /* rarest character in string */
261 /* This structure much match XPVCV */
263 typedef U16 cv_flags_t;
266 char * xpv_pv; /* pointer to malloced string */
267 STRLEN xpv_cur; /* length of xpv_pv as a C string */
268 STRLEN xpv_len; /* allocated size */
269 IV xiv_iv; /* integer value or pv offset */
270 NV xnv_nv; /* numeric value, if any */
271 MAGIC* xmg_magic; /* linked list of magicalness */
272 HV* xmg_stash; /* class package */
277 void (*xcv_xsub)(pTHXo_ CV*);
281 long xcv_depth; /* >= 2 indicates recursive call */
285 perl_mutex *xcv_mutexp; /* protects xcv_owner */
286 struct perl_thread *xcv_owner; /* current owner thread */
287 #endif /* USE_THREADS */
288 cv_flags_t xcv_flags;
294 char * xpv_pv; /* pointer to malloced string */
295 STRLEN xpv_cur; /* length of xpv_pv as a C string */
296 STRLEN xpv_len; /* allocated size */
297 IV xiv_iv; /* integer value or pv offset */
298 NV xnv_nv; /* numeric value, if any */
299 MAGIC* xmg_magic; /* linked list of magicalness */
300 HV* xmg_stash; /* class package */
302 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
303 PerlIO * xio_ofp; /* but sockets need separate streams */
304 DIR * xio_dirp; /* for opendir, readdir, etc */
305 long xio_lines; /* $. */
306 long xio_page; /* $% */
307 long xio_page_len; /* $= */
308 long xio_lines_left; /* $- */
309 char * xio_top_name; /* $^ */
310 GV * xio_top_gv; /* $^ */
311 char * xio_fmt_name; /* $~ */
312 GV * xio_fmt_gv; /* $~ */
313 char * xio_bottom_name;/* $^B */
314 GV * xio_bottom_gv; /* $^B */
315 short xio_subprocess; /* -| or |- */
320 #define IOf_ARGV 1 /* this fp iterates over ARGV */
321 #define IOf_START 2 /* check for null ARGV and substitute '-' */
322 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
323 #define IOf_DIDTOP 8 /* just did top of form */
324 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
325 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
327 /* The following macros define implementation-independent predicates on SVs. */
329 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
330 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
331 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
332 SVp_IOK|SVp_NOK|SVf_IVisUV))
334 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
335 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
338 #define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
341 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
342 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
343 #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
344 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
345 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
346 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
347 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
349 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
350 #define SvIOK_on(sv) (SvOOK_off(sv), \
351 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
352 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
353 #define SvIOK_only(sv) (SvOK_off(sv), \
354 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
355 #define SvIOK_only_UV(sv) (SvOK_off_exc_UV(sv), \
356 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
358 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
359 == (SVf_IOK|SVf_IVisUV))
360 #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
363 #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
364 #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
365 #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
367 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
368 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
369 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
370 #define SvNOK_only(sv) (SvOK_off(sv), \
371 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
373 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_ISUTF8)
374 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_ISUTF8))
375 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_ISUTF8))
377 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
378 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
379 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
380 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|SVf_IVisUV), \
381 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
383 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
384 #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
385 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
387 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
388 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
389 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
391 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
392 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
393 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
395 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
396 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
397 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
399 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
400 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
401 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
403 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
404 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
405 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
407 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
408 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
409 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
411 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
412 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
413 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
416 #define Gv_AMG(stash) \
417 (HV_AMAGICmb(stash) && \
418 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
420 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
422 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
423 == (SVf_ROK|SVprv_WEAKREF))
424 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
425 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
427 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
429 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
431 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
432 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
433 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
435 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
436 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
438 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
439 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
440 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
442 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
443 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
444 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
446 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
447 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
448 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
450 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
451 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
452 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
454 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
455 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
456 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
458 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
459 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
460 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
462 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
463 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
464 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
466 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
467 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
468 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
470 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
471 #define SvRVx(sv) SvRV(sv)
473 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
474 #define SvIVXx(sv) SvIVX(sv)
475 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
476 #define SvUVXx(sv) SvUVX(sv)
477 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
478 #define SvNVXx(sv) SvNVX(sv)
479 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
480 #define SvPVXx(sv) SvPVX(sv)
481 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
482 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
483 #define SvLENx(sv) SvLEN(sv)
484 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
485 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
486 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
487 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
489 #define SvIV_set(sv, val) \
490 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
491 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
492 #define SvNV_set(sv, val) \
493 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
494 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
495 #define SvPV_set(sv, val) \
496 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
497 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
498 #define SvCUR_set(sv, val) \
499 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
500 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
501 #define SvLEN_set(sv, val) \
502 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
503 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
504 #define SvEND_set(sv, val) \
505 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
506 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
508 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
509 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
510 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
512 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
514 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
515 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
516 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
517 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
519 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
520 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
521 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
522 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
523 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
524 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
525 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
526 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
527 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
528 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
529 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
530 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
531 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
532 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
533 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
534 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
536 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
537 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
538 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
540 #define SvTAINT(sv) \
549 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
550 #define SvPV(sv, lp) sv_pvn(sv, &lp)
551 #define SvPV_nolen(sv) sv_pv(sv)
553 #define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
554 #define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
555 #define SvPVutf8_nolen(sv) sv_pvutf8(sv)
557 #define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
558 #define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
559 #define SvPVbyte_nolen(sv) sv_pvbyte(sv)
561 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
562 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
563 #define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
564 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
565 #define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
566 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
568 #define SvIVx(sv) sv_iv(sv)
569 #define SvUVx(sv) sv_uv(sv)
570 #define SvNVx(sv) sv_nv(sv)
572 #define SvTRUEx(sv) sv_true(sv)
574 #define SvIV(sv) SvIVx(sv)
575 #define SvNV(sv) SvNVx(sv)
576 #define SvUV(sv) SvUVx(sv)
577 #define SvTRUE(sv) SvTRUEx(sv)
580 /* redefine some things to more efficient inlined versions */
582 /* Let us hope that bitmaps for UV and IV are the same */
584 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
587 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
590 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
593 #define SvPV(sv, lp) \
594 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
595 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
599 #define SvPV_force(sv, lp) \
600 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
601 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
604 #define SvPV_nolen(sv) \
605 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
606 ? SvPVX(sv) : sv_2pv_nolen(sv))
609 #define SvPVutf8(sv, lp) \
610 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
611 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
613 #undef SvPVutf8_force
614 #define SvPVutf8_force(sv, lp) \
615 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK||SVf_UTF8) \
616 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
618 #undef SvPVutf8_nolen
619 #define SvPVutf8_nolen(sv) \
620 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK||SVf_UTF8)\
621 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
624 #define SvPVutf8(sv, lp) \
625 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
626 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
628 #undef SvPVutf8_force
629 #define SvPVutf8_force(sv, lp) \
630 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK||SVf_UTF8) \
631 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
633 #undef SvPVutf8_nolen
634 #define SvPVutf8_nolen(sv) \
635 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
636 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
639 #define SvPVbyte(sv, lp) \
640 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
641 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
643 #undef SvPVbyte_force
644 #define SvPVbyte_force(sv, lp) \
645 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
646 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
648 #undef SvPVbyte_nolen
649 #define SvPVbyte_nolen(sv) \
650 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
651 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
663 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
664 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
665 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
666 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
667 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
668 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
669 # define SvTRUE(sv) ( \
673 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
675 (*nxpv->xpv_pv > '0' || \
676 nxpv->xpv_cur > 1 || \
677 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
686 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
689 /* These inlined macros use globals, which will require a thread
690 * declaration in user code, so we avoid them under threads */
700 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
701 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
702 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
703 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
704 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
705 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
706 # define SvTRUE(sv) ( \
710 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
711 (*PL_Xpv->xpv_pv > '0' || \
712 PL_Xpv->xpv_cur > 1 || \
713 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
722 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
723 #endif /* !USE_THREADS */
724 #endif /* !__GNU__ */
725 #endif /* !CRIPPLED_CC */
727 #define newRV_inc(sv) newRV(sv)
729 /* the following macros update any magic values this sv is associated with */
731 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
732 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
734 #define SvSetSV_and(dst,src,finally) \
736 if ((dst) != (src)) { \
737 sv_setsv(dst, src); \
741 #define SvSetSV_nosteal_and(dst,src,finally) \
743 if ((dst) != (src)) { \
744 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
746 sv_setsv(dst, src); \
747 SvFLAGS(src) |= tMpF; \
752 #define SvSetSV(dst,src) \
753 SvSetSV_and(dst,src,/*nothing*/;)
754 #define SvSetSV_nosteal(dst,src) \
755 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
757 #define SvSetMagicSV(dst,src) \
758 SvSetSV_and(dst,src,SvSETMAGIC(dst))
759 #define SvSetMagicSV_nosteal(dst,src) \
760 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
763 #define SvPEEK(sv) sv_peek(sv)
765 #define SvPEEK(sv) ""
768 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
770 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
772 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
774 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
775 #define Sv_Grow sv_grow