3 * Copyright (c) 1991-2002, 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() */
17 =for apidoc AmU||svtype
18 An enum of flags for Perl types. These are found in the file B<sv.h>
19 in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
21 =for apidoc AmU||SVt_PV
22 Pointer type flag for scalars. See C<svtype>.
24 =for apidoc AmU||SVt_IV
25 Integer type flag for scalars. See C<svtype>.
27 =for apidoc AmU||SVt_NV
28 Double type flag for scalars. See C<svtype>.
30 =for apidoc AmU||SVt_PVMG
31 Type flag for blessed scalars. See C<svtype>.
33 =for apidoc AmU||SVt_PVAV
34 Type flag for arrays. See C<svtype>.
36 =for apidoc AmU||SVt_PVHV
37 Type flag for hashes. See C<svtype>.
39 =for apidoc AmU||SVt_PVCV
40 Type flag for code refs. See C<svtype>.
64 /* Using C's structural equivalence to help emulate C++ inheritance here... */
66 struct STRUCT_SV { /* struct sv { */
67 void* sv_any; /* pointer to something */
68 U32 sv_refcnt; /* how many references to us */
69 U32 sv_flags; /* what we are */
73 XPVGV* sv_any; /* pointer to something */
74 U32 sv_refcnt; /* how many references to us */
75 U32 sv_flags; /* what we are */
79 XPVCV* sv_any; /* pointer to something */
80 U32 sv_refcnt; /* how many references to us */
81 U32 sv_flags; /* what we are */
85 XPVAV* sv_any; /* pointer to something */
86 U32 sv_refcnt; /* how many references to us */
87 U32 sv_flags; /* what we are */
91 XPVHV* sv_any; /* pointer to something */
92 U32 sv_refcnt; /* how many references to us */
93 U32 sv_flags; /* what we are */
97 XPVIO* sv_any; /* pointer to something */
98 U32 sv_refcnt; /* how many references to us */
99 U32 sv_flags; /* what we are */
103 =head1 SV Manipulation Functions
105 =for apidoc Am|U32|SvREFCNT|SV* sv
106 Returns the value of the object's reference count.
108 =for apidoc Am|SV*|SvREFCNT_inc|SV* sv
109 Increments the reference count of the given SV.
111 =for apidoc Am|void|SvREFCNT_dec|SV* sv
112 Decrements the reference count of the given SV.
114 =for apidoc Am|svtype|SvTYPE|SV* sv
115 Returns the type of the SV. See C<svtype>.
117 =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type
118 Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
119 perform the upgrade if necessary. See C<svtype>.
124 #define SvANY(sv) (sv)->sv_any
125 #define SvFLAGS(sv) (sv)->sv_flags
126 #define SvREFCNT(sv) (sv)->sv_refcnt
128 #ifdef USE_5005THREADS
131 # define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count)
132 # define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count))
134 # ifdef EMULATE_ATOMIC_REFCOUNTS
135 # define ATOMIC_INC(count) STMT_START { \
136 MUTEX_LOCK(&PL_svref_mutex); \
138 MUTEX_UNLOCK(&PL_svref_mutex); \
140 # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \
141 MUTEX_LOCK(&PL_svref_mutex); \
142 res = (--count == 0); \
143 MUTEX_UNLOCK(&PL_svref_mutex); \
146 # define ATOMIC_INC(count) atomic_inc(&count)
147 # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count))
148 # endif /* EMULATE_ATOMIC_REFCOUNTS */
151 # define ATOMIC_INC(count) (++count)
152 # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
153 #endif /* USE_5005THREADS */
156 # define SvREFCNT_inc(sv) \
158 SV *nsv = (SV*)(sv); \
160 ATOMIC_INC(SvREFCNT(nsv)); \
164 # if defined(CRIPPLED_CC) || defined(USE_5005THREADS)
165 # if defined(VMS) && defined(__ALPHA)
166 # define SvREFCNT_inc(sv) \
167 (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv)
169 # define SvREFCNT_inc(sv) sv_newref((SV*)sv)
172 # define SvREFCNT_inc(sv) \
173 ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
177 #define SvREFCNT_dec(sv) sv_free((SV*)sv)
179 #define SVTYPEMASK 0xff
180 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
182 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
184 #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */
185 #define SVs_PADTMP 0x00000200 /* in use as tmp */
186 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
187 #define SVs_TEMP 0x00000800 /* string is stealable? */
188 #define SVs_OBJECT 0x00001000 /* is "blessed" */
189 #define SVs_GMG 0x00002000 /* has magical get method */
190 #define SVs_SMG 0x00004000 /* has magical set method */
191 #define SVs_RMG 0x00008000 /* has random magical methods */
193 #define SVf_IOK 0x00010000 /* has valid public integer value */
194 #define SVf_NOK 0x00020000 /* has valid public numeric value */
195 #define SVf_POK 0x00040000 /* has valid public pointer value */
196 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
198 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
199 #define SVf_OOK 0x00200000 /* has valid offset value */
200 #define SVf_BREAK 0x00400000 /* refcnt is artificially low - used
201 * by SV's in final arena cleanup */
202 #define SVf_READONLY 0x00800000 /* may not be modified */
205 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
206 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
207 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
208 #define SVp_SCREAM 0x08000000 /* has been studied? */
210 #define SVf_UTF8 0x20000000 /* SvPVX is UTF-8 encoded */
212 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)
214 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
215 SVp_IOK|SVp_NOK|SVp_POK)
217 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
221 /* Some private flags. */
223 /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
224 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
225 #define SVpad_TYPED 0x40000000 /* Typed Lexical */
227 #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
229 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
231 #define SVpbm_VALID 0x80000000
232 #define SVpbm_TAIL 0x40000000
234 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
236 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
237 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
239 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
242 SV * xrv_rv; /* pointer to another SV */
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 */
252 char * xpv_pv; /* pointer to malloced string */
253 STRLEN xpv_cur; /* length of xpv_pv as a C string */
254 STRLEN xpv_len; /* allocated size */
255 IV xiv_iv; /* integer value or pv offset */
259 char * xpv_pv; /* pointer to malloced string */
260 STRLEN xpv_cur; /* length of xpv_pv as a C string */
261 STRLEN xpv_len; /* allocated size */
262 UV xuv_uv; /* unsigned value or pv offset */
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 */
273 /* These structure must match the beginning of struct xpvhv in hv.h. */
275 char * xpv_pv; /* pointer to malloced string */
276 STRLEN xpv_cur; /* length of xpv_pv as a C string */
277 STRLEN xpv_len; /* allocated size */
278 IV xiv_iv; /* integer value or pv offset */
279 NV xnv_nv; /* numeric value, if any */
280 MAGIC* xmg_magic; /* linked list of magicalness */
281 HV* xmg_stash; /* class package */
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 NV xnv_nv; /* numeric value, if any */
290 MAGIC* xmg_magic; /* linked list of magicalness */
291 HV* xmg_stash; /* class package */
300 char * xpv_pv; /* pointer to malloced string */
301 STRLEN xpv_cur; /* length of xpv_pv as a C string */
302 STRLEN xpv_len; /* allocated size */
303 IV xiv_iv; /* integer value or pv offset */
304 NV xnv_nv; /* numeric value, if any */
305 MAGIC* xmg_magic; /* linked list of magicalness */
306 HV* xmg_stash; /* class package */
316 char * xpv_pv; /* pointer to malloced string */
317 STRLEN xpv_cur; /* length of xpv_pv as a C string */
318 STRLEN xpv_len; /* allocated size */
319 IV xiv_iv; /* integer value or pv offset */
320 NV xnv_nv; /* numeric value, if any */
321 MAGIC* xmg_magic; /* linked list of magicalness */
322 HV* xmg_stash; /* class package */
324 I32 xbm_useful; /* is this constant pattern being useful? */
325 U16 xbm_previous; /* how many characters in string before rare? */
326 U8 xbm_rare; /* rarest character in string */
329 /* This structure much match XPVCV in cv.h */
331 typedef U16 cv_flags_t;
334 char * xpv_pv; /* pointer to malloced string */
335 STRLEN xpv_cur; /* length of xpv_pv as a C string */
336 STRLEN xpv_len; /* allocated size */
337 IV xiv_iv; /* integer value or pv offset */
338 NV xnv_nv; /* numeric value, if any */
339 MAGIC* xmg_magic; /* linked list of magicalness */
340 HV* xmg_stash; /* class package */
345 void (*xcv_xsub)(pTHX_ CV*);
349 long xcv_depth; /* >= 2 indicates recursive call */
352 #ifdef USE_5005THREADS
353 perl_mutex *xcv_mutexp; /* protects xcv_owner */
354 struct perl_thread *xcv_owner; /* current owner thread */
355 #endif /* USE_5005THREADS */
356 cv_flags_t xcv_flags;
362 char * xpv_pv; /* pointer to malloced string */
363 STRLEN xpv_cur; /* length of xpv_pv as a C string */
364 STRLEN xpv_len; /* allocated size */
365 IV xiv_iv; /* integer value or pv offset */
366 NV xnv_nv; /* numeric value, if any */
367 MAGIC* xmg_magic; /* linked list of magicalness */
368 HV* xmg_stash; /* class package */
370 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
371 PerlIO * xio_ofp; /* but sockets need separate streams */
372 /* Cray addresses everything by word boundaries (64 bits) and
373 * code and data pointers cannot be mixed (which is exactly what
374 * Perl_filter_add() tries to do with the dirp), hence the following
375 * union trick (as suggested by Gurusamy Sarathy).
376 * For further information see Geir Johansen's problem report titled
377 [ID 20000612.002] Perl problem on Cray system
378 * The any pointer (known as IoANY()) will also be a good place
379 * to hang any IO disciplines to.
382 DIR * xiou_dirp; /* for opendir, readdir, etc */
383 void * xiou_any; /* for alignment */
385 IV xio_lines; /* $. */
386 IV xio_page; /* $% */
387 IV xio_page_len; /* $= */
388 IV xio_lines_left; /* $- */
389 char * xio_top_name; /* $^ */
390 GV * xio_top_gv; /* $^ */
391 char * xio_fmt_name; /* $~ */
392 GV * xio_fmt_gv; /* $~ */
393 char * xio_bottom_name;/* $^B */
394 GV * xio_bottom_gv; /* $^B */
395 short xio_subprocess; /* -| or |- */
399 #define xio_dirp xio_dirpu.xiou_dirp
400 #define xio_any xio_dirpu.xiou_any
402 #define IOf_ARGV 1 /* this fp iterates over ARGV */
403 #define IOf_START 2 /* check for null ARGV and substitute '-' */
404 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
405 #define IOf_DIDTOP 8 /* just did top of form */
406 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
407 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
408 #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
410 /* The following macros define implementation-independent predicates on SVs. */
413 =for apidoc Am|bool|SvNIOK|SV* sv
414 Returns a boolean indicating whether the SV contains a number, integer or
417 =for apidoc Am|bool|SvNIOKp|SV* sv
418 Returns a boolean indicating whether the SV contains a number, integer or
419 double. Checks the B<private> setting. Use C<SvNIOK>.
421 =for apidoc Am|void|SvNIOK_off|SV* sv
422 Unsets the NV/IV status of an SV.
424 =for apidoc Am|bool|SvOK|SV* sv
425 Returns a boolean indicating whether the value is an SV.
427 =for apidoc Am|bool|SvIOKp|SV* sv
428 Returns a boolean indicating whether the SV contains an integer. Checks
429 the B<private> setting. Use C<SvIOK>.
431 =for apidoc Am|bool|SvNOKp|SV* sv
432 Returns a boolean indicating whether the SV contains a double. Checks the
433 B<private> setting. Use C<SvNOK>.
435 =for apidoc Am|bool|SvPOKp|SV* sv
436 Returns a boolean indicating whether the SV contains a character string.
437 Checks the B<private> setting. Use C<SvPOK>.
439 =for apidoc Am|bool|SvIOK|SV* sv
440 Returns a boolean indicating whether the SV contains an integer.
442 =for apidoc Am|void|SvIOK_on|SV* sv
443 Tells an SV that it is an integer.
445 =for apidoc Am|void|SvIOK_off|SV* sv
446 Unsets the IV status of an SV.
448 =for apidoc Am|void|SvIOK_only|SV* sv
449 Tells an SV that it is an integer and disables all other OK bits.
451 =for apidoc Am|void|SvIOK_only_UV|SV* sv
452 Tells and SV that it is an unsigned integer and disables all other OK bits.
454 =for apidoc Am|void|SvIOK_UV|SV* sv
455 Returns a boolean indicating whether the SV contains an unsigned integer.
457 =for apidoc Am|void|SvUOK|SV* sv
458 Returns a boolean indicating whether the SV contains an unsigned integer.
460 =for apidoc Am|void|SvIOK_notUV|SV* sv
461 Returns a boolean indicating whether the SV contains a signed integer.
463 =for apidoc Am|bool|SvNOK|SV* sv
464 Returns a boolean indicating whether the SV contains a double.
466 =for apidoc Am|void|SvNOK_on|SV* sv
467 Tells an SV that it is a double.
469 =for apidoc Am|void|SvNOK_off|SV* sv
470 Unsets the NV status of an SV.
472 =for apidoc Am|void|SvNOK_only|SV* sv
473 Tells an SV that it is a double and disables all other OK bits.
475 =for apidoc Am|bool|SvPOK|SV* sv
476 Returns a boolean indicating whether the SV contains a character
479 =for apidoc Am|void|SvPOK_on|SV* sv
480 Tells an SV that it is a string.
482 =for apidoc Am|void|SvPOK_off|SV* sv
483 Unsets the PV status of an SV.
485 =for apidoc Am|void|SvPOK_only|SV* sv
486 Tells an SV that it is a string and disables all other OK bits.
487 Will also turn off the UTF8 status.
489 =for apidoc Am|bool|SvOOK|SV* sv
490 Returns a boolean indicating whether the SvIVX is a valid offset value for
491 the SvPVX. This hack is used internally to speed up removal of characters
492 from the beginning of a SvPV. When SvOOK is true, then the start of the
493 allocated string buffer is really (SvPVX - SvIVX).
495 =for apidoc Am|bool|SvROK|SV* sv
496 Tests if the SV is an RV.
498 =for apidoc Am|void|SvROK_on|SV* sv
499 Tells an SV that it is an RV.
501 =for apidoc Am|void|SvROK_off|SV* sv
502 Unsets the RV status of an SV.
504 =for apidoc Am|SV*|SvRV|SV* sv
505 Dereferences an RV to return the SV.
507 =for apidoc Am|IV|SvIVX|SV* sv
508 Returns the raw value in the SV's IV slot, without checks or conversions.
509 Only use when you are sure SvIOK is true. See also C<SvIV()>.
511 =for apidoc Am|UV|SvUVX|SV* sv
512 Returns the raw value in the SV's UV slot, without checks or conversions.
513 Only use when you are sure SvIOK is true. See also C<SvUV()>.
515 =for apidoc Am|NV|SvNVX|SV* sv
516 Returns the raw value in the SV's NV slot, without checks or conversions.
517 Only use when you are sure SvNOK is true. See also C<SvNV()>.
519 =for apidoc Am|char*|SvPVX|SV* sv
520 Returns a pointer to the physical string in the SV. The SV must contain a
523 =for apidoc Am|STRLEN|SvCUR|SV* sv
524 Returns the length of the string which is in the SV. See C<SvLEN>.
526 =for apidoc Am|STRLEN|SvLEN|SV* sv
527 Returns the size of the string buffer in the SV, not including any part
528 attributable to C<SvOOK>. See C<SvCUR>.
530 =for apidoc Am|char*|SvEND|SV* sv
531 Returns a pointer to the last character in the string which is in the SV.
532 See C<SvCUR>. Access the character as *(SvEND(sv)).
534 =for apidoc Am|HV*|SvSTASH|SV* sv
535 Returns the stash of the SV.
537 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
538 Set the length of the string which is in the SV. See C<SvCUR>.
543 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
544 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
545 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
546 SVp_IOK|SVp_NOK|SVf_IVisUV))
548 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
549 #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
550 SVf_IVisUV|SVf_UTF8), \
552 #define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
556 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
557 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
558 #define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
559 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
560 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
561 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
562 #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK)
564 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
565 #define SvIOK_on(sv) ((void)SvOOK_off(sv), \
566 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
567 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
568 #define SvIOK_only(sv) ((void)SvOK_off(sv), \
569 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
570 #define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \
571 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
573 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
574 == (SVf_IOK|SVf_IVisUV))
575 #define SvUOK(sv) SvIOK_UV(sv)
576 #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
579 #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV)
580 #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV)
581 #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV)
583 #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK)
584 #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
585 #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
586 #define SvNOK_only(sv) ((void)SvOK_off(sv), \
587 SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
590 =for apidoc Am|void|SvUTF8|SV* sv
591 Returns a boolean indicating whether the SV contains UTF-8 encoded data.
593 =for apidoc Am|void|SvUTF8_on|SV *sv
594 Turn on the UTF8 status of an SV (the data is not changed, just the flag).
595 Do not use frivolously.
597 =for apidoc Am|void|SvUTF8_off|SV *sv
598 Unsets the UTF8 status of an SV.
600 =for apidoc Am|void|SvPOK_only_UTF8|SV* sv
601 Tells an SV that it is a string and disables all other OK bits,
602 and leaves the UTF8 status as it was.
607 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
608 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
609 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
611 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
612 #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
613 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
614 #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
615 SVf_IVisUV|SVf_UTF8), \
616 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
617 #define SvPOK_only_UTF8(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
619 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
621 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
622 #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
623 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
625 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
626 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
627 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
629 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
630 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
631 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
633 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
634 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
635 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
637 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
638 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
639 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
641 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
642 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
643 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
645 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
646 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
647 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
649 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
650 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
651 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
653 #define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC))
656 #define Gv_AMG(stash) \
657 (HV_AMAGICmb(stash) && \
658 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
660 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
662 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
663 == (SVf_ROK|SVprv_WEAKREF))
664 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
665 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
667 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
669 #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY)
671 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
672 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
673 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
675 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
676 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
678 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
679 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
680 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
682 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
683 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
684 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
686 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
687 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
688 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
690 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
691 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
692 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
694 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
695 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
696 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
698 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
699 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
700 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
702 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
703 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
704 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
706 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
707 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
708 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
711 /* The following uses the FAKE flag to show that a regex pointer is infact
712 its own offset in the regexpad for ithreads */
713 #define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE)
714 #define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
715 #define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
718 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
719 #define SvRVx(sv) SvRV(sv)
721 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
722 #define SvIVXx(sv) SvIVX(sv)
723 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
724 #define SvUVXx(sv) SvUVX(sv)
725 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
726 #define SvNVXx(sv) SvNVX(sv)
727 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
728 #define SvPVXx(sv) SvPVX(sv)
729 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
730 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
731 #define SvLENx(sv) SvLEN(sv)
732 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
733 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
734 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
735 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
737 /* Ask a scalar nicely to try to become an IV, if possible.
738 Not guaranteed to stay returning void */
739 /* Macro won't actually call sv_2iv if already IOK */
740 #define SvIV_please(sv) \
741 STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \
742 (void) SvIV(sv); } STMT_END
743 #define SvIV_set(sv, val) \
744 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
745 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
746 #define SvNV_set(sv, val) \
747 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
748 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
749 #define SvPV_set(sv, val) \
750 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
751 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
752 #define SvCUR_set(sv, val) \
753 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
754 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
755 #define SvLEN_set(sv, val) \
756 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
757 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
758 #define SvEND_set(sv, val) \
759 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
760 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
762 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
763 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
764 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
766 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
768 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
769 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
770 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
771 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
773 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
774 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
775 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
776 #define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any
777 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
778 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
779 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
780 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
781 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
782 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
783 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
784 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
785 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
786 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
787 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
788 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
789 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
791 /* IoTYPE(sv) is a single character telling the type of I/O connection. */
792 #define IoTYPE_RDONLY '<'
793 #define IoTYPE_WRONLY '>'
794 #define IoTYPE_RDWR '+'
795 #define IoTYPE_APPEND 'a'
796 #define IoTYPE_PIPE '|'
797 #define IoTYPE_STD '-' /* stdin or stdout */
798 #define IoTYPE_SOCKET 's'
799 #define IoTYPE_CLOSED ' '
802 =for apidoc Am|bool|SvTAINTED|SV* sv
803 Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
806 =for apidoc Am|void|SvTAINTED_on|SV* sv
807 Marks an SV as tainted.
809 =for apidoc Am|void|SvTAINTED_off|SV* sv
810 Untaints an SV. Be I<very> careful with this routine, as it short-circuits
811 some of Perl's fundamental security features. XS module authors should not
812 use this function unless they fully understand all the implications of
813 unconditionally untainting the value. Untainting should be done in the
814 standard perl fashion, via a carefully crafted regexp, rather than directly
815 untainting variables.
817 =for apidoc Am|void|SvTAINT|SV* sv
818 Taints an SV if tainting is enabled
823 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
824 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
825 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
827 #define SvTAINT(sv) \
836 =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
837 Like C<SvPV> but will force the SV into containing just a string
838 (C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
841 =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len
842 Like C<SvPV> but will force the SV into containing just a string
843 (C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
844 directly. Doesn't process magic.
846 =for apidoc Am|char*|SvPV|SV* sv|STRLEN len
847 Returns a pointer to the string in the SV, or a stringified form of
848 the SV if the SV does not contain a string. The SV may cache the
849 stringified version becoming C<SvPOK>. Handles 'get' magic. See also
850 C<SvPVx> for a version which guarantees to evaluate sv only once.
852 =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len
853 A version of C<SvPV> which guarantees to evaluate sv only once.
855 =for apidoc Am|char*|SvPV_nolen|SV* sv
856 Returns a pointer to the string in the SV, or a stringified form of
857 the SV if the SV does not contain a string. The SV may cache the
858 stringified form becoming C<SvPOK>. Handles 'get' magic.
860 =for apidoc Am|IV|SvIV|SV* sv
861 Coerces the given SV to an integer and returns it. See C<SvIVx> for a
862 version which guarantees to evaluate sv only once.
864 =for apidoc Am|IV|SvIVx|SV* sv
865 Coerces the given SV to an integer and returns it. Guarantees to evaluate
866 sv only once. Use the more efficient C<SvIV> otherwise.
868 =for apidoc Am|NV|SvNV|SV* sv
869 Coerce the given SV to a double and return it. See C<SvNVx> for a version
870 which guarantees to evaluate sv only once.
872 =for apidoc Am|NV|SvNVx|SV* sv
873 Coerces the given SV to a double and returns it. Guarantees to evaluate
874 sv only once. Use the more efficient C<SvNV> otherwise.
876 =for apidoc Am|UV|SvUV|SV* sv
877 Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
878 for a version which guarantees to evaluate sv only once.
880 =for apidoc Am|UV|SvUVx|SV* sv
881 Coerces the given SV to an unsigned integer and returns it. Guarantees to
882 evaluate sv only once. Use the more efficient C<SvUV> otherwise.
884 =for apidoc Am|bool|SvTRUE|SV* sv
885 Returns a boolean indicating whether Perl would evaluate the SV as true or
886 false, defined or undefined. Does not handle 'get' magic.
888 =for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len
889 Like C<SvPV_force>, but converts sv to utf8 first if necessary.
891 =for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len
892 Like C<SvPV>, but converts sv to utf8 first if necessary.
894 =for apidoc Am|char*|SvPVutf8_nolen|SV* sv
895 Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
897 =for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len
898 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
900 =for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len
901 Like C<SvPV>, but converts sv to byte representation first if necessary.
903 =for apidoc Am|char*|SvPVbyte_nolen|SV* sv
904 Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
906 =for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len
907 Like C<SvPV_force>, but converts sv to utf8 first if necessary.
908 Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
911 =for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len
912 Like C<SvPV>, but converts sv to utf8 first if necessary.
913 Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
916 =for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len
917 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
918 Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
921 =for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len
922 Like C<SvPV>, but converts sv to byte representation first if necessary.
923 Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
930 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
931 #define SvPV(sv, lp) sv_pvn(sv, &lp)
932 #define SvPV_nolen(sv) sv_pv(sv)
933 #define SvPV_nomg(sv, lp) sv_pvn_nomg(sv, &lp)
934 #define SvPV_force_flags(sv, lp, flags) sv_pvn_force_flags(sv, &lp, flags)
936 #define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
937 #define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
938 #define SvPVutf8_nolen(sv) sv_pvutf8(sv)
940 #define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
941 #define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
942 #define SvPVbyte_nolen(sv) sv_pvbyte(sv)
944 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
945 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
946 #define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
947 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
948 #define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
949 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
951 #define SvIVx(sv) sv_iv(sv)
952 #define SvUVx(sv) sv_uv(sv)
953 #define SvNVx(sv) sv_nv(sv)
955 #define SvTRUEx(sv) sv_true(sv)
957 #define SvIV(sv) SvIVx(sv)
958 #define SvNV(sv) SvNVx(sv)
959 #define SvUV(sv) SvUVx(sv)
960 #define SvTRUE(sv) SvTRUEx(sv)
962 /* flag values for sv_*_flags functions */
963 #define SV_IMMEDIATE_UNREF 1
966 #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
967 #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
968 #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
971 /* redefine some things to more efficient inlined versions */
973 /* Let us hope that bitmaps for UV and IV are the same */
975 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
978 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
981 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
983 #define sv_setsv(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC)
984 #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0)
985 #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
986 #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
987 #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
988 #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
989 #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
990 #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
991 #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)
994 #define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC)
997 #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
1000 #define SvPV_flags(sv, lp, flags) \
1001 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
1002 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
1005 #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
1006 #undef SvPV_force_nomg
1007 #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
1009 #undef SvPV_force_flags
1010 #define SvPV_force_flags(sv, lp, flags) \
1011 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
1012 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
1015 #define SvPV_nolen(sv) \
1016 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
1017 ? SvPVX(sv) : sv_2pv_nolen(sv))
1020 #define SvPVutf8(sv, lp) \
1021 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
1022 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
1024 #undef SvPVutf8_force
1025 #define SvPVutf8_force(sv, lp) \
1026 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
1027 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
1029 #undef SvPVutf8_nolen
1030 #define SvPVutf8_nolen(sv) \
1031 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
1032 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
1035 #define SvPVutf8(sv, lp) \
1036 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
1037 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
1039 #undef SvPVutf8_force
1040 #define SvPVutf8_force(sv, lp) \
1041 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
1042 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
1044 #undef SvPVutf8_nolen
1045 #define SvPVutf8_nolen(sv) \
1046 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
1047 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
1050 #define SvPVbyte(sv, lp) \
1051 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
1052 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
1054 #undef SvPVbyte_force
1055 #define SvPVbyte_force(sv, lp) \
1056 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
1057 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
1059 #undef SvPVbyte_nolen
1060 #define SvPVbyte_nolen(sv) \
1061 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
1062 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
1074 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
1075 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
1076 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
1077 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
1078 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
1079 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
1080 # define SvTRUE(sv) ( \
1084 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
1086 (nxpv->xpv_cur > 1 || \
1087 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
1094 ? SvNVX(sv) != 0.0 \
1096 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
1097 #else /* __GNUC__ */
1098 #ifndef USE_5005THREADS
1099 /* These inlined macros use globals, which will require a thread
1100 * declaration in user code, so we avoid them under threads */
1110 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
1111 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
1112 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
1113 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
1114 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
1115 # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
1116 # define SvTRUE(sv) ( \
1120 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
1121 (PL_Xpv->xpv_cur > 1 || \
1122 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
1129 ? SvNVX(sv) != 0.0 \
1131 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
1132 #endif /* !USE_5005THREADS */
1133 #endif /* !__GNU__ */
1134 #endif /* !CRIPPLED_CC */
1137 =for apidoc Am|SV*|newRV_inc|SV* sv
1139 Creates an RV wrapper for an SV. The reference count for the original SV is
1145 #define newRV_inc(sv) newRV(sv)
1147 /* the following macros update any magic values this sv is associated with */
1150 =head1 Magical Functions
1152 =for apidoc Am|void|SvGETMAGIC|SV* sv
1153 Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1154 argument more than once.
1156 =for apidoc Am|void|SvSETMAGIC|SV* sv
1157 Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1158 argument more than once.
1160 =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1161 Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1164 =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1165 Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1166 ssv. May evaluate arguments more than once.
1168 =for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv
1169 Like C<SvSetSV>, but does any set magic required afterwards.
1171 =for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv
1172 Like C<SvSetMagicSV>, but does any set magic required afterwards.
1174 =for apidoc Am|void|SvSHARE|SV* sv
1175 Arranges for sv to be shared between threads if a suitable module
1178 =for apidoc Am|void|SvLOCK|SV* sv
1179 Arranges for a mutual exclusion lock to be obtained on sv if a suitable module
1182 =for apidoc Am|void|SvUNLOCK|SV* sv
1183 Releases a mutual exclusion lock on sv if a suitable module
1186 =head1 SV Manipulation Functions
1188 =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len
1189 Expands the character buffer in the SV so that it has room for the
1190 indicated number of bytes (remember to reserve space for an extra trailing
1191 NUL character). Calls C<sv_grow> to perform the expansion if necessary.
1192 Returns a pointer to the character buffer.
1197 #define SvSHARE(sv) CALL_FPTR(PL_sharehook)(aTHX_ sv)
1198 #define SvLOCK(sv) CALL_FPTR(PL_lockhook)(aTHX_ sv)
1199 #define SvUNLOCK(sv) CALL_FPTR(PL_unlockhook)(aTHX_ sv)
1201 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1202 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1204 #define SvSetSV_and(dst,src,finally) \
1206 if ((dst) != (src)) { \
1207 sv_setsv(dst, src); \
1211 #define SvSetSV_nosteal_and(dst,src,finally) \
1213 if ((dst) != (src)) { \
1214 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
1216 sv_setsv(dst, src); \
1217 SvFLAGS(src) |= tMpF; \
1222 #define SvSetSV(dst,src) \
1223 SvSetSV_and(dst,src,/*nothing*/;)
1224 #define SvSetSV_nosteal(dst,src) \
1225 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
1227 #define SvSetMagicSV(dst,src) \
1228 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1229 #define SvSetMagicSV_nosteal(dst,src) \
1230 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1232 #if !defined(SKIP_DEBUGGING)
1233 #define SvPEEK(sv) sv_peek(sv)
1235 #define SvPEEK(sv) ""
1238 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
1240 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
1242 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1244 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1245 #define Sv_Grow sv_grow
1247 #define CLONEf_COPY_STACKS 1
1248 #define CLONEf_KEEP_PTR_TABLE 2
1249 #define CLONEf_CLONE_HOST 4
1251 struct clone_params {