3 * Copyright (c) 1991-2000, 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() */
15 =for apidoc AmU||svtype
16 An enum of flags for Perl types. These are found in the file B<sv.h>
17 in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
19 =for apidoc AmU||SVt_PV
20 Pointer type flag for scalars. See C<svtype>.
22 =for apidoc AmU||SVt_IV
23 Integer type flag for scalars. See C<svtype>.
25 =for apidoc AmU||SVt_NV
26 Double type flag for scalars. See C<svtype>.
28 =for apidoc AmU||SVt_PVMG
29 Type flag for blessed scalars. See C<svtype>.
31 =for apidoc AmU||SVt_PVAV
32 Type flag for arrays. See C<svtype>.
34 =for apidoc AmU||SVt_PVHV
35 Type flag for hashes. See C<svtype>.
37 =for apidoc AmU||SVt_PVCV
38 Type flag for code refs. See C<svtype>.
62 /* Using C's structural equivalence to help emulate C++ inheritance here... */
65 void* sv_any; /* pointer to something */
66 U32 sv_refcnt; /* how many references to us */
67 U32 sv_flags; /* what we are */
71 XPVGV* sv_any; /* pointer to something */
72 U32 sv_refcnt; /* how many references to us */
73 U32 sv_flags; /* what we are */
77 XPVCV* sv_any; /* pointer to something */
78 U32 sv_refcnt; /* how many references to us */
79 U32 sv_flags; /* what we are */
83 XPVAV* sv_any; /* pointer to something */
84 U32 sv_refcnt; /* how many references to us */
85 U32 sv_flags; /* what we are */
89 XPVHV* sv_any; /* pointer to something */
90 U32 sv_refcnt; /* how many references to us */
91 U32 sv_flags; /* what we are */
95 XPVIO* sv_any; /* pointer to something */
96 U32 sv_refcnt; /* how many references to us */
97 U32 sv_flags; /* what we are */
101 =for apidoc Am|U32|SvREFCNT|SV* sv
102 Returns the value of the object's reference count.
104 =for apidoc Am|SV*|SvREFCNT_inc|SV* sv
105 Increments the reference count of the given SV.
107 =for apidoc Am|void|SvREFCNT_dec|SV* sv
108 Decrements the reference count of the given SV.
110 =for apidoc Am|svtype|SvTYPE|SV* sv
111 Returns the type of the SV. See C<svtype>.
113 =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
114 Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
115 perform the upgrade if necessary. See C<svtype>.
120 #define SvANY(sv) (sv)->sv_any
121 #define SvFLAGS(sv) (sv)->sv_flags
122 #define SvREFCNT(sv) (sv)->sv_refcnt
127 # define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count)
128 # define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count))
130 # ifdef EMULATE_ATOMIC_REFCOUNTS
131 # define ATOMIC_INC(count) STMT_START { \
132 MUTEX_LOCK(&PL_svref_mutex); \
134 MUTEX_UNLOCK(&PL_svref_mutex); \
136 # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
137 MUTEX_LOCK(&PL_svref_mutex); \
138 res = (--count == 0); \
139 MUTEX_UNLOCK(&PL_svref_mutex); \
142 # define ATOMIC_INC(count) atomic_inc(&count)
143 # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
144 # endif /* EMULATE_ATOMIC_REFCOUNTS */
147 # define ATOMIC_INC(count) (++count)
148 # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
149 #endif /* USE_THREADS */
152 # define SvREFCNT_inc(sv) \
154 SV *nsv = (SV*)(sv); \
156 ATOMIC_INC(SvREFCNT(nsv)); \
160 # if defined(CRIPPLED_CC) || defined(USE_THREADS)
161 # if defined(VMS) && defined(__ALPHA)
162 # define SvREFCNT_inc(sv) \
163 (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv)
165 # define SvREFCNT_inc(sv) sv_newref((SV*)sv)
168 # define SvREFCNT_inc(sv) \
169 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
173 #define SvREFCNT_dec(sv) sv_free((SV*)sv)
175 #define SVTYPEMASK 0xff
176 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
178 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
180 #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
181 #define SVs_PADTMP 0x00000200 /* in use as tmp */
182 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
183 #define SVs_TEMP 0x00000800 /* string is stealable? */
184 #define SVs_OBJECT 0x00001000 /* is "blessed" */
185 #define SVs_GMG 0x00002000 /* has magical get method */
186 #define SVs_SMG 0x00004000 /* has magical set method */
187 #define SVs_RMG 0x00008000 /* has random magical methods */
189 #define SVf_IOK 0x00010000 /* has valid public integer value */
190 #define SVf_NOK 0x00020000 /* has valid public numeric value */
191 #define SVf_POK 0x00040000 /* has valid public pointer value */
192 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
194 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
195 #define SVf_OOK 0x00200000 /* has valid offset value */
196 #define SVf_BREAK 0x00400000 /* refcnt is artificially low */
197 #define SVf_READONLY 0x00800000 /* may not be modified */
200 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
201 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
202 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
203 #define SVp_SCREAM 0x08000000 /* has been studied? */
205 #define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
207 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE|SVf_UTF8)
209 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
210 SVp_IOK|SVp_NOK|SVp_POK)
212 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
216 /* Some private flags. */
218 /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
219 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
221 #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
223 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
225 #define SVpbm_VALID 0x80000000
226 #define SVpbm_TAIL 0x40000000
228 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
230 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
231 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
233 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
236 SV * xrv_rv; /* pointer to another SV */
240 char * xpv_pv; /* pointer to malloced string */
241 STRLEN xpv_cur; /* length of xpv_pv as a C string */
242 STRLEN xpv_len; /* allocated size */
246 char * xpv_pv; /* pointer to malloced string */
247 STRLEN xpv_cur; /* length of xpv_pv as a C string */
248 STRLEN xpv_len; /* allocated size */
249 IV xiv_iv; /* integer value or pv offset */
253 char * xpv_pv; /* pointer to malloced string */
254 STRLEN xpv_cur; /* length of xpv_pv as a C string */
255 STRLEN xpv_len; /* allocated size */
256 UV xuv_uv; /* unsigned value or pv offset */
260 char * xpv_pv; /* pointer to malloced string */
261 STRLEN xpv_cur; /* length of xpv_pv as a C string */
262 STRLEN xpv_len; /* allocated size */
263 IV xiv_iv; /* integer value or pv offset */
264 NV xnv_nv; /* numeric value, if any */
267 /* These structure must match the beginning of struct xpvhv in hv.h. */
269 char * xpv_pv; /* pointer to malloced string */
270 STRLEN xpv_cur; /* length of xpv_pv as a C string */
271 STRLEN xpv_len; /* allocated size */
272 IV xiv_iv; /* integer value or pv offset */
273 NV xnv_nv; /* numeric value, if any */
274 MAGIC* xmg_magic; /* linked list of magicalness */
275 HV* xmg_stash; /* class package */
279 char * xpv_pv; /* pointer to malloced string */
280 STRLEN xpv_cur; /* length of xpv_pv as a C string */
281 STRLEN xpv_len; /* allocated size */
282 IV xiv_iv; /* integer value or pv offset */
283 NV xnv_nv; /* numeric value, if any */
284 MAGIC* xmg_magic; /* linked list of magicalness */
285 HV* xmg_stash; /* class package */
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 */
310 char * xpv_pv; /* pointer to malloced string */
311 STRLEN xpv_cur; /* length of xpv_pv as a C string */
312 STRLEN xpv_len; /* allocated size */
313 IV xiv_iv; /* integer value or pv offset */
314 NV xnv_nv; /* numeric value, if any */
315 MAGIC* xmg_magic; /* linked list of magicalness */
316 HV* xmg_stash; /* class package */
318 I32 xbm_useful; /* is this constant pattern being useful? */
319 U16 xbm_previous; /* how many characters in string before rare? */
320 U8 xbm_rare; /* rarest character in string */
323 /* This structure much match XPVCV in cv.h */
325 typedef U16 cv_flags_t;
328 char * xpv_pv; /* pointer to malloced string */
329 STRLEN xpv_cur; /* length of xpv_pv as a C string */
330 STRLEN xpv_len; /* allocated size */
331 IV xiv_iv; /* integer value or pv offset */
332 NV xnv_nv; /* numeric value, if any */
333 MAGIC* xmg_magic; /* linked list of magicalness */
334 HV* xmg_stash; /* class package */
339 void (*xcv_xsub)(pTHXo_ CV*);
343 long xcv_depth; /* >= 2 indicates recursive call */
347 perl_mutex *xcv_mutexp; /* protects xcv_owner */
348 struct perl_thread *xcv_owner; /* current owner thread */
349 #endif /* USE_THREADS */
350 cv_flags_t xcv_flags;
356 char * xpv_pv; /* pointer to malloced string */
357 STRLEN xpv_cur; /* length of xpv_pv as a C string */
358 STRLEN xpv_len; /* allocated size */
359 IV xiv_iv; /* integer value or pv offset */
360 NV xnv_nv; /* numeric value, if any */
361 MAGIC* xmg_magic; /* linked list of magicalness */
362 HV* xmg_stash; /* class package */
364 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
365 PerlIO * xio_ofp; /* but sockets need separate streams */
366 /* Cray addresses everything by word boundaries (64 bits) and
367 * code and data pointers cannot be mixed (which is exactly what
368 * Perl_filter_add() tries to do), hence the following
369 * union trick (as suggested by Gurusamy Sarathy).
370 * For further information see Geir Johansen's problem report titled
371 [ID 20000612.002] Perl problem on Cray system
374 DIR * xiou_dirp; /* for opendir, readdir, etc */
375 void * xiou_dummy; /* for alignment */
377 long xio_lines; /* $. */
378 long xio_page; /* $% */
379 long xio_page_len; /* $= */
380 long xio_lines_left; /* $- */
381 char * xio_top_name; /* $^ */
382 GV * xio_top_gv; /* $^ */
383 char * xio_fmt_name; /* $~ */
384 GV * xio_fmt_gv; /* $~ */
385 char * xio_bottom_name;/* $^B */
386 GV * xio_bottom_gv; /* $^B */
387 short xio_subprocess; /* -| or |- */
391 #define xio_dirp xio_dirpu.xiou_dirp
393 #define IOf_ARGV 1 /* this fp iterates over ARGV */
394 #define IOf_START 2 /* check for null ARGV and substitute '-' */
395 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
396 #define IOf_DIDTOP 8 /* just did top of form */
397 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
398 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
399 #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
401 /* The following macros define implementation-independent predicates on SVs. */
404 =for apidoc Am|bool|SvNIOK|SV* sv
405 Returns a boolean indicating whether the SV contains a number, integer or
408 =for apidoc Am|bool|SvNIOKp|SV* sv
409 Returns a boolean indicating whether the SV contains a number, integer or
410 double. Checks the B<private> setting. Use C<SvNIOK>.
412 =for apidoc Am|void|SvNIOK_off|SV* sv
413 Unsets the NV/IV status of an SV.
415 =for apidoc Am|bool|SvOK|SV* sv
416 Returns a boolean indicating whether the value is an SV.
418 =for apidoc Am|bool|SvIOKp|SV* sv
419 Returns a boolean indicating whether the SV contains an integer. Checks
420 the B<private> setting. Use C<SvIOK>.
422 =for apidoc Am|bool|SvNOKp|SV* sv
423 Returns a boolean indicating whether the SV contains a double. Checks the
424 B<private> setting. Use C<SvNOK>.
426 =for apidoc Am|bool|SvPOKp|SV* sv
427 Returns a boolean indicating whether the SV contains a character string.
428 Checks the B<private> setting. Use C<SvPOK>.
430 =for apidoc Am|bool|SvIOK|SV* sv
431 Returns a boolean indicating whether the SV contains an integer.
433 =for apidoc Am|void|SvIOK_on|SV* sv
434 Tells an SV that it is an integer.
436 =for apidoc Am|void|SvIOK_off|SV* sv
437 Unsets the IV status of an SV.
439 =for apidoc Am|void|SvIOK_only|SV* sv
440 Tells an SV that it is an integer and disables all other OK bits.
442 =for apidoc Am|bool|SvNOK|SV* sv
443 Returns a boolean indicating whether the SV contains a double.
445 =for apidoc Am|void|SvNOK_on|SV* sv
446 Tells an SV that it is a double.
448 =for apidoc Am|void|SvNOK_off|SV* sv
449 Unsets the NV status of an SV.
451 =for apidoc Am|void|SvNOK_only|SV* sv
452 Tells an SV that it is a double and disables all other OK bits.
454 =for apidoc Am|bool|SvPOK|SV* sv
455 Returns a boolean indicating whether the SV contains a character
458 =for apidoc Am|void|SvPOK_on|SV* sv
459 Tells an SV that it is a string.
461 =for apidoc Am|void|SvPOK_off|SV* sv
462 Unsets the PV status of an SV.
464 =for apidoc Am|void|SvPOK_only|SV* sv
465 Tells an SV that it is a string and disables all other OK bits.
467 =for apidoc Am|bool|SvOOK|SV* sv
468 Returns a boolean indicating whether the SvIVX is a valid offset value for
469 the SvPVX. This hack is used internally to speed up removal of characters
470 from the beginning of a SvPV. When SvOOK is true, then the start of the
471 allocated string buffer is really (SvPVX - SvIVX).
473 =for apidoc Am|bool|SvROK|SV* sv
474 Tests if the SV is an RV.
476 =for apidoc Am|void|SvROK_on|SV* sv
477 Tells an SV that it is an RV.
479 =for apidoc Am|void|SvROK_off|SV* sv
480 Unsets the RV status of an SV.
482 =for apidoc Am|SV*|SvRV|SV* sv
483 Dereferences an RV to return the SV.
485 =for apidoc Am|IV|SvIVX|SV* sv
486 Returns the integer which is stored in the SV, assuming SvIOK is
489 =for apidoc Am|UV|SvUVX|SV* sv
490 Returns the unsigned integer which is stored in the SV, assuming SvIOK is
493 =for apidoc Am|NV|SvNVX|SV* sv
494 Returns the double which is stored in the SV, assuming SvNOK is
497 =for apidoc Am|char*|SvPVX|SV* sv
498 Returns a pointer to the string in the SV. The SV must contain a
501 =for apidoc Am|STRLEN|SvCUR|SV* sv
502 Returns the length of the string which is in the SV. See C<SvLEN>.
504 =for apidoc Am|STRLEN|SvLEN|SV* sv
505 Returns the size of the string buffer in the SV. See C<SvCUR>.
507 =for apidoc Am|char*|SvEND|SV* sv
508 Returns a pointer to the last character in the string which is in the SV.
509 See C<SvCUR>. Access the character as *(SvEND(sv)).
511 =for apidoc Am|HV*|SvSTASH|SV* sv
512 Returns the stash of the SV.
514 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
515 Set the length of the string which is in the SV. See C<SvCUR>.
520 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
521 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
522 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
523 SVp_IOK|SVp_NOK|SVf_IVisUV))
525 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
526 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
527 SVf_IVisUV|SVf_UTF8), \
529 #define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
533 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
534 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
535 #define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
536 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
537 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
538 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
539 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
541 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
542 #define SvIOK_on(sv) ((void)SvOOK_off(sv), \
543 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
544 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
545 #define SvIOK_only(sv) ((void)SvOK_off(sv), \
546 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
547 #define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \
548 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
550 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
551 == (SVf_IOK|SVf_IVisUV))
552 #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
555 #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
556 #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
557 #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
559 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
560 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
561 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
562 #define SvNOK_only(sv) ((void)SvOK_off(sv), \
563 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
565 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
566 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
567 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
569 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
570 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
571 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
572 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
573 SVf_IVisUV|SVf_UTF8), \
574 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
575 #define SvPOK_only_UTF8(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
577 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
579 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
580 #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
581 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
583 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
584 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
585 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
587 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
588 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
589 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
591 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
592 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
593 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
595 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
596 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
597 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
599 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
600 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
601 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
603 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
604 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
605 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
607 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
608 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
609 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
612 #define Gv_AMG(stash) \
613 (HV_AMAGICmb(stash) && \
614 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
616 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
618 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
619 == (SVf_ROK|SVprv_WEAKREF))
620 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
621 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
623 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
625 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
627 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
628 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
629 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
631 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
632 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
634 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
635 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
636 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
638 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
639 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
640 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
642 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
643 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
644 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
646 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
647 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
648 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
650 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
651 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
652 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
654 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
655 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
656 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
658 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
659 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
660 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
662 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
663 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
664 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
666 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
667 #define SvRVx(sv) SvRV(sv)
669 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
670 #define SvIVXx(sv) SvIVX(sv)
671 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
672 #define SvUVXx(sv) SvUVX(sv)
673 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
674 #define SvNVXx(sv) SvNVX(sv)
675 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
676 #define SvPVXx(sv) SvPVX(sv)
677 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
678 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
679 #define SvLENx(sv) SvLEN(sv)
680 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
681 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
682 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
683 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
685 #define SvIV_set(sv, val) \
686 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
687 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
688 #define SvNV_set(sv, val) \
689 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
690 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
691 #define SvPV_set(sv, val) \
692 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
693 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
694 #define SvCUR_set(sv, val) \
695 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
696 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
697 #define SvLEN_set(sv, val) \
698 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
699 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
700 #define SvEND_set(sv, val) \
701 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
702 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
704 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
705 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
706 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
708 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
710 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
711 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
712 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
713 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
715 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
716 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
717 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
718 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
719 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
720 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
721 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
722 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
723 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
724 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
725 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
726 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
727 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
728 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
729 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
730 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
733 IoTYPE(sv) is a single character saying what type of I/O connection
746 =for apidoc Am|bool|SvTAINTED|SV* sv
747 Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
750 =for apidoc Am|void|SvTAINTED_on|SV* sv
751 Marks an SV as tainted.
753 =for apidoc Am|void|SvTAINTED_off|SV* sv
754 Untaints an SV. Be I<very> careful with this routine, as it short-circuits
755 some of Perl's fundamental security features. XS module authors should not
756 use this function unless they fully understand all the implications of
757 unconditionally untainting the value. Untainting should be done in the
758 standard perl fashion, via a carefully crafted regexp, rather than directly
759 untainting variables.
761 =for apidoc Am|void|SvTAINT|SV* sv
762 Taints an SV if tainting is enabled
767 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
768 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
769 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
771 #define SvTAINT(sv) \
781 =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
782 Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
783 force if you are going to update the SvPVX directly.
785 =for apidoc Am|char*|SvPV|SV* sv|STRLEN len
786 Returns a pointer to the string in the SV, or a stringified form of the SV
787 if the SV does not contain a string. Handles 'get' magic.
789 =for apidoc Am|char*|SvPV_nolen|SV* sv
790 Returns a pointer to the string in the SV, or a stringified form of the SV
791 if the SV does not contain a string. Handles 'get' magic.
793 =for apidoc Am|IV|SvIV|SV* sv
794 Coerces the given SV to an integer and returns it.
796 =for apidoc Am|NV|SvNV|SV* sv
797 Coerce the given SV to a double and return it.
799 =for apidoc Am|UV|SvUV|SV* sv
800 Coerces the given SV to an unsigned integer and returns it.
802 =for apidoc Am|bool|SvTRUE|SV* sv
803 Returns a boolean indicating whether Perl would evaluate the SV as true or
804 false, defined or undefined. Does not handle 'get' magic.
809 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
810 #define SvPV(sv, lp) sv_pvn(sv, &lp)
811 #define SvPV_nolen(sv) sv_pv(sv)
813 #define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
814 #define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
815 #define SvPVutf8_nolen(sv) sv_pvutf8(sv)
817 #define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
818 #define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
819 #define SvPVbyte_nolen(sv) sv_pvbyte(sv)
821 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
822 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
823 #define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
824 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
825 #define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
826 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
828 #define SvIVx(sv) sv_iv(sv)
829 #define SvUVx(sv) sv_uv(sv)
830 #define SvNVx(sv) sv_nv(sv)
832 #define SvTRUEx(sv) sv_true(sv)
834 #define SvIV(sv) SvIVx(sv)
835 #define SvNV(sv) SvNVx(sv)
836 #define SvUV(sv) SvUVx(sv)
837 #define SvTRUE(sv) SvTRUEx(sv)
840 /* redefine some things to more efficient inlined versions */
842 /* Let us hope that bitmaps for UV and IV are the same */
844 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
847 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
850 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
853 #define SvPV(sv, lp) \
854 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
855 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
859 #define SvPV_force(sv, lp) \
860 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
861 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
864 #define SvPV_nolen(sv) \
865 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
866 ? SvPVX(sv) : sv_2pv_nolen(sv))
869 #define SvPVutf8(sv, lp) \
870 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
871 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
873 #undef SvPVutf8_force
874 #define SvPVutf8_force(sv, lp) \
875 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
876 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
878 #undef SvPVutf8_nolen
879 #define SvPVutf8_nolen(sv) \
880 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
881 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
884 #define SvPVutf8(sv, lp) \
885 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
886 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
888 #undef SvPVutf8_force
889 #define SvPVutf8_force(sv, lp) \
890 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
891 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
893 #undef SvPVutf8_nolen
894 #define SvPVutf8_nolen(sv) \
895 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
896 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
899 #define SvPVbyte(sv, lp) \
900 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
901 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
903 #undef SvPVbyte_force
904 #define SvPVbyte_force(sv, lp) \
905 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
906 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
908 #undef SvPVbyte_nolen
909 #define SvPVbyte_nolen(sv) \
910 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
911 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
923 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
924 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
925 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
926 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
927 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
928 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
929 # define SvTRUE(sv) ( \
933 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
935 (nxpv->xpv_cur > 1 || \
936 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
945 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
948 /* These inlined macros use globals, which will require a thread
949 * declaration in user code, so we avoid them under threads */
959 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
960 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
961 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
962 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
963 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
964 # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
965 # define SvTRUE(sv) ( \
969 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
970 (PL_Xpv->xpv_cur > 1 || \
971 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
980 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
981 #endif /* !USE_THREADS */
982 #endif /* !__GNU__ */
983 #endif /* !CRIPPLED_CC */
986 =for apidoc Am|SV*|newRV_inc|SV* sv
988 Creates an RV wrapper for an SV. The reference count for the original SV is
994 #define newRV_inc(sv) newRV(sv)
996 /* the following macros update any magic values this sv is associated with */
999 =for apidoc Am|void|SvGETMAGIC|SV* sv
1000 Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1001 argument more than once.
1003 =for apidoc Am|void|SvSETMAGIC|SV* sv
1004 Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1005 argument more than once.
1007 =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1008 Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1011 =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1012 Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1013 ssv. May evaluate arguments more than once.
1015 =for apidoc Am|void|SvGROW|SV* sv|STRLEN len
1016 Expands the character buffer in the SV so that it has room for the
1017 indicated number of bytes (remember to reserve space for an extra trailing
1018 NUL character). Calls C<sv_grow> to perform the expansion if necessary.
1019 Returns a pointer to the character buffer.
1021 =for apidoc Am|void|SvLOCK|SV* sv
1022 Aquires an internal mutex for a SV. Used to make sure multiple threads
1023 don't stomp on the guts of an SV at the same time
1025 =for apidoc Am|void|SvUNLOCK|SV* sv
1026 Release the internal mutex for an SV.
1031 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1032 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1034 #define SvSetSV_and(dst,src,finally) \
1036 if ((dst) != (src)) { \
1037 sv_setsv(dst, src); \
1041 #define SvSetSV_nosteal_and(dst,src,finally) \
1043 if ((dst) != (src)) { \
1044 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
1046 sv_setsv(dst, src); \
1047 SvFLAGS(src) |= tMpF; \
1052 #define SvSetSV(dst,src) \
1053 SvSetSV_and(dst,src,/*nothing*/;)
1054 #define SvSetSV_nosteal(dst,src) \
1055 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
1057 #define SvSetMagicSV(dst,src) \
1058 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1059 #define SvSetMagicSV_nosteal(dst,src) \
1060 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1064 #define SvLOCK(sv) MUTEX_LOCK(&PL_sv_lock_mutex)
1065 #define SvUNLOCK(sv) MUTEX_UNLOCK(&PL_sv_lock_mutex)
1066 #define SvPEEK(sv) sv_peek(sv)
1068 #define SvPEEK(sv) ""
1071 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
1073 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
1075 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1077 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1078 #define Sv_Grow sv_grow