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 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
129 # define SvREFCNT_inc(sv) \
131 SV *nsv = (SV*)(sv); \
137 # define SvREFCNT_inc(sv) \
138 ((PL_Sv=(SV*)(sv)), (PL_Sv && ++(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
141 #define SvREFCNT_dec(sv) sv_free((SV*)(sv))
143 #define SVTYPEMASK 0xff
144 #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK)
146 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
148 #define SVs_PADSTALE 0x00000100 /* lexical has gone out of scope */
149 #define SVs_PADTMP 0x00000200 /* in use as tmp */
150 #define SVs_PADMY 0x00000400 /* in use a "my" variable */
151 #define SVs_TEMP 0x00000800 /* string is stealable? */
152 #define SVs_OBJECT 0x00001000 /* is "blessed" */
153 #define SVs_GMG 0x00002000 /* has magical get method */
154 #define SVs_SMG 0x00004000 /* has magical set method */
155 #define SVs_RMG 0x00008000 /* has random magical methods */
157 #define SVf_IOK 0x00010000 /* has valid public integer value */
158 #define SVf_NOK 0x00020000 /* has valid public numeric value */
159 #define SVf_POK 0x00040000 /* has valid public pointer value */
160 #define SVf_ROK 0x00080000 /* has a valid reference pointer */
162 #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */
163 #define SVf_OOK 0x00200000 /* has valid offset value */
164 #define SVf_BREAK 0x00400000 /* refcnt is artificially low - used
165 * by SV's in final arena cleanup */
166 #define SVf_READONLY 0x00800000 /* may not be modified */
169 #define SVp_IOK 0x01000000 /* has valid non-public integer value */
170 #define SVp_NOK 0x02000000 /* has valid non-public numeric value */
171 #define SVp_POK 0x04000000 /* has valid non-public pointer value */
172 #define SVp_SCREAM 0x08000000 /* has been studied? */
174 #define SVf_UTF8 0x20000000 /* SvPV is UTF-8 encoded */
176 #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)
178 #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
179 SVp_IOK|SVp_NOK|SVp_POK)
181 #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */
183 #define PRIVSHIFT 8 /* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */
185 /* Some private flags. */
187 /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
188 #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */
189 #define SVpad_TYPED 0x40000000 /* Typed Lexical */
191 #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */
193 #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */
195 #define SVpbm_VALID 0x80000000
196 #define SVpbm_TAIL 0x40000000
198 #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */
200 #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */
201 #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */
202 #define SVphv_HASKFLAGS 0x80000000 /* keys have flag byte after hash */
204 #define SVprv_WEAKREF 0x80000000 /* Weak reference */
207 SV * xrv_rv; /* pointer to another SV */
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 */
217 char * xpv_pv; /* pointer to malloced string */
218 STRLEN xpv_cur; /* length of xpv_pv as a C string */
219 STRLEN xpv_len; /* allocated size */
220 IV xiv_iv; /* integer value or pv offset */
224 char * xpv_pv; /* pointer to malloced string */
225 STRLEN xpv_cur; /* length of xpv_pv as a C string */
226 STRLEN xpv_len; /* allocated size */
227 UV xuv_uv; /* unsigned value or pv offset */
231 char * xpv_pv; /* pointer to malloced string */
232 STRLEN xpv_cur; /* length of xpv_pv as a C string */
233 STRLEN xpv_len; /* allocated size */
234 IV xiv_iv; /* integer value or pv offset */
235 NV xnv_nv; /* numeric value, if any */
238 /* These structure must match the beginning of struct xpvhv in hv.h. */
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 */
243 IV xiv_iv; /* integer value or pv offset */
244 NV xnv_nv; /* numeric value, if any */
245 MAGIC* xmg_magic; /* linked list of magicalness */
246 HV* xmg_stash; /* class package */
250 char * xpv_pv; /* pointer to malloced string */
251 STRLEN xpv_cur; /* length of xpv_pv as a C string */
252 STRLEN xpv_len; /* allocated size */
253 IV xiv_iv; /* integer value or pv offset */
254 NV xnv_nv; /* numeric value, if any */
255 MAGIC* xmg_magic; /* linked list of magicalness */
256 HV* xmg_stash; /* class package */
265 char * xpv_pv; /* pointer to malloced string */
266 STRLEN xpv_cur; /* length of xpv_pv as a C string */
267 STRLEN xpv_len; /* allocated size */
268 IV xiv_iv; /* integer value or pv offset */
269 NV xnv_nv; /* numeric value, if any */
270 MAGIC* xmg_magic; /* linked list of magicalness */
271 HV* xmg_stash; /* class package */
281 char * xpv_pv; /* pointer to malloced string */
282 STRLEN xpv_cur; /* length of xpv_pv as a C string */
283 STRLEN xpv_len; /* allocated size */
284 IV xiv_iv; /* integer value or pv offset */
285 NV xnv_nv; /* numeric value, if any */
286 MAGIC* xmg_magic; /* linked list of magicalness */
287 HV* xmg_stash; /* class package */
289 I32 xbm_useful; /* is this constant pattern being useful? */
290 U16 xbm_previous; /* how many characters in string before rare? */
291 U8 xbm_rare; /* rarest character in string */
294 /* This structure much match XPVCV in cv.h */
296 typedef U16 cv_flags_t;
299 char * xpv_pv; /* pointer to malloced string */
300 STRLEN xpv_cur; /* length of xpv_pv as a C string */
301 STRLEN xpv_len; /* allocated size */
302 IV xiv_iv; /* integer value or pv offset */
303 NV xnv_nv; /* numeric value, if any */
304 MAGIC* xmg_magic; /* linked list of magicalness */
305 HV* xmg_stash; /* class package */
310 void (*xcv_xsub)(pTHX_ CV*);
314 long xcv_depth; /* >= 2 indicates recursive call */
317 cv_flags_t xcv_flags;
318 U32 xcv_outside_seq; /* the COP sequence (at the point of our
319 * compilation) in the lexically enclosing
325 char * xpv_pv; /* pointer to malloced string */
326 STRLEN xpv_cur; /* length of xpv_pv as a C string */
327 STRLEN xpv_len; /* allocated size */
328 IV xiv_iv; /* integer value or pv offset */
329 NV xnv_nv; /* numeric value, if any */
330 MAGIC* xmg_magic; /* linked list of magicalness */
331 HV* xmg_stash; /* class package */
333 PerlIO * xio_ifp; /* ifp and ofp are normally the same */
334 PerlIO * xio_ofp; /* but sockets need separate streams */
335 /* Cray addresses everything by word boundaries (64 bits) and
336 * code and data pointers cannot be mixed (which is exactly what
337 * Perl_filter_add() tries to do with the dirp), hence the following
338 * union trick (as suggested by Gurusamy Sarathy).
339 * For further information see Geir Johansen's problem report titled
340 [ID 20000612.002] Perl problem on Cray system
341 * The any pointer (known as IoANY()) will also be a good place
342 * to hang any IO disciplines to.
345 DIR * xiou_dirp; /* for opendir, readdir, etc */
346 void * xiou_any; /* for alignment */
348 IV xio_lines; /* $. */
349 IV xio_page; /* $% */
350 IV xio_page_len; /* $= */
351 IV xio_lines_left; /* $- */
352 char * xio_top_name; /* $^ */
353 GV * xio_top_gv; /* $^ */
354 char * xio_fmt_name; /* $~ */
355 GV * xio_fmt_gv; /* $~ */
356 char * xio_bottom_name;/* $^B */
357 GV * xio_bottom_gv; /* $^B */
358 short xio_subprocess; /* -| or |- */
362 #define xio_dirp xio_dirpu.xiou_dirp
363 #define xio_any xio_dirpu.xiou_any
365 #define IOf_ARGV 1 /* this fp iterates over ARGV */
366 #define IOf_START 2 /* check for null ARGV and substitute '-' */
367 #define IOf_FLUSH 4 /* this fp wants a flush after write op */
368 #define IOf_DIDTOP 8 /* just did top of form */
369 #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */
370 #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */
371 #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */
373 /* The following macros define implementation-independent predicates on SVs. */
376 =for apidoc Am|bool|SvNIOK|SV* sv
377 Returns a boolean indicating whether the SV contains a number, integer or
380 =for apidoc Am|bool|SvNIOKp|SV* sv
381 Returns a boolean indicating whether the SV contains a number, integer or
382 double. Checks the B<private> setting. Use C<SvNIOK>.
384 =for apidoc Am|void|SvNIOK_off|SV* sv
385 Unsets the NV/IV status of an SV.
387 =for apidoc Am|bool|SvOK|SV* sv
388 Returns a boolean indicating whether the value is an SV.
390 =for apidoc Am|bool|SvIOKp|SV* sv
391 Returns a boolean indicating whether the SV contains an integer. Checks
392 the B<private> setting. Use C<SvIOK>.
394 =for apidoc Am|bool|SvNOKp|SV* sv
395 Returns a boolean indicating whether the SV contains a double. Checks the
396 B<private> setting. Use C<SvNOK>.
398 =for apidoc Am|bool|SvPOKp|SV* sv
399 Returns a boolean indicating whether the SV contains a character string.
400 Checks the B<private> setting. Use C<SvPOK>.
402 =for apidoc Am|bool|SvIOK|SV* sv
403 Returns a boolean indicating whether the SV contains an integer.
405 =for apidoc Am|void|SvIOK_on|SV* sv
406 Tells an SV that it is an integer.
408 =for apidoc Am|void|SvIOK_off|SV* sv
409 Unsets the IV status of an SV.
411 =for apidoc Am|void|SvIOK_only|SV* sv
412 Tells an SV that it is an integer and disables all other OK bits.
414 =for apidoc Am|void|SvIOK_only_UV|SV* sv
415 Tells and SV that it is an unsigned integer and disables all other OK bits.
417 =for apidoc Am|void|SvIOK_UV|SV* sv
418 Returns a boolean indicating whether the SV contains an unsigned integer.
420 =for apidoc Am|void|SvUOK|SV* sv
421 Returns a boolean indicating whether the SV contains an unsigned integer.
423 =for apidoc Am|void|SvIOK_notUV|SV* sv
424 Returns a boolean indicating whether the SV contains a signed integer.
426 =for apidoc Am|bool|SvNOK|SV* sv
427 Returns a boolean indicating whether the SV contains a double.
429 =for apidoc Am|void|SvNOK_on|SV* sv
430 Tells an SV that it is a double.
432 =for apidoc Am|void|SvNOK_off|SV* sv
433 Unsets the NV status of an SV.
435 =for apidoc Am|void|SvNOK_only|SV* sv
436 Tells an SV that it is a double and disables all other OK bits.
438 =for apidoc Am|bool|SvPOK|SV* sv
439 Returns a boolean indicating whether the SV contains a character
442 =for apidoc Am|void|SvPOK_on|SV* sv
443 Tells an SV that it is a string.
445 =for apidoc Am|void|SvPOK_off|SV* sv
446 Unsets the PV status of an SV.
448 =for apidoc Am|void|SvPOK_only|SV* sv
449 Tells an SV that it is a string and disables all other OK bits.
450 Will also turn off the UTF8 status.
452 =for apidoc Am|bool|SvVOK|SV* sv
453 Returns a boolean indicating whether the SV contains a v-string.
455 =for apidoc Am|bool|SvOOK|SV* sv
456 Returns a boolean indicating whether the SvIVX is a valid offset value for
457 the SvPVX. This hack is used internally to speed up removal of characters
458 from the beginning of a SvPV. When SvOOK is true, then the start of the
459 allocated string buffer is really (SvPVX - SvIVX).
461 =for apidoc Am|bool|SvROK|SV* sv
462 Tests if the SV is an RV.
464 =for apidoc Am|void|SvROK_on|SV* sv
465 Tells an SV that it is an RV.
467 =for apidoc Am|void|SvROK_off|SV* sv
468 Unsets the RV status of an SV.
470 =for apidoc Am|SV*|SvRV|SV* sv
471 Dereferences an RV to return the SV.
473 =for apidoc Am|IV|SvIVX|SV* sv
474 Returns the raw value in the SV's IV slot, without checks or conversions.
475 Only use when you are sure SvIOK is true. See also C<SvIV()>.
477 =for apidoc Am|UV|SvUVX|SV* sv
478 Returns the raw value in the SV's UV slot, without checks or conversions.
479 Only use when you are sure SvIOK is true. See also C<SvUV()>.
481 =for apidoc Am|NV|SvNVX|SV* sv
482 Returns the raw value in the SV's NV slot, without checks or conversions.
483 Only use when you are sure SvNOK is true. See also C<SvNV()>.
485 =for apidoc Am|char*|SvPVX|SV* sv
486 Returns a pointer to the physical string in the SV. The SV must contain a
489 =for apidoc Am|STRLEN|SvCUR|SV* sv
490 Returns the length of the string which is in the SV. See C<SvLEN>.
492 =for apidoc Am|STRLEN|SvLEN|SV* sv
493 Returns the size of the string buffer in the SV, not including any part
494 attributable to C<SvOOK>. See C<SvCUR>.
496 =for apidoc Am|char*|SvEND|SV* sv
497 Returns a pointer to the last character in the string which is in the SV.
498 See C<SvCUR>. Access the character as *(SvEND(sv)).
500 =for apidoc Am|HV*|SvSTASH|SV* sv
501 Returns the stash of the SV.
503 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
504 Set the length of the string which is in the SV. See C<SvCUR>.
509 #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
510 #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
511 #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
512 SVp_IOK|SVp_NOK|SVf_IVisUV))
515 #define assert_not_ROK(sv) ({assert(!SvROK(sv) || !SvRV(sv))})
517 #define assert_not_ROK(sv) 0
520 #define SvOK(sv) (SvFLAGS(sv) & SVf_OK)
521 #define SvOK_off(sv) (assert_not_ROK(sv), \
522 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
523 SVf_IVisUV|SVf_UTF8), \
525 #define SvOK_off_exc_UV(sv) (assert_not_ROK(sv), \
526 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
530 #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
531 #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK)
532 #define SvIOKp_on(sv) (SvRELEASE_IVX(sv), \
533 SvFLAGS(sv) |= SVp_IOK)
534 #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK)
535 #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK)
536 #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK)
537 #define SvPOKp_on(sv) (assert_not_ROK(sv), \
538 SvFLAGS(sv) |= SVp_POK)
540 #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK)
541 #define SvIOK_on(sv) (SvRELEASE_IVX(sv), \
542 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
543 #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
544 #define SvIOK_only(sv) ((void)SvOK_off(sv), \
545 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
546 #define SvIOK_only_UV(sv) ((void)SvOK_off_exc_UV(sv), \
547 SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
549 #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \
550 == (SVf_IOK|SVf_IVisUV))
551 #define SvUOK(sv) SvIOK_UV(sv)
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))
566 =for apidoc Am|void|SvUTF8|SV* sv
567 Returns a boolean indicating whether the SV contains UTF-8 encoded data.
569 =for apidoc Am|void|SvUTF8_on|SV *sv
570 Turn on the UTF8 status of an SV (the data is not changed, just the flag).
571 Do not use frivolously.
573 =for apidoc Am|void|SvUTF8_off|SV *sv
574 Unsets the UTF8 status of an SV.
576 =for apidoc Am|void|SvPOK_only_UTF8|SV* sv
577 Tells an SV that it is a string and disables all other OK bits,
578 and leaves the UTF8 status as it was.
583 #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8)
584 #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8))
585 #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8))
587 #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK)
588 #define SvPOK_on(sv) (assert_not_ROK(sv), \
589 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
590 #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
591 #define SvPOK_only(sv) (assert_not_ROK(sv), \
592 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
593 SVf_IVisUV|SVf_UTF8), \
594 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
595 #define SvPOK_only_UTF8(sv) (assert_not_ROK(sv), \
596 SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \
598 SvFLAGS(sv) |= (SVf_POK|SVp_POK))
600 #define SvVOK(sv) (SvMAGICAL(sv) && mg_find(sv,'V'))
601 #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK)
602 #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
603 #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv))
605 #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE)
606 #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
607 #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
609 #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK)
610 #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK)
611 #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
613 #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
614 #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
615 #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
617 #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG)
618 #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG)
619 #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG)
621 #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG)
622 #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG)
623 #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG)
625 #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG)
626 #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG)
627 #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG)
629 #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC)
630 #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC)
631 #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC)
633 #define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC))
636 #define Gv_AMG(stash) \
637 (HV_AMAGICmb(stash) && \
638 ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
640 #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash))
642 #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
643 == (SVf_ROK|SVprv_WEAKREF))
644 #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF))
645 #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
647 #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST)
649 #define SvPADSTALE(sv) (SvFLAGS(sv) & SVs_PADSTALE)
650 #define SvPADSTALE_on(sv) (SvFLAGS(sv) |= SVs_PADSTALE)
651 #define SvPADSTALE_off(sv) (SvFLAGS(sv) &= ~SVs_PADSTALE)
653 #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP)
654 #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP)
655 #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP)
657 #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY)
658 #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY)
660 #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP)
661 #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP)
662 #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP)
664 #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT)
665 #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT)
666 #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT)
668 #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY)
669 #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY)
670 #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY)
672 #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM)
673 #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM)
674 #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM)
676 #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED)
677 #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED)
678 #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED)
680 #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL)
681 #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL)
682 #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL)
684 #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL)
685 #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL)
686 #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL)
688 #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID)
689 #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID)
690 #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID)
693 /* The following uses the FAKE flag to show that a regex pointer is infact
694 its own offset in the regexpad for ithreads */
695 #define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE)
696 #define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE)
697 #define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE)
700 #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv
701 #define SvRVx(sv) SvRV(sv)
703 #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
704 #define SvIVXx(sv) SvIVX(sv)
705 #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv
706 #define SvUVXx(sv) SvUVX(sv)
707 #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv
708 #define SvNVXx(sv) SvNVX(sv)
709 #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv
710 #define SvPVXx(sv) SvPVX(sv)
711 #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur
712 #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len
713 #define SvLENx(sv) SvLEN(sv)
714 #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
715 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
716 #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic
717 #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash
719 /* Ask a scalar nicely to try to become an IV, if possible.
720 Not guaranteed to stay returning void */
721 /* Macro won't actually call sv_2iv if already IOK */
722 #define SvIV_please(sv) \
723 STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \
724 (void) SvIV(sv); } STMT_END
725 #define SvIV_set(sv, val) \
726 STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
727 (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END
728 #define SvNV_set(sv, val) \
729 STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
730 (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END
731 #define SvPV_set(sv, val) \
732 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
733 (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END
734 #define SvCUR_set(sv, val) \
735 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
736 (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END
737 #define SvLEN_set(sv, val) \
738 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
739 (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END
740 #define SvEND_set(sv, val) \
741 STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
742 (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
744 #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare
745 #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful
746 #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous
748 #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines
750 #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type
751 #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ
752 #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff
753 #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
755 #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp
756 #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
757 #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp
758 #define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any
759 #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines
760 #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page
761 #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len
762 #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left
763 #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name
764 #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv
765 #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name
766 #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv
767 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
768 #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv
769 #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess
770 #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type
771 #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags
773 /* IoTYPE(sv) is a single character telling the type of I/O connection. */
774 #define IoTYPE_RDONLY '<'
775 #define IoTYPE_WRONLY '>'
776 #define IoTYPE_RDWR '+'
777 #define IoTYPE_APPEND 'a'
778 #define IoTYPE_PIPE '|'
779 #define IoTYPE_STD '-' /* stdin or stdout */
780 #define IoTYPE_SOCKET 's'
781 #define IoTYPE_CLOSED ' '
784 =for apidoc Am|bool|SvTAINTED|SV* sv
785 Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
788 =for apidoc Am|void|SvTAINTED_on|SV* sv
789 Marks an SV as tainted.
791 =for apidoc Am|void|SvTAINTED_off|SV* sv
792 Untaints an SV. Be I<very> careful with this routine, as it short-circuits
793 some of Perl's fundamental security features. XS module authors should not
794 use this function unless they fully understand all the implications of
795 unconditionally untainting the value. Untainting should be done in the
796 standard perl fashion, via a carefully crafted regexp, rather than directly
797 untainting variables.
799 =for apidoc Am|void|SvTAINT|SV* sv
800 Taints an SV if tainting is enabled
805 #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))
806 #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END
807 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
809 #define SvTAINT(sv) \
818 =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
819 Like C<SvPV> but will force the SV into containing just a string
820 (C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
823 =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len
824 Like C<SvPV> but will force the SV into containing just a string
825 (C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
826 directly. Doesn't process magic.
828 =for apidoc Am|char*|SvPV|SV* sv|STRLEN len
829 Returns a pointer to the string in the SV, or a stringified form of
830 the SV if the SV does not contain a string. The SV may cache the
831 stringified version becoming C<SvPOK>. Handles 'get' magic. See also
832 C<SvPVx> for a version which guarantees to evaluate sv only once.
834 =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len
835 A version of C<SvPV> which guarantees to evaluate sv only once.
837 =for apidoc Am|char*|SvPV_nolen|SV* sv
838 Returns a pointer to the string in the SV, or a stringified form of
839 the SV if the SV does not contain a string. The SV may cache the
840 stringified form becoming C<SvPOK>. Handles 'get' magic.
842 =for apidoc Am|IV|SvIV|SV* sv
843 Coerces the given SV to an integer and returns it. See C<SvIVx> for a
844 version which guarantees to evaluate sv only once.
846 =for apidoc Am|IV|SvIVx|SV* sv
847 Coerces the given SV to an integer and returns it. Guarantees to evaluate
848 sv only once. Use the more efficient C<SvIV> otherwise.
850 =for apidoc Am|NV|SvNV|SV* sv
851 Coerce the given SV to a double and return it. See C<SvNVx> for a version
852 which guarantees to evaluate sv only once.
854 =for apidoc Am|NV|SvNVx|SV* sv
855 Coerces the given SV to a double and returns it. Guarantees to evaluate
856 sv only once. Use the more efficient C<SvNV> otherwise.
858 =for apidoc Am|UV|SvUV|SV* sv
859 Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
860 for a version which guarantees to evaluate sv only once.
862 =for apidoc Am|UV|SvUVx|SV* sv
863 Coerces the given SV to an unsigned integer and returns it. Guarantees to
864 evaluate sv only once. Use the more efficient C<SvUV> otherwise.
866 =for apidoc Am|bool|SvTRUE|SV* sv
867 Returns a boolean indicating whether Perl would evaluate the SV as true or
868 false, defined or undefined. Does not handle 'get' magic.
870 =for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len
871 Like C<SvPV_force>, but converts sv to utf8 first if necessary.
873 =for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len
874 Like C<SvPV>, but converts sv to utf8 first if necessary.
876 =for apidoc Am|char*|SvPVutf8_nolen|SV* sv
877 Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
879 =for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len
880 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
882 =for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len
883 Like C<SvPV>, but converts sv to byte representation first if necessary.
885 =for apidoc Am|char*|SvPVbyte_nolen|SV* sv
886 Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
888 =for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len
889 Like C<SvPV_force>, but converts sv to utf8 first if necessary.
890 Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
893 =for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len
894 Like C<SvPV>, but converts sv to utf8 first if necessary.
895 Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
898 =for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len
899 Like C<SvPV_force>, but converts sv to byte representation first if necessary.
900 Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
903 =for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len
904 Like C<SvPV>, but converts sv to byte representation first if necessary.
905 Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
912 /* Let us hope that bitmaps for UV and IV are the same */
913 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
914 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
915 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
919 #define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC)
921 #define SvPV_flags(sv, lp, flags) \
922 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
923 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))
925 #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)
927 #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)
929 #define SvPV_force_flags(sv, lp, flags) \
930 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
931 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))
933 #define SvPV_nolen(sv) \
934 ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
935 ? SvPVX(sv) : sv_2pv_nolen(sv))
937 #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)
941 #define SvPVutf8(sv, lp) \
942 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
943 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
945 #define SvPVutf8_force(sv, lp) \
946 ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
947 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
950 #define SvPVutf8_nolen(sv) \
951 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
952 ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
956 #define SvPVbyte(sv, lp) \
957 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
958 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
960 #define SvPVbyte_force(sv, lp) \
961 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
962 ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
964 #define SvPVbyte_nolen(sv) \
965 ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
966 ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
970 /* define FOOx(): idempotent versions of FOO(). If possible, use a local
971 * var to evaluate the arg once; failing that, use a global if possible;
972 * failing that, call a function to do the work
975 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
976 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
977 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
979 #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)
981 # define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
982 # define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
983 # define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
984 # define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
985 # define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
986 # define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
987 # define SvTRUE(sv) ( \
991 ? (({XPV *nxpv = (XPV*)SvANY(sv); \
993 (nxpv->xpv_cur > 1 || \
994 (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \
1001 ? SvNVX(sv) != 0.0 \
1003 # define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
1005 #else /* __GNUC__ */
1007 /* These inlined macros use globals, which will require a thread
1008 * declaration in user code, so we avoid them under threads */
1010 # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
1011 # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
1012 # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
1013 # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
1014 # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
1015 # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
1016 # define SvTRUE(sv) ( \
1020 ? ((PL_Xpv = (XPV*)SvANY(sv)) && \
1021 (PL_Xpv->xpv_cur > 1 || \
1022 (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \
1029 ? SvNVX(sv) != 0.0 \
1031 # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
1032 #endif /* __GNU__ */
1034 #define SvIsCOW(sv) ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \
1035 (SVf_FAKE | SVf_READONLY))
1036 #define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0)
1038 /* flag values for sv_*_flags functions */
1039 #define SV_IMMEDIATE_UNREF 1
1041 #define SV_COW_DROP_PV 4
1042 #define SV_UTF8_NO_ENCODING 8
1044 /* We are about to replace the SV's current value. So if it's copy on write
1045 we need to normalise it. Use the SV_COW_DROP_PV flag hint to say that
1046 the value is about to get thrown away, so drop the PV rather than go to
1047 the effort of making a read-write copy only for it to get immediately
1050 #define SV_CHECK_THINKFIRST_COW_DROP(sv) if (SvTHINKFIRST(sv)) \
1051 sv_force_normal_flags(sv, SV_COW_DROP_PV)
1053 #ifdef PERL_COPY_ON_WRITE
1054 # define SvRELEASE_IVX(sv) ((void)((SvFLAGS(sv) & (SVf_OOK|SVf_READONLY|SVf_FAKE)) \
1055 && Perl_sv_release_IVX(aTHX_ sv)))
1056 # define SvIsCOW_normal(sv) (SvIsCOW(sv) && SvLEN(sv))
1058 # define SvRELEASE_IVX(sv) ((void)SvOOK_off(sv))
1059 #endif /* PERL_COPY_ON_WRITE */
1061 #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) \
1062 sv_force_normal_flags(sv, 0)
1065 /* all these 'functions' are now just macros */
1067 #define sv_pv(sv) SvPV_nolen(sv)
1068 #define sv_pvutf8(sv) SvPVutf8_nolen(sv)
1069 #define sv_pvbyte(sv) SvPVbyte_nolen(sv)
1071 #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0)
1072 #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0)
1073 #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0)
1074 #define sv_setsv(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC)
1075 #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0)
1076 #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC)
1077 #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0)
1078 #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC)
1079 #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC)
1080 #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0)
1081 #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC)
1082 #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC)
1086 =for apidoc Am|SV*|newRV_inc|SV* sv
1088 Creates an RV wrapper for an SV. The reference count for the original SV is
1094 #define newRV_inc(sv) newRV(sv)
1096 /* the following macros update any magic values this sv is associated with */
1099 =head1 Magical Functions
1101 =for apidoc Am|void|SvGETMAGIC|SV* sv
1102 Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1103 argument more than once.
1105 =for apidoc Am|void|SvSETMAGIC|SV* sv
1106 Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1107 argument more than once.
1109 =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1110 Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1113 =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1114 Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1115 ssv. May evaluate arguments more than once.
1117 =for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv
1118 Like C<SvSetSV>, but does any set magic required afterwards.
1120 =for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv
1121 Like C<SvSetMagicSV>, but does any set magic required afterwards.
1123 =for apidoc Am|void|SvSHARE|SV* sv
1124 Arranges for sv to be shared between threads if a suitable module
1127 =for apidoc Am|void|SvLOCK|SV* sv
1128 Arranges for a mutual exclusion lock to be obtained on sv if a suitable module
1131 =for apidoc Am|void|SvUNLOCK|SV* sv
1132 Releases a mutual exclusion lock on sv if a suitable module
1135 =head1 SV Manipulation Functions
1137 =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len
1138 Expands the character buffer in the SV so that it has room for the
1139 indicated number of bytes (remember to reserve space for an extra trailing
1140 NUL character). Calls C<sv_grow> to perform the expansion if necessary.
1141 Returns a pointer to the character buffer.
1146 #define SvSHARE(sv) CALL_FPTR(PL_sharehook)(aTHX_ sv)
1147 #define SvLOCK(sv) CALL_FPTR(PL_lockhook)(aTHX_ sv)
1148 #define SvUNLOCK(sv) CALL_FPTR(PL_unlockhook)(aTHX_ sv)
1150 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1151 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1153 #define SvSetSV_and(dst,src,finally) \
1155 if ((dst) != (src)) { \
1156 sv_setsv(dst, src); \
1160 #define SvSetSV_nosteal_and(dst,src,finally) \
1162 if ((dst) != (src)) { \
1163 U32 tMpF = SvFLAGS(src) & SVs_TEMP; \
1165 sv_setsv(dst, src); \
1166 SvFLAGS(src) |= tMpF; \
1171 #define SvSetSV(dst,src) \
1172 SvSetSV_and(dst,src,/*nothing*/;)
1173 #define SvSetSV_nosteal(dst,src) \
1174 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
1176 #define SvSetMagicSV(dst,src) \
1177 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1178 #define SvSetMagicSV_nosteal(dst,src) \
1179 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1181 #if !defined(SKIP_DEBUGGING)
1182 #define SvPEEK(sv) sv_peek(sv)
1184 #define SvPEEK(sv) ""
1187 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
1189 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
1191 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1193 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1194 #define Sv_Grow sv_grow
1196 #define CLONEf_COPY_STACKS 1
1197 #define CLONEf_KEEP_PTR_TABLE 2
1198 #define CLONEf_CLONE_HOST 4
1199 #define CLONEf_JOIN_IN 8
1201 struct clone_params {
1204 PerlInterpreter *proto_perl;