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
76 # define SvREFCNT_inc(sv) ({SV* nsv=(SV*)(sv); if(nsv) ++SvREFCNT(nsv); nsv;})
78 # if defined(CRIPPLED_CC) || defined(USE_THREADS)
79 # define SvREFCNT_inc(sv) sv_newref((SV*)sv)
81 # define SvREFCNT_inc(sv) ((Sv=(SV*)(sv)), (Sv && ++SvREFCNT(Sv)), (SV*)Sv)
85 #define SvREFCNT_dec(sv) sv_free((SV*)sv)
87 #define SVTYPEMASK 0xff
88 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
90 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
92 #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
93 #define SVs_PADTMP 0x00000200 /* in use as tmp */
94 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
95 #define SVs_TEMP 0x00000800 /* string is stealable? */
96 #define SVs_OBJECT 0x00001000 /* is "blessed" */
97 #define SVs_GMG 0x00002000 /* has magical get method */
98 #define SVs_SMG 0x00004000 /* has magical set method */
99 #define SVs_RMG 0x00008000 /* has random magical methods */
101 #define SVf_IOK 0x00010000 /* has valid public integer value */
102 #define SVf_NOK 0x00020000 /* has valid public numeric value */
103 #define SVf_POK 0x00040000 /* has valid public pointer value */
104 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
106 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
107 #define SVf_OOK 0x00200000 /* has valid offset value */
108 #define SVf_BREAK 0x00400000 /* refcnt is artificially low */
109 #define SVf_READONLY 0x00800000 /* may not be modified */
111 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK)
113 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
114 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
115 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
116 #define SVp_SCREAM 0x08000000 /* has been studied? */
118 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
119 SVp_IOK|SVp_NOK|SVp_POK)
122 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
123 #endif /* OVERLOAD */
127 /* Some private flags. */
129 #define SVpfm_COMPILED 0x80000000
131 #define SVpbm_VALID 0x80000000
132 #define SVpbm_TAIL 0x40000000
134 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
135 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
138 SV * xrv_rv; /* pointer to another SV */
142 char * xpv_pv; /* pointer to malloced string */
143 STRLEN xpv_cur; /* length of xpv_pv as a C string */
144 STRLEN xpv_len; /* allocated size */
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 IV xiv_iv; /* integer value or pv offset */
155 char * xpv_pv; /* pointer to malloced string */
156 STRLEN xpv_cur; /* length of xpv_pv as a C string */
157 STRLEN xpv_len; /* allocated size */
158 UV xuv_uv; /* unsigned value or pv offset */
162 char * xpv_pv; /* pointer to malloced string */
163 STRLEN xpv_cur; /* length of xpv_pv as a C string */
164 STRLEN xpv_len; /* allocated size */
165 IV xiv_iv; /* integer value or pv offset */
166 double xnv_nv; /* numeric value, if any */
170 char * xpv_pv; /* pointer to malloced string */
171 STRLEN xpv_cur; /* length of xpv_pv as a C string */
172 STRLEN xpv_len; /* allocated size */
173 IV xiv_iv; /* integer value or pv offset */
174 double xnv_nv; /* numeric value, if any */
175 MAGIC* xmg_magic; /* linked list of magicalness */
176 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 IV 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 */
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 IV xiv_iv; /* integer value or pv offset */
199 double xnv_nv; /* numeric value, if any */
200 MAGIC* xmg_magic; /* linked list of magicalness */
201 HV* xmg_stash; /* class package */
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 double xnv_nv; /* numeric value, if any */
216 MAGIC* xmg_magic; /* linked list of magicalness */
217 HV* xmg_stash; /* class package */
219 I32 xbm_useful; /* is this constant pattern being useful? */
220 U16 xbm_previous; /* how many characters in string before rare? */
221 U8 xbm_rare; /* rarest character in string */
224 /* This structure much match XPVCV */
226 typedef U16 cv_flags_t;
229 char * xpv_pv; /* pointer to malloced string */
230 STRLEN xpv_cur; /* length of xpv_pv as a C string */
231 STRLEN xpv_len; /* allocated size */
232 IV xiv_iv; /* integer value or pv offset */
233 double xnv_nv; /* numeric value, if any */
234 MAGIC* xmg_magic; /* linked list of magicalness */
235 HV* xmg_stash; /* class package */
240 void (*xcv_xsub)_((CV*));
244 long xcv_depth; /* >= 2 indicates recursive call */
248 perl_mutex *xcv_mutexp; /* protects xcv_owner */
249 struct perl_thread *xcv_owner; /* current owner thread */
250 #endif /* USE_THREADS */
251 cv_flags_t xcv_flags;
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 */
265 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
266 PerlIO * xio_ofp; /* but sockets need separate streams */
267 DIR * xio_dirp; /* for opendir, readdir, etc */
268 long xio_lines; /* $. */
269 long xio_page; /* $% */
270 long xio_page_len; /* $= */
271 long xio_lines_left; /* $- */
272 char * xio_top_name; /* $^ */
273 GV * xio_top_gv; /* $^ */
274 char * xio_fmt_name; /* $~ */
275 GV * xio_fmt_gv; /* $~ */
276 char * xio_bottom_name;/* $^B */
277 GV * xio_bottom_gv; /* $^B */
278 short xio_subprocess; /* -| or |- */
283 #define IOf_ARGV 1 /* this fp iterates over ARGV */
284 #define IOf_START 2 /* check for null ARGV and substitute '-' */
285 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
286 #define IOf_DIDTOP 8 /* just did top of form */
287 #define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */
289 /* The following macros define implementation-independent predicates on SVs. */
291 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
292 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
293 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
296 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
299 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
302 #define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv))
303 #endif /* OVERLOAD */
305 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
306 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
307 #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
308 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
309 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
310 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
311 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
313 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
314 #define SvIOK_on(sv) (SvOOK_off(sv), \
315 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
316 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK))
317 #define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \
318 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
320 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
321 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
322 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
323 #define SvNOK_only(sv) (SvOK_off(sv), \
324 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
326 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
327 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
328 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
331 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \
332 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
334 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \
335 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
336 #endif /* OVERLOAD */
338 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
339 #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
340 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
342 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
343 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
344 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
346 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
347 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
350 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
352 #define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK)
353 #endif /* OVERLOAD */
355 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
356 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
357 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
359 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
360 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
361 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
363 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
364 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
365 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
367 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
368 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
369 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
372 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
373 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
374 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
377 #define Gv_AMG(stash) \
378 (HV_AMAGICmb(stash) && \
379 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
381 #define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash))
382 #endif /* OVERLOAD */
384 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
386 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
388 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
389 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
390 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
392 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
393 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
395 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
396 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
397 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
399 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
400 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
401 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
403 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
404 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
405 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
407 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
408 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
409 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
411 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
412 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
413 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
415 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
416 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
417 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
419 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
420 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
421 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
423 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
424 #define SvRVx(sv) SvRV(sv)
426 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
427 #define SvIVXx(sv) SvIVX(sv)
428 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
429 #define SvUVXx(sv) SvUVX(sv)
430 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
431 #define SvNVXx(sv) SvNVX(sv)
432 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
433 #define SvPVXx(sv) SvPVX(sv)
434 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
435 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
436 #define SvLENx(sv) SvLEN(sv)
437 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
438 #define SvENDx(sv) ((Sv = (sv)), SvEND(Sv))
439 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
440 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
442 #define SvIV_set(sv, val) \
443 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
444 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
445 #define SvNV_set(sv, val) \
446 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
447 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
448 #define SvPV_set(sv, val) \
449 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
450 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
451 #define SvCUR_set(sv, val) \
452 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
453 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
454 #define SvLEN_set(sv, val) \
455 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
456 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
457 #define SvEND_set(sv, val) \
458 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
459 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
461 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
462 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
463 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
465 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
467 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
468 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
469 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
470 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
472 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
473 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
474 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
475 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
476 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
477 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
478 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
479 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
480 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
481 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
482 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
483 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
484 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
485 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
486 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
487 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
489 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
490 #define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END
491 #define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END
493 #define SvTAINT(sv) \
502 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
503 #define SvPV(sv, lp) sv_pvn(sv, &lp)
504 #define SvIVx(sv) sv_iv(sv)
505 #define SvUVx(sv) sv_uv(sv)
506 #define SvNVx(sv) sv_nv(sv)
507 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
508 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
509 #define SvTRUEx(sv) sv_true(sv)
511 #define SvIV(sv) SvIVx(sv)
512 #define SvNV(sv) SvNVx(sv)
513 #define SvUV(sv) SvIVx(sv)
514 #define SvTRUE(sv) SvTRUEx(sv)
517 /* redefine some things to more efficient inlined versions */
520 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
523 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
526 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
529 #define SvPV(sv, lp) \
530 (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
533 #define SvPV_force(sv, lp) \
534 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
535 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
544 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
545 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
546 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
547 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
548 # define SvTRUE(sv) ( \
552 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
554 (*nxpv->xpv_pv > '0' || \
555 nxpv->xpv_cur > 1 || \
556 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
565 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
568 /* These inlined macros use globals, which will require a thread
569 * declaration in user code, so we avoid them under threads */
577 # define SvIVx(sv) ((Sv = (sv)), SvIV(Sv))
578 # define SvUVx(sv) ((Sv = (sv)), SvUV(Sv))
579 # define SvNVx(sv) ((Sv = (sv)), SvNV(Sv))
580 # define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp))
581 # define SvTRUE(sv) ( \
585 ? ((Xpv = (XPV*)SvANY(sv)) && \
586 (*Xpv->xpv_pv > '0' || \
587 Xpv->xpv_cur > 1 || \
588 (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \
597 # define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv))
598 #endif /* !USE_THREADS */
599 #endif /* !__GNU__ */
600 #endif /* !CRIPPLED_CC */
602 #define newRV_inc(sv) newRV(sv)
605 # define newRV_noinc(sv) ({SV *nsv=newRV((sv)); --SvREFCNT(SvRV(nsv)); nsv;})
607 # if defined(CRIPPLED_CC) || defined(USE_THREADS)
610 # define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv)
612 #endif /* __GNUC__ */
614 /* the following macros update any magic values this sv is associated with */
616 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
617 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
619 #define SvSetSV_and(dst,src,finally) \
621 if ((dst) != (src)) { \
622 sv_setsv(dst, src); \
626 #define SvSetSV_nosteal_and(dst,src,finally) \
628 if ((dst) != (src)) { \
629 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
631 sv_setsv(dst, src); \
632 SvFLAGS(src) |= tMpF; \
637 #define SvSetSV(dst,src) \
638 SvSetSV_and(dst,src,/*nothing*/;)
639 #define SvSetSV_nosteal(dst,src) \
640 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
642 #define SvSetMagicSV(dst,src) \
643 SvSetSV_and(dst,src,SvSETMAGIC(dst))
644 #define SvSetMagicSV_nosteal(dst,src) \
645 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
647 #define SvPEEK(sv) sv_peek(sv)
649 #define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no)
651 #define boolSV(b) ((b) ? &sv_yes : &sv_no)
653 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
656 # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
657 # define Sv_Grow sv_grow
659 /* extra parentheses intentionally NOT placed around "len"! */
660 # define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \
661 ? sv_grow(sv,(unsigned long)len) : SvPVX(sv))
662 # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len))