3 * Copyright (c) 1991-1997, 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 */
140 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK)
142 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
143 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
144 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
145 #define SVp_SCREAM 0x08000000 /* has been studied? */
147 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
148 SVp_IOK|SVp_NOK|SVp_POK)
150 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
154 /* Some private flags. */
156 #define SVpfm_COMPILED 0x80000000
158 #define SVpbm_VALID 0x80000000
159 #define SVpbm_TAIL 0x40000000
161 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
162 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
165 SV * xrv_rv; /* pointer to another SV */
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 */
175 char * xpv_pv; /* pointer to malloced string */
176 STRLEN xpv_cur; /* length of xpv_pv as a C string */
177 STRLEN xpv_len; /* allocated size */
178 IV xiv_iv; /* integer value or pv offset */
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 */
185 UV xuv_uv; /* unsigned value or pv offset */
189 char * xpv_pv; /* pointer to malloced string */
190 STRLEN xpv_cur; /* length of xpv_pv as a C string */
191 STRLEN xpv_len; /* allocated size */
192 IV xiv_iv; /* integer value or pv offset */
193 double xnv_nv; /* numeric value, if any */
196 /* These structure must match the beginning of struct xpvhv in hv.h. */
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 double xnv_nv; /* numeric value, if any */
203 MAGIC* xmg_magic; /* linked list of magicalness */
204 HV* xmg_stash; /* class package */
208 char * xpv_pv; /* pointer to malloced string */
209 STRLEN xpv_cur; /* length of xpv_pv as a C string */
210 STRLEN xpv_len; /* allocated size */
211 IV xiv_iv; /* integer value or pv offset */
212 double xnv_nv; /* numeric value, if any */
213 MAGIC* xmg_magic; /* linked list of magicalness */
214 HV* xmg_stash; /* class package */
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 */
239 char * xpv_pv; /* pointer to malloced string */
240 STRLEN xpv_cur; /* length of xpv_pv as a C string */
241 STRLEN xpv_len; /* allocated size */
242 IV xiv_iv; /* integer value or pv offset */
243 double xnv_nv; /* numeric value, if any */
244 MAGIC* xmg_magic; /* linked list of magicalness */
245 HV* xmg_stash; /* class package */
247 I32 xbm_useful; /* is this constant pattern being useful? */
248 U16 xbm_previous; /* how many characters in string before rare? */
249 U8 xbm_rare; /* rarest character in string */
252 /* This structure much match XPVCV */
254 typedef U16 cv_flags_t;
257 char * xpv_pv; /* pointer to malloced string */
258 STRLEN xpv_cur; /* length of xpv_pv as a C string */
259 STRLEN xpv_len; /* allocated size */
260 IV xiv_iv; /* integer value or pv offset */
261 double xnv_nv; /* numeric value, if any */
262 MAGIC* xmg_magic; /* linked list of magicalness */
263 HV* xmg_stash; /* class package */
268 void (*xcv_xsub)_((CV* _CPERLproto));
272 long xcv_depth; /* >= 2 indicates recursive call */
276 perl_mutex *xcv_mutexp; /* protects xcv_owner */
277 struct perl_thread *xcv_owner; /* current owner thread */
278 #endif /* USE_THREADS */
279 cv_flags_t xcv_flags;
285 char * xpv_pv; /* pointer to malloced string */
286 STRLEN xpv_cur; /* length of xpv_pv as a C string */
287 STRLEN xpv_len; /* allocated size */
288 IV xiv_iv; /* integer value or pv offset */
289 double xnv_nv; /* numeric value, if any */
290 MAGIC* xmg_magic; /* linked list of magicalness */
291 HV* xmg_stash; /* class package */
293 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
294 PerlIO * xio_ofp; /* but sockets need separate streams */
295 DIR * xio_dirp; /* for opendir, readdir, etc */
296 long xio_lines; /* $. */
297 long xio_page; /* $% */
298 long xio_page_len; /* $= */
299 long xio_lines_left; /* $- */
300 char * xio_top_name; /* $^ */
301 GV * xio_top_gv; /* $^ */
302 char * xio_fmt_name; /* $~ */
303 GV * xio_fmt_gv; /* $~ */
304 char * xio_bottom_name;/* $^B */
305 GV * xio_bottom_gv; /* $^B */
306 short xio_subprocess; /* -| or |- */
311 #define IOf_ARGV 1 /* this fp iterates over ARGV */
312 #define IOf_START 2 /* check for null ARGV and substitute '-' */
313 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
314 #define IOf_DIDTOP 8 /* just did top of form */
315 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
316 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
318 /* The following macros define implementation-independent predicates on SVs. */
320 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
321 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
322 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
325 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
326 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
329 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
330 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
331 #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
332 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
333 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
334 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
335 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
337 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
338 #define SvIOK_on(sv) (SvOOK_off(sv), \
339 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
340 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
341 #define SvIOK_only(sv) (SvOK_off(sv), \
342 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
344 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
345 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
346 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
347 #define SvNOK_only(sv) (SvOK_off(sv), \
348 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
350 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
351 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
352 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
353 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
354 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
356 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
357 #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
358 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
360 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
361 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
362 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
364 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
365 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
366 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
368 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
369 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
370 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
372 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
373 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
374 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
376 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
377 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
378 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
380 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
381 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
382 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
384 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
385 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
386 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
389 #define Gv_AMG(stash) \
390 (HV_AMAGICmb(stash) && \
391 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
393 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
395 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
397 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
399 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
400 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
401 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
403 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
404 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
406 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
407 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
408 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
410 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
411 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
412 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
414 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
415 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
416 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
418 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
419 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
420 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
422 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
423 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
424 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
426 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
427 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
428 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
430 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
431 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
432 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
434 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
435 #define SvRVx(sv) SvRV(sv)
437 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
438 #define SvIVXx(sv) SvIVX(sv)
439 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
440 #define SvUVXx(sv) SvUVX(sv)
441 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
442 #define SvNVXx(sv) SvNVX(sv)
443 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
444 #define SvPVXx(sv) SvPVX(sv)
445 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
446 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
447 #define SvLENx(sv) SvLEN(sv)
448 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
449 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
450 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
451 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
453 #define SvIV_set(sv, val) \
454 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
455 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
456 #define SvNV_set(sv, val) \
457 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
458 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
459 #define SvPV_set(sv, val) \
460 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
461 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
462 #define SvCUR_set(sv, val) \
463 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
464 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
465 #define SvLEN_set(sv, val) \
466 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
467 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
468 #define SvEND_set(sv, val) \
469 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
470 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
472 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
473 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
474 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
476 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
478 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
479 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
480 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
481 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
483 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
484 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
485 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
486 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
487 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
488 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
489 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
490 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
491 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
492 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
493 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
494 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
495 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
496 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
497 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
498 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
500 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
501 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
502 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
504 #define SvTAINT(sv) \
513 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
514 #define SvPV(sv, lp) sv_pvn(sv, &lp)
515 #define SvPV_nolen(sv) sv_pv(sv)
516 #define SvIVx(sv) sv_iv(sv)
517 #define SvUVx(sv) sv_uv(sv)
518 #define SvNVx(sv) sv_nv(sv)
519 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
520 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
521 #define SvTRUEx(sv) sv_true(sv)
523 #define SvIV(sv) SvIVx(sv)
524 #define SvNV(sv) SvNVx(sv)
525 #define SvUV(sv) SvIVx(sv)
526 #define SvTRUE(sv) SvTRUEx(sv)
529 /* redefine some things to more efficient inlined versions */
532 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
535 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
538 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
541 #define SvPV(sv, lp) \
542 (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
545 #define SvPV_force(sv, lp) \
546 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
547 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
550 #define SvPV_nolen(sv) \
551 (SvPOK(sv) ? SvPVX(sv) : sv_2pv_nolen(sv))
560 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
561 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
562 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
563 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
564 # define SvTRUE(sv) ( \
568 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
570 (*nxpv->xpv_pv > '0' || \
571 nxpv->xpv_cur > 1 || \
572 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
581 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
584 /* These inlined macros use globals, which will require a thread
585 * declaration in user code, so we avoid them under threads */
593 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
594 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
595 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
596 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
597 # define SvTRUE(sv) ( \
601 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
602 (*PL_Xpv->xpv_pv > '0' || \
603 PL_Xpv->xpv_cur > 1 || \
604 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
613 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
614 #endif /* !USE_THREADS */
615 #endif /* !__GNU__ */
616 #endif /* !CRIPPLED_CC */
618 #define newRV_inc(sv) newRV(sv)
620 /* the following macros update any magic values this sv is associated with */
622 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
623 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
625 #define SvSetSV_and(dst,src,finally) \
627 if ((dst) != (src)) { \
628 sv_setsv(dst, src); \
632 #define SvSetSV_nosteal_and(dst,src,finally) \
634 if ((dst) != (src)) { \
635 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
637 sv_setsv(dst, src); \
638 SvFLAGS(src) |= tMpF; \
643 #define SvSetSV(dst,src) \
644 SvSetSV_and(dst,src,/*nothing*/;)
645 #define SvSetSV_nosteal(dst,src) \
646 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
648 #define SvSetMagicSV(dst,src) \
649 SvSetSV_and(dst,src,SvSETMAGIC(dst))
650 #define SvSetMagicSV_nosteal(dst,src) \
651 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
654 #define SvPEEK(sv) sv_peek(sv)
656 #define SvPEEK(sv) ""
659 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
661 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
663 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
666 # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
667 # define Sv_Grow sv_grow
669 /* extra parentheses intentionally NOT placed around "len"! */
670 # define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
671 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
672 # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))