d9522c40f93fd6054477803c57ed8c384ff04b5d
[p5sagit/p5-mst-13.2.git] / sv.h
1 /*    sv.h
2  *
3  *    Copyright (c) 1991-2000, Larry Wall
4  *
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.
7  *
8  */
9
10 #ifdef sv_flags
11 #undef sv_flags         /* Convex has this in <signal.h> for sigvec() */
12 #endif
13
14 /*
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.
18
19 =for apidoc AmU||SVt_PV
20 Pointer type flag for scalars.  See C<svtype>.
21
22 =for apidoc AmU||SVt_IV
23 Integer type flag for scalars.  See C<svtype>.
24
25 =for apidoc AmU||SVt_NV
26 Double type flag for scalars.  See C<svtype>.
27
28 =for apidoc AmU||SVt_PVMG
29 Type flag for blessed scalars.  See C<svtype>.
30
31 =for apidoc AmU||SVt_PVAV
32 Type flag for arrays.  See C<svtype>.
33
34 =for apidoc AmU||SVt_PVHV
35 Type flag for hashes.  See C<svtype>.
36
37 =for apidoc AmU||SVt_PVCV
38 Type flag for code refs.  See C<svtype>.
39
40 =cut
41 */
42
43 typedef enum {
44         SVt_NULL,       /* 0 */
45         SVt_IV,         /* 1 */
46         SVt_NV,         /* 2 */
47         SVt_RV,         /* 3 */
48         SVt_PV,         /* 4 */
49         SVt_PVIV,       /* 5 */
50         SVt_PVNV,       /* 6 */
51         SVt_PVMG,       /* 7 */
52         SVt_PVBM,       /* 8 */
53         SVt_PVLV,       /* 9 */
54         SVt_PVAV,       /* 10 */
55         SVt_PVHV,       /* 11 */
56         SVt_PVCV,       /* 12 */
57         SVt_PVGV,       /* 13 */
58         SVt_PVFM,       /* 14 */
59         SVt_PVIO        /* 15 */
60 } svtype;
61
62 /* Using C's structural equivalence to help emulate C++ inheritance here... */
63
64 struct sv {
65     void*       sv_any;         /* pointer to something */
66     U32         sv_refcnt;      /* how many references to us */
67     U32         sv_flags;       /* what we are */
68 };
69
70 struct gv {
71     XPVGV*      sv_any;         /* pointer to something */
72     U32         sv_refcnt;      /* how many references to us */
73     U32         sv_flags;       /* what we are */
74 };
75
76 struct cv {
77     XPVCV*      sv_any;         /* pointer to something */
78     U32         sv_refcnt;      /* how many references to us */
79     U32         sv_flags;       /* what we are */
80 };
81
82 struct av {
83     XPVAV*      sv_any;         /* pointer to something */
84     U32         sv_refcnt;      /* how many references to us */
85     U32         sv_flags;       /* what we are */
86 };
87
88 struct hv {
89     XPVHV*      sv_any;         /* pointer to something */
90     U32         sv_refcnt;      /* how many references to us */
91     U32         sv_flags;       /* what we are */
92 };
93
94 struct io {
95     XPVIO*      sv_any;         /* pointer to something */
96     U32         sv_refcnt;      /* how many references to us */
97     U32         sv_flags;       /* what we are */
98 };
99
100 /*
101 =for apidoc Am|U32|SvREFCNT|SV* sv
102 Returns the value of the object's reference count.
103
104 =for apidoc Am|SV*|SvREFCNT_inc|SV* sv
105 Increments the reference count of the given SV.
106
107 =for apidoc Am|void|SvREFCNT_dec|SV* sv
108 Decrements the reference count of the given SV.
109
110 =for apidoc Am|svtype|SvTYPE|SV* sv
111 Returns the type of the SV.  See C<svtype>.
112
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>.
116
117 =cut
118 */
119
120 #define SvANY(sv)       (sv)->sv_any
121 #define SvFLAGS(sv)     (sv)->sv_flags
122 #define SvREFCNT(sv)    (sv)->sv_refcnt
123
124 #ifdef USE_THREADS
125
126 #  if defined(VMS)
127 #    define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count)
128 #    define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count))
129  #  else
130 #    ifdef EMULATE_ATOMIC_REFCOUNTS
131  #      define ATOMIC_INC(count) STMT_START {   \
132           MUTEX_LOCK(&PL_svref_mutex);          \
133           ++count;                              \
134           MUTEX_UNLOCK(&PL_svref_mutex);                \
135        } STMT_END
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);                        \
140        } STMT_END
141 #    else
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 */
145 #  endif /* VMS */
146 #else
147 #  define ATOMIC_INC(count) (++count)
148 #  define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0))
149 #endif /* USE_THREADS */
150
151 #ifdef __GNUC__
152 #  define SvREFCNT_inc(sv)              \
153     ({                                  \
154         SV *nsv = (SV*)(sv);            \
155         if (nsv)                        \
156              ATOMIC_INC(SvREFCNT(nsv)); \
157         nsv;                            \
158     })
159 #else
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)
164 #    else
165 #      define SvREFCNT_inc(sv) sv_newref((SV*)sv)
166 #    endif
167 #  else
168 #    define SvREFCNT_inc(sv)    \
169         ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv)
170 #  endif
171 #endif
172
173 #define SvREFCNT_dec(sv)        sv_free((SV*)sv)
174
175 #define SVTYPEMASK      0xff
176 #define SvTYPE(sv)      ((sv)->sv_flags & SVTYPEMASK)
177
178 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
179
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 */
188
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 */
193
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 */
198
199
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? */
204
205 #ifdef EBCDIC
206 #define SVf_UTF8        0x00000000      /* SvPVX is not UTF-8 encoded */
207 #else
208 #define SVf_UTF8        0x20000000      /* SvPVX is UTF-8 encoded */
209 #endif
210
211 #define SVf_THINKFIRST  (SVf_READONLY|SVf_ROK|SVf_FAKE|SVf_UTF8)
212
213 #define SVf_OK          (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \
214                          SVp_IOK|SVp_NOK|SVp_POK)
215
216 #define SVf_AMAGIC      0x10000000      /* has magical overloaded methods */
217
218 #define PRIVSHIFT 8
219
220 /* Some private flags. */
221
222 /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */
223 #define SVpad_OUR       0x80000000      /* pad name is "our" instead of "my" */
224
225 #define SVf_IVisUV      0x80000000      /* use XPVUV instead of XPVIV */
226
227 #define SVpfm_COMPILED  0x80000000      /* FORMLINE is compiled */
228
229 #define SVpbm_VALID     0x80000000
230 #define SVpbm_TAIL      0x40000000
231
232 #define SVrepl_EVAL     0x40000000      /* Replacement part of s///e */
233
234 #define SVphv_SHAREKEYS 0x20000000      /* keys live on shared string table */
235 #define SVphv_LAZYDEL   0x40000000      /* entry in xhv_eiter must be deleted */
236
237 #define SVprv_WEAKREF   0x80000000      /* Weak reference */
238
239 struct xrv {
240     SV *        xrv_rv;         /* pointer to another SV */
241 };
242
243 struct xpv {
244     char *      xpv_pv;         /* pointer to malloced string */
245     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
246     STRLEN      xpv_len;        /* allocated size */
247 };
248
249 struct xpviv {
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 };
255
256 struct xpvuv {
257     char *      xpv_pv;         /* pointer to malloced string */
258     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
259     STRLEN      xpv_len;        /* allocated size */
260     UV          xuv_uv;         /* unsigned value or pv offset */
261 };
262
263 struct xpvnv {
264     char *      xpv_pv;         /* pointer to malloced string */
265     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
266     STRLEN      xpv_len;        /* allocated size */
267     IV          xiv_iv;         /* integer value or pv offset */
268     NV          xnv_nv;         /* numeric value, if any */
269 };
270
271 /* These structure must match the beginning of struct xpvhv in hv.h. */
272 struct xpvmg {
273     char *      xpv_pv;         /* pointer to malloced string */
274     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
275     STRLEN      xpv_len;        /* allocated size */
276     IV          xiv_iv;         /* integer value or pv offset */
277     NV          xnv_nv;         /* numeric value, if any */
278     MAGIC*      xmg_magic;      /* linked list of magicalness */
279     HV*         xmg_stash;      /* class package */
280 };
281
282 struct xpvlv {
283     char *      xpv_pv;         /* pointer to malloced string */
284     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
285     STRLEN      xpv_len;        /* allocated size */
286     IV          xiv_iv;         /* integer value or pv offset */
287     NV          xnv_nv;         /* numeric value, if any */
288     MAGIC*      xmg_magic;      /* linked list of magicalness */
289     HV*         xmg_stash;      /* class package */
290
291     STRLEN      xlv_targoff;
292     STRLEN      xlv_targlen;
293     SV*         xlv_targ;
294     char        xlv_type;
295 };
296
297 struct xpvgv {
298     char *      xpv_pv;         /* pointer to malloced string */
299     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
300     STRLEN      xpv_len;        /* allocated size */
301     IV          xiv_iv;         /* integer value or pv offset */
302     NV          xnv_nv;         /* numeric value, if any */
303     MAGIC*      xmg_magic;      /* linked list of magicalness */
304     HV*         xmg_stash;      /* class package */
305
306     GP*         xgv_gp;
307     char*       xgv_name;
308     STRLEN      xgv_namelen;
309     HV*         xgv_stash;
310     U8          xgv_flags;
311 };
312
313 struct xpvbm {
314     char *      xpv_pv;         /* pointer to malloced string */
315     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
316     STRLEN      xpv_len;        /* allocated size */
317     IV          xiv_iv;         /* integer value or pv offset */
318     NV          xnv_nv;         /* numeric value, if any */
319     MAGIC*      xmg_magic;      /* linked list of magicalness */
320     HV*         xmg_stash;      /* class package */
321
322     I32         xbm_useful;     /* is this constant pattern being useful? */
323     U16         xbm_previous;   /* how many characters in string before rare? */
324     U8          xbm_rare;       /* rarest character in string */
325 };
326
327 /* This structure much match XPVCV in cv.h */
328
329 typedef U16 cv_flags_t;
330
331 struct xpvfm {
332     char *      xpv_pv;         /* pointer to malloced string */
333     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
334     STRLEN      xpv_len;        /* allocated size */
335     IV          xiv_iv;         /* integer value or pv offset */
336     NV          xnv_nv;         /* numeric value, if any */
337     MAGIC*      xmg_magic;      /* linked list of magicalness */
338     HV*         xmg_stash;      /* class package */
339
340     HV *        xcv_stash;
341     OP *        xcv_start;
342     OP *        xcv_root;
343     void      (*xcv_xsub)(pTHXo_ CV*);
344     ANY         xcv_xsubany;
345     GV *        xcv_gv;
346     char *      xcv_file;
347     long        xcv_depth;      /* >= 2 indicates recursive call */
348     AV *        xcv_padlist;
349     CV *        xcv_outside;
350 #ifdef USE_THREADS
351     perl_mutex *xcv_mutexp;     /* protects xcv_owner */
352     struct perl_thread *xcv_owner;      /* current owner thread */
353 #endif /* USE_THREADS */
354     cv_flags_t  xcv_flags;
355
356     I32         xfm_lines;
357 };
358
359 struct xpvio {
360     char *      xpv_pv;         /* pointer to malloced string */
361     STRLEN      xpv_cur;        /* length of xpv_pv as a C string */
362     STRLEN      xpv_len;        /* allocated size */
363     IV          xiv_iv;         /* integer value or pv offset */
364     NV          xnv_nv;         /* numeric value, if any */
365     MAGIC*      xmg_magic;      /* linked list of magicalness */
366     HV*         xmg_stash;      /* class package */
367
368     PerlIO *    xio_ifp;        /* ifp and ofp are normally the same */
369     PerlIO *    xio_ofp;        /* but sockets need separate streams */
370     /* Cray addresses everything by word boundaries (64 bits) and
371      * code and data pointers cannot be mixed (which is exactly what
372      * Perl_filter_add() tries to do with the dirp), hence the following
373      * union trick (as suggested by Gurusamy Sarathy).
374      * For further information see Geir Johansen's problem report titled
375        [ID 20000612.002] Perl problem on Cray system
376      * The any pointer (known as IoANY()) will also be a good place
377      * to hang any IO disciplines to.
378      */
379     union {
380         DIR *   xiou_dirp;      /* for opendir, readdir, etc */
381         void *  xiou_any;       /* for alignment */
382     } xio_dirpu;
383     long        xio_lines;      /* $. */
384     long        xio_page;       /* $% */
385     long        xio_page_len;   /* $= */
386     long        xio_lines_left; /* $- */
387     char *      xio_top_name;   /* $^ */
388     GV *        xio_top_gv;     /* $^ */
389     char *      xio_fmt_name;   /* $~ */
390     GV *        xio_fmt_gv;     /* $~ */
391     char *      xio_bottom_name;/* $^B */
392     GV *        xio_bottom_gv;  /* $^B */
393     short       xio_subprocess; /* -| or |- */
394     char        xio_type;
395     char        xio_flags;
396 };
397 #define xio_dirp        xio_dirpu.xiou_dirp
398 #define xio_any         xio_dirpu.xiou_any
399
400 #define IOf_ARGV        1       /* this fp iterates over ARGV */
401 #define IOf_START       2       /* check for null ARGV and substitute '-' */
402 #define IOf_FLUSH       4       /* this fp wants a flush after write op */
403 #define IOf_DIDTOP      8       /* just did top of form */
404 #define IOf_UNTAINT     16      /* consider this fp (and its data) "safe" */
405 #define IOf_NOLINE      32      /* slurped a pseudo-line from empty file */
406 #define IOf_FAKE_DIRP   64      /* xio_dirp is fake (source filters kludge) */
407
408 /* The following macros define implementation-independent predicates on SVs. */
409
410 /*
411 =for apidoc Am|bool|SvNIOK|SV* sv
412 Returns a boolean indicating whether the SV contains a number, integer or
413 double.
414
415 =for apidoc Am|bool|SvNIOKp|SV* sv
416 Returns a boolean indicating whether the SV contains a number, integer or
417 double.  Checks the B<private> setting.  Use C<SvNIOK>.
418
419 =for apidoc Am|void|SvNIOK_off|SV* sv
420 Unsets the NV/IV status of an SV.
421
422 =for apidoc Am|bool|SvOK|SV* sv
423 Returns a boolean indicating whether the value is an SV.
424
425 =for apidoc Am|bool|SvIOKp|SV* sv
426 Returns a boolean indicating whether the SV contains an integer.  Checks
427 the B<private> setting.  Use C<SvIOK>.
428
429 =for apidoc Am|bool|SvNOKp|SV* sv
430 Returns a boolean indicating whether the SV contains a double.  Checks the
431 B<private> setting.  Use C<SvNOK>.
432
433 =for apidoc Am|bool|SvPOKp|SV* sv
434 Returns a boolean indicating whether the SV contains a character string.
435 Checks the B<private> setting.  Use C<SvPOK>.
436
437 =for apidoc Am|bool|SvIOK|SV* sv
438 Returns a boolean indicating whether the SV contains an integer.
439
440 =for apidoc Am|void|SvIOK_on|SV* sv
441 Tells an SV that it is an integer.
442
443 =for apidoc Am|void|SvIOK_off|SV* sv
444 Unsets the IV status of an SV.
445
446 =for apidoc Am|void|SvIOK_only|SV* sv
447 Tells an SV that it is an integer and disables all other OK bits.
448
449 =for apidoc Am|void|SvIOK_only_UV|SV* sv
450 Tells and SV that it is an unsigned integer and disables all other OK bits.
451
452 =for apidoc Am|void|SvIOK_UV|SV* sv
453 Returns a boolean indicating whether the SV contains an unsigned integer.
454
455 =for apidoc Am|void|SvIOK_notUV|SV* sv
456 Returns a boolean indicating whether the SV contains an signed integer.
457
458 =for apidoc Am|bool|SvNOK|SV* sv
459 Returns a boolean indicating whether the SV contains a double.
460
461 =for apidoc Am|void|SvNOK_on|SV* sv
462 Tells an SV that it is a double.
463
464 =for apidoc Am|void|SvNOK_off|SV* sv
465 Unsets the NV status of an SV.
466
467 =for apidoc Am|void|SvNOK_only|SV* sv
468 Tells an SV that it is a double and disables all other OK bits.
469
470 =for apidoc Am|bool|SvPOK|SV* sv
471 Returns a boolean indicating whether the SV contains a character
472 string.
473
474 =for apidoc Am|void|SvPOK_on|SV* sv
475 Tells an SV that it is a string.
476
477 =for apidoc Am|void|SvPOK_off|SV* sv
478 Unsets the PV status of an SV.
479
480 =for apidoc Am|void|SvPOK_only|SV* sv
481 Tells an SV that it is a string and disables all other OK bits.
482
483 =for apidoc Am|bool|SvOOK|SV* sv
484 Returns a boolean indicating whether the SvIVX is a valid offset value for
485 the SvPVX.  This hack is used internally to speed up removal of characters
486 from the beginning of a SvPV.  When SvOOK is true, then the start of the
487 allocated string buffer is really (SvPVX - SvIVX).
488
489 =for apidoc Am|bool|SvROK|SV* sv
490 Tests if the SV is an RV.
491
492 =for apidoc Am|void|SvROK_on|SV* sv
493 Tells an SV that it is an RV.
494
495 =for apidoc Am|void|SvROK_off|SV* sv
496 Unsets the RV status of an SV.
497
498 =for apidoc Am|SV*|SvRV|SV* sv
499 Dereferences an RV to return the SV.
500
501 =for apidoc Am|IV|SvIVX|SV* sv
502 Returns the integer which is stored in the SV, assuming SvIOK is
503 true.
504
505 =for apidoc Am|UV|SvUVX|SV* sv
506 Returns the unsigned integer which is stored in the SV, assuming SvIOK is
507 true.
508
509 =for apidoc Am|NV|SvNVX|SV* sv
510 Returns the double which is stored in the SV, assuming SvNOK is
511 true.
512
513 =for apidoc Am|char*|SvPVX|SV* sv
514 Returns a pointer to the string in the SV.  The SV must contain a
515 string.
516
517 =for apidoc Am|STRLEN|SvCUR|SV* sv
518 Returns the length of the string which is in the SV.  See C<SvLEN>.
519
520 =for apidoc Am|STRLEN|SvLEN|SV* sv
521 Returns the size of the string buffer in the SV, not including any part
522 attributable to C<SvOOK>.  See C<SvCUR>.
523
524 =for apidoc Am|char*|SvEND|SV* sv
525 Returns a pointer to the last character in the string which is in the SV.
526 See C<SvCUR>.  Access the character as *(SvEND(sv)).
527
528 =for apidoc Am|HV*|SvSTASH|SV* sv
529 Returns the stash of the SV.
530
531 =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len
532 Set the length of the string which is in the SV.  See C<SvCUR>.
533
534 =cut
535 */
536
537 #define SvNIOK(sv)              (SvFLAGS(sv) & (SVf_IOK|SVf_NOK))
538 #define SvNIOKp(sv)             (SvFLAGS(sv) & (SVp_IOK|SVp_NOK))
539 #define SvNIOK_off(sv)          (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \
540                                                   SVp_IOK|SVp_NOK|SVf_IVisUV))
541
542 #define SvOK(sv)                (SvFLAGS(sv) & SVf_OK)
543 #define SvOK_off(sv)            (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|    \
544                                                   SVf_IVisUV|SVf_UTF8), \
545                                                         SvOOK_off(sv))
546 #define SvOK_off_exc_UV(sv)     (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|    \
547                                                   SVf_UTF8),            \
548                                                         SvOOK_off(sv))
549
550 #define SvOKp(sv)               (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK))
551 #define SvIOKp(sv)              (SvFLAGS(sv) & SVp_IOK)
552 #define SvIOKp_on(sv)           ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK)
553 #define SvNOKp(sv)              (SvFLAGS(sv) & SVp_NOK)
554 #define SvNOKp_on(sv)           (SvFLAGS(sv) |= SVp_NOK)
555 #define SvPOKp(sv)              (SvFLAGS(sv) & SVp_POK)
556 #define SvPOKp_on(sv)           (SvFLAGS(sv) |= SVp_POK)
557
558 #define SvIOK(sv)               (SvFLAGS(sv) & SVf_IOK)
559 #define SvIOK_on(sv)            ((void)SvOOK_off(sv), \
560                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
561 #define SvIOK_off(sv)           (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV))
562 #define SvIOK_only(sv)          ((void)SvOK_off(sv), \
563                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
564 #define SvIOK_only_UV(sv)       ((void)SvOK_off_exc_UV(sv), \
565                                     SvFLAGS(sv) |= (SVf_IOK|SVp_IOK))
566
567 #define SvIOK_UV(sv)            ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV))   \
568                                  == (SVf_IOK|SVf_IVisUV))
569 #define SvIOK_notUV(sv)         ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV))   \
570                                  == SVf_IOK)
571
572 #define SvIsUV(sv)              (SvFLAGS(sv) & SVf_IVisUV)
573 #define SvIsUV_on(sv)           (SvFLAGS(sv) |= SVf_IVisUV)
574 #define SvIsUV_off(sv)          (SvFLAGS(sv) &= ~SVf_IVisUV)
575
576 #define SvNOK(sv)               (SvFLAGS(sv) & SVf_NOK)
577 #define SvNOK_on(sv)            (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
578 #define SvNOK_off(sv)           (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK))
579 #define SvNOK_only(sv)          ((void)SvOK_off(sv), \
580                                     SvFLAGS(sv) |= (SVf_NOK|SVp_NOK))
581
582 /*
583 =for apidoc Am|void|SvUTF8|SV* sv
584 Returns a boolean indicating whether the SV contains UTF-8 encoded data.
585
586 =for apidoc Am|void|SvUTF8_on|SV *sv
587 Tells an SV that it is a string and encoded in UTF8.  Do not use frivolously.
588
589 =for apidoc Am|void|SvUTF8_off|SV *sv
590 Unsets the UTF8 status of an SV.
591
592 =for apidoc Am|void|SvPOK_only_UTF8|SV* sv
593 Tells an SV that it is a UTF8 string (do not use frivolously)
594 and disables all other OK bits.
595   
596 =cut
597  */
598
599 #define SvUTF8(sv)              (SvFLAGS(sv) & SVf_UTF8)
600 #define SvUTF8_on(sv)           (SvFLAGS(sv) |= (SVf_UTF8))
601 #define SvUTF8_off(sv)          (SvFLAGS(sv) &= ~(SVf_UTF8))
602
603 #define SvPOK(sv)               (SvFLAGS(sv) & SVf_POK)
604 #define SvPOK_on(sv)            (SvFLAGS(sv) |= (SVf_POK|SVp_POK))
605 #define SvPOK_off(sv)           (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK))
606 #define SvPOK_only(sv)          (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|    \
607                                                   SVf_IVisUV|SVf_UTF8), \
608                                     SvFLAGS(sv) |= (SVf_POK|SVp_POK))
609 #define SvPOK_only_UTF8(sv)     (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|    \
610                                                   SVf_IVisUV),          \
611                                     SvFLAGS(sv) |= (SVf_POK|SVp_POK))
612
613 #define SvOOK(sv)               (SvFLAGS(sv) & SVf_OOK)
614 #define SvOOK_on(sv)            ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK)
615 #define SvOOK_off(sv)           (SvOOK(sv) && sv_backoff(sv))
616
617 #define SvFAKE(sv)              (SvFLAGS(sv) & SVf_FAKE)
618 #define SvFAKE_on(sv)           (SvFLAGS(sv) |= SVf_FAKE)
619 #define SvFAKE_off(sv)          (SvFLAGS(sv) &= ~SVf_FAKE)
620
621 #define SvROK(sv)               (SvFLAGS(sv) & SVf_ROK)
622 #define SvROK_on(sv)            (SvFLAGS(sv) |= SVf_ROK)
623 #define SvROK_off(sv)           (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC))
624
625 #define SvMAGICAL(sv)           (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG))
626 #define SvMAGICAL_on(sv)        (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG))
627 #define SvMAGICAL_off(sv)       (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG))
628
629 #define SvGMAGICAL(sv)          (SvFLAGS(sv) & SVs_GMG)
630 #define SvGMAGICAL_on(sv)       (SvFLAGS(sv) |= SVs_GMG)
631 #define SvGMAGICAL_off(sv)      (SvFLAGS(sv) &= ~SVs_GMG)
632
633 #define SvSMAGICAL(sv)          (SvFLAGS(sv) & SVs_SMG)
634 #define SvSMAGICAL_on(sv)       (SvFLAGS(sv) |= SVs_SMG)
635 #define SvSMAGICAL_off(sv)      (SvFLAGS(sv) &= ~SVs_SMG)
636
637 #define SvRMAGICAL(sv)          (SvFLAGS(sv) & SVs_RMG)
638 #define SvRMAGICAL_on(sv)       (SvFLAGS(sv) |= SVs_RMG)
639 #define SvRMAGICAL_off(sv)      (SvFLAGS(sv) &= ~SVs_RMG)
640
641 #define SvAMAGIC(sv)            (SvFLAGS(sv) & SVf_AMAGIC)
642 #define SvAMAGIC_on(sv)         (SvFLAGS(sv) |= SVf_AMAGIC)
643 #define SvAMAGIC_off(sv)        (SvFLAGS(sv) &= ~SVf_AMAGIC)
644
645 #define SvGAMAGIC(sv)           (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC)) 
646
647 /*
648 #define Gv_AMG(stash) \
649         (HV_AMAGICmb(stash) && \
650          ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash)))
651 */
652 #define Gv_AMG(stash)           (PL_amagic_generation && Gv_AMupdate(stash))
653
654 #define SvWEAKREF(sv)           ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \
655                                   == (SVf_ROK|SVprv_WEAKREF))
656 #define SvWEAKREF_on(sv)        (SvFLAGS(sv) |=  (SVf_ROK|SVprv_WEAKREF))
657 #define SvWEAKREF_off(sv)       (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF))
658
659 #define SvTHINKFIRST(sv)        (SvFLAGS(sv) & SVf_THINKFIRST)
660
661 #define SvPADBUSY(sv)           (SvFLAGS(sv) & SVs_PADBUSY)
662
663 #define SvPADTMP(sv)            (SvFLAGS(sv) & SVs_PADTMP)
664 #define SvPADTMP_on(sv)         (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY)
665 #define SvPADTMP_off(sv)        (SvFLAGS(sv) &= ~SVs_PADTMP)
666
667 #define SvPADMY(sv)             (SvFLAGS(sv) & SVs_PADMY)
668 #define SvPADMY_on(sv)          (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY)
669
670 #define SvTEMP(sv)              (SvFLAGS(sv) & SVs_TEMP)
671 #define SvTEMP_on(sv)           (SvFLAGS(sv) |= SVs_TEMP)
672 #define SvTEMP_off(sv)          (SvFLAGS(sv) &= ~SVs_TEMP)
673
674 #define SvOBJECT(sv)            (SvFLAGS(sv) & SVs_OBJECT)
675 #define SvOBJECT_on(sv)         (SvFLAGS(sv) |= SVs_OBJECT)
676 #define SvOBJECT_off(sv)        (SvFLAGS(sv) &= ~SVs_OBJECT)
677
678 #define SvREADONLY(sv)          (SvFLAGS(sv) & SVf_READONLY)
679 #define SvREADONLY_on(sv)       (SvFLAGS(sv) |= SVf_READONLY)
680 #define SvREADONLY_off(sv)      (SvFLAGS(sv) &= ~SVf_READONLY)
681
682 #define SvSCREAM(sv)            (SvFLAGS(sv) & SVp_SCREAM)
683 #define SvSCREAM_on(sv)         (SvFLAGS(sv) |= SVp_SCREAM)
684 #define SvSCREAM_off(sv)        (SvFLAGS(sv) &= ~SVp_SCREAM)
685
686 #define SvCOMPILED(sv)          (SvFLAGS(sv) & SVpfm_COMPILED)
687 #define SvCOMPILED_on(sv)       (SvFLAGS(sv) |= SVpfm_COMPILED)
688 #define SvCOMPILED_off(sv)      (SvFLAGS(sv) &= ~SVpfm_COMPILED)
689
690 #define SvEVALED(sv)            (SvFLAGS(sv) & SVrepl_EVAL)
691 #define SvEVALED_on(sv)         (SvFLAGS(sv) |= SVrepl_EVAL)
692 #define SvEVALED_off(sv)        (SvFLAGS(sv) &= ~SVrepl_EVAL)
693
694 #define SvTAIL(sv)              (SvFLAGS(sv) & SVpbm_TAIL)
695 #define SvTAIL_on(sv)           (SvFLAGS(sv) |= SVpbm_TAIL)
696 #define SvTAIL_off(sv)          (SvFLAGS(sv) &= ~SVpbm_TAIL)
697
698 #define SvVALID(sv)             (SvFLAGS(sv) & SVpbm_VALID)
699 #define SvVALID_on(sv)          (SvFLAGS(sv) |= SVpbm_VALID)
700 #define SvVALID_off(sv)         (SvFLAGS(sv) &= ~SVpbm_VALID)
701
702 #define SvRV(sv) ((XRV*)  SvANY(sv))->xrv_rv
703 #define SvRVx(sv) SvRV(sv)
704
705 #define SvIVX(sv) ((XPVIV*)  SvANY(sv))->xiv_iv
706 #define SvIVXx(sv) SvIVX(sv)
707 #define SvUVX(sv) ((XPVUV*)  SvANY(sv))->xuv_uv
708 #define SvUVXx(sv) SvUVX(sv)
709 #define SvNVX(sv)  ((XPVNV*)SvANY(sv))->xnv_nv
710 #define SvNVXx(sv) SvNVX(sv)
711 #define SvPVX(sv)  ((XPV*)  SvANY(sv))->xpv_pv
712 #define SvPVXx(sv) SvPVX(sv)
713 #define SvCUR(sv) ((XPV*)  SvANY(sv))->xpv_cur
714 #define SvLEN(sv) ((XPV*)  SvANY(sv))->xpv_len
715 #define SvLENx(sv) SvLEN(sv)
716 #define SvEND(sv)(((XPV*)  SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur)
717 #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv))
718 #define SvMAGIC(sv)     ((XPVMG*)  SvANY(sv))->xmg_magic
719 #define SvSTASH(sv)     ((XPVMG*)  SvANY(sv))->xmg_stash
720
721 #define SvIV_set(sv, val) \
722         STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \
723                 (((XPVIV*)  SvANY(sv))->xiv_iv = val); } STMT_END
724 #define SvNV_set(sv, val) \
725         STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \
726                 (((XPVNV*)  SvANY(sv))->xnv_nv = val); } STMT_END
727 #define SvPV_set(sv, val) \
728         STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
729                 (((XPV*)  SvANY(sv))->xpv_pv = val); } STMT_END
730 #define SvCUR_set(sv, val) \
731         STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
732                 (((XPV*)  SvANY(sv))->xpv_cur = val); } STMT_END
733 #define SvLEN_set(sv, val) \
734         STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
735                 (((XPV*)  SvANY(sv))->xpv_len = val); } STMT_END
736 #define SvEND_set(sv, val) \
737         STMT_START { assert(SvTYPE(sv) >= SVt_PV); \
738                 (((XPV*)  SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END
739
740 #define BmRARE(sv)      ((XPVBM*)  SvANY(sv))->xbm_rare
741 #define BmUSEFUL(sv)    ((XPVBM*)  SvANY(sv))->xbm_useful
742 #define BmPREVIOUS(sv)  ((XPVBM*)  SvANY(sv))->xbm_previous
743
744 #define FmLINES(sv)     ((XPVFM*)  SvANY(sv))->xfm_lines
745
746 #define LvTYPE(sv)      ((XPVLV*)  SvANY(sv))->xlv_type
747 #define LvTARG(sv)      ((XPVLV*)  SvANY(sv))->xlv_targ
748 #define LvTARGOFF(sv)   ((XPVLV*)  SvANY(sv))->xlv_targoff
749 #define LvTARGLEN(sv)   ((XPVLV*)  SvANY(sv))->xlv_targlen
750
751 #define IoIFP(sv)       ((XPVIO*)  SvANY(sv))->xio_ifp
752 #define IoOFP(sv)       ((XPVIO*)  SvANY(sv))->xio_ofp
753 #define IoDIRP(sv)      ((XPVIO*)  SvANY(sv))->xio_dirp
754 #define IoANY(sv)       ((XPVIO*)  SvANY(sv))->xio_any
755 #define IoLINES(sv)     ((XPVIO*)  SvANY(sv))->xio_lines
756 #define IoPAGE(sv)      ((XPVIO*)  SvANY(sv))->xio_page
757 #define IoPAGE_LEN(sv)  ((XPVIO*)  SvANY(sv))->xio_page_len
758 #define IoLINES_LEFT(sv)((XPVIO*)  SvANY(sv))->xio_lines_left
759 #define IoTOP_NAME(sv)  ((XPVIO*)  SvANY(sv))->xio_top_name
760 #define IoTOP_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_top_gv
761 #define IoFMT_NAME(sv)  ((XPVIO*)  SvANY(sv))->xio_fmt_name
762 #define IoFMT_GV(sv)    ((XPVIO*)  SvANY(sv))->xio_fmt_gv
763 #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name
764 #define IoBOTTOM_GV(sv) ((XPVIO*)  SvANY(sv))->xio_bottom_gv
765 #define IoSUBPROCESS(sv)((XPVIO*)  SvANY(sv))->xio_subprocess
766 #define IoTYPE(sv)      ((XPVIO*)  SvANY(sv))->xio_type
767 #define IoFLAGS(sv)     ((XPVIO*)  SvANY(sv))->xio_flags
768
769 /* IoTYPE(sv) is a single character telling the type of I/O connection. */
770 #define IoTYPE_RDONLY   '<'
771 #define IoTYPE_WRONLY   '>'
772 #define IoTYPE_RDWR     '+'
773 #define IoTYPE_APPEND   'a'
774 #define IoTYPE_PIPE     '|'
775 #define IoTYPE_STD      '-'     /* stdin or stdout */
776 #define IoTYPE_SOCKET   's'
777 #define IoTYPE_CLOSED   ' '
778
779 /*
780 =for apidoc Am|bool|SvTAINTED|SV* sv
781 Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
782 not.
783
784 =for apidoc Am|void|SvTAINTED_on|SV* sv
785 Marks an SV as tainted.
786
787 =for apidoc Am|void|SvTAINTED_off|SV* sv
788 Untaints an SV. Be I<very> careful with this routine, as it short-circuits
789 some of Perl's fundamental security features. XS module authors should not
790 use this function unless they fully understand all the implications of
791 unconditionally untainting the value. Untainting should be done in the
792 standard perl fashion, via a carefully crafted regexp, rather than directly
793 untainting variables.
794
795 =for apidoc Am|void|SvTAINT|SV* sv
796 Taints an SV if tainting is enabled
797
798 =cut
799 */
800
801 #define SvTAINTED(sv)     (SvMAGICAL(sv) && sv_tainted(sv))
802 #define SvTAINTED_on(sv)  STMT_START{ if(PL_tainting){sv_taint(sv);}   }STMT_END
803 #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END
804
805 #define SvTAINT(sv)                     \
806     STMT_START {                        \
807         if (PL_tainting) {              \
808             dTHR;                       \
809             if (PL_tainted)             \
810                 SvTAINTED_on(sv);       \
811         }                               \
812     } STMT_END
813
814 /*
815 =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len
816 Like <SvPV> but will force the SV into becoming a string (SvPOK).  You want
817 force if you are going to update the SvPVX directly.
818
819 =for apidoc Am|char*|SvPV|SV* sv|STRLEN len
820 Returns a pointer to the string in the SV, or a stringified form of the SV
821 if the SV does not contain a string.  Handles 'get' magic.
822
823 =for apidoc Am|char*|SvPV_nolen|SV* sv
824 Returns a pointer to the string in the SV, or a stringified form of the SV
825 if the SV does not contain a string.  Handles 'get' magic.
826
827 =for apidoc Am|IV|SvIV|SV* sv
828 Coerces the given SV to an integer and returns it.
829
830 =for apidoc Am|NV|SvNV|SV* sv
831 Coerce the given SV to a double and return it.
832
833 =for apidoc Am|UV|SvUV|SV* sv
834 Coerces the given SV to an unsigned integer and returns it.
835
836 =for apidoc Am|bool|SvTRUE|SV* sv
837 Returns a boolean indicating whether Perl would evaluate the SV as true or
838 false, defined or undefined.  Does not handle 'get' magic.
839
840 =cut
841 */
842
843 #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp)
844 #define SvPV(sv, lp) sv_pvn(sv, &lp)
845 #define SvPV_nolen(sv) sv_pv(sv)
846
847 #define SvPVutf8_force(sv, lp) sv_pvutf8n_force(sv, &lp)
848 #define SvPVutf8(sv, lp) sv_pvutf8n(sv, &lp)
849 #define SvPVutf8_nolen(sv) sv_pvutf8(sv)
850
851 #define SvPVbyte_force(sv, lp) sv_pvbyte_force(sv, &lp)
852 #define SvPVbyte(sv, lp) sv_pvbyten(sv, &lp)
853 #define SvPVbyte_nolen(sv) sv_pvbyte(sv)
854
855 #define SvPVx(sv, lp) sv_pvn(sv, &lp)
856 #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)
857 #define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp)
858 #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)
859 #define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp)
860 #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)
861
862 #define SvIVx(sv) sv_iv(sv)
863 #define SvUVx(sv) sv_uv(sv)
864 #define SvNVx(sv) sv_nv(sv)
865
866 #define SvTRUEx(sv) sv_true(sv)
867
868 #define SvIV(sv) SvIVx(sv)
869 #define SvNV(sv) SvNVx(sv)
870 #define SvUV(sv) SvUVx(sv)
871 #define SvTRUE(sv) SvTRUEx(sv)
872
873 #ifndef CRIPPLED_CC
874 /* redefine some things to more efficient inlined versions */
875
876 /* Let us hope that bitmaps for UV and IV are the same */
877 #undef SvIV
878 #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
879
880 #undef SvUV
881 #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
882
883 #undef SvNV
884 #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))
885
886 #undef SvPV
887 #define SvPV(sv, lp) \
888     ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
889      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp))
890
891
892 #undef SvPV_force
893 #define SvPV_force(sv, lp) \
894     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \
895      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp))
896
897 #undef SvPV_nolen
898 #define SvPV_nolen(sv) \
899     ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \
900      ? SvPVX(sv) : sv_2pv_nolen(sv))
901
902 #undef SvPVutf8
903 #define SvPVutf8(sv, lp) \
904     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
905      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
906
907 #undef SvPVutf8_force
908 #define SvPVutf8_force(sv, lp) \
909     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
910      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
911
912 #undef SvPVutf8_nolen
913 #define SvPVutf8_nolen(sv) \
914     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
915      ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
916
917 #undef SvPVutf8
918 #define SvPVutf8(sv, lp) \
919     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \
920      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))
921
922 #undef SvPVutf8_force
923 #define SvPVutf8_force(sv, lp) \
924     ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \
925      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))
926
927 #undef SvPVutf8_nolen
928 #define SvPVutf8_nolen(sv) \
929     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\
930      ? SvPVX(sv) : sv_2pvutf8_nolen(sv))
931
932 #undef SvPVbyte
933 #define SvPVbyte(sv, lp) \
934     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
935      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))
936
937 #undef SvPVbyte_force
938 #define SvPVbyte_force(sv, lp) \
939     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \
940      ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyte_force(sv, &lp))
941
942 #undef SvPVbyte_nolen
943 #define SvPVbyte_nolen(sv) \
944     ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\
945      ? SvPVX(sv) : sv_2pvbyte_nolen(sv))
946
947
948 #ifdef __GNUC__
949 #  undef SvIVx
950 #  undef SvUVx
951 #  undef SvNVx
952 #  undef SvPVx
953 #  undef SvPVutf8x
954 #  undef SvPVbytex
955 #  undef SvTRUE
956 #  undef SvTRUEx
957 #  define SvIVx(sv) ({SV *nsv = (SV*)(sv); SvIV(nsv); })
958 #  define SvUVx(sv) ({SV *nsv = (SV*)(sv); SvUV(nsv); })
959 #  define SvNVx(sv) ({SV *nsv = (SV*)(sv); SvNV(nsv); })
960 #  define SvPVx(sv, lp) ({SV *nsv = (sv); SvPV(nsv, lp); })
961 #  define SvPVutf8x(sv, lp) ({SV *nsv = (sv); SvPVutf8(nsv, lp); })
962 #  define SvPVbytex(sv, lp) ({SV *nsv = (sv); SvPVbyte(nsv, lp); })
963 #  define SvTRUE(sv) (                                          \
964     !sv                                                         \
965     ? 0                                                         \
966     :    SvPOK(sv)                                              \
967         ?   (({XPV *nxpv = (XPV*)SvANY(sv);                     \
968              nxpv &&                                            \
969              (nxpv->xpv_cur > 1 ||                              \
970               (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); })      \
971              ? 1                                                \
972              : 0)                                               \
973         :                                                       \
974             SvIOK(sv)                                           \
975             ? SvIVX(sv) != 0                                    \
976             :   SvNOK(sv)                                       \
977                 ? SvNVX(sv) != 0.0                              \
978                 : sv_2bool(sv) )
979 #  define SvTRUEx(sv) ({SV *nsv = (sv); SvTRUE(nsv); })
980 #else /* __GNUC__ */
981 #ifndef USE_THREADS
982 /* These inlined macros use globals, which will require a thread
983  * declaration in user code, so we avoid them under threads */
984
985 #  undef SvIVx
986 #  undef SvUVx
987 #  undef SvNVx
988 #  undef SvPVx
989 #  undef SvPVutf8x
990 #  undef SvPVbytex
991 #  undef SvTRUE
992 #  undef SvTRUEx
993 #  define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))
994 #  define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))
995 #  define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))
996 #  define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))
997 #  define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))
998 #  define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))
999 #  define SvTRUE(sv) (                                          \
1000     !sv                                                         \
1001     ? 0                                                         \
1002     :    SvPOK(sv)                                              \
1003         ?   ((PL_Xpv = (XPV*)SvANY(sv)) &&                      \
1004              (PL_Xpv->xpv_cur > 1 ||                            \
1005               (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0'))      \
1006              ? 1                                                \
1007              : 0)                                               \
1008         :                                                       \
1009             SvIOK(sv)                                           \
1010             ? SvIVX(sv) != 0                                    \
1011             :   SvNOK(sv)                                       \
1012                 ? SvNVX(sv) != 0.0                              \
1013                 : sv_2bool(sv) )
1014 #  define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))
1015 #endif /* !USE_THREADS */
1016 #endif /* !__GNU__ */
1017 #endif /* !CRIPPLED_CC */
1018
1019 /*
1020 =for apidoc Am|SV*|newRV_inc|SV* sv
1021
1022 Creates an RV wrapper for an SV.  The reference count for the original SV is
1023 incremented.
1024
1025 =cut
1026 */
1027
1028 #define newRV_inc(sv)   newRV(sv)
1029
1030 /* the following macros update any magic values this sv is associated with */
1031
1032 /*
1033 =for apidoc Am|void|SvGETMAGIC|SV* sv
1034 Invokes C<mg_get> on an SV if it has 'get' magic.  This macro evaluates its
1035 argument more than once.
1036
1037 =for apidoc Am|void|SvSETMAGIC|SV* sv
1038 Invokes C<mg_set> on an SV if it has 'set' magic.  This macro evaluates its
1039 argument more than once.
1040
1041 =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv
1042 Calls C<sv_setsv> if dsv is not the same as ssv.  May evaluate arguments
1043 more than once.
1044
1045 =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv
1046 Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1047 ssv. May evaluate arguments more than once.
1048
1049 =for apidoc Am|void|SvGROW|SV* sv|STRLEN len
1050 Expands the character buffer in the SV so that it has room for the
1051 indicated number of bytes (remember to reserve space for an extra trailing
1052 NUL character).  Calls C<sv_grow> to perform the expansion if necessary. 
1053 Returns a pointer to the character buffer.
1054
1055 =cut
1056 */
1057
1058 #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END
1059 #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END
1060
1061 #define SvSetSV_and(dst,src,finally) \
1062         STMT_START {                                    \
1063             if ((dst) != (src)) {                       \
1064                 sv_setsv(dst, src);                     \
1065                 finally;                                \
1066             }                                           \
1067         } STMT_END
1068 #define SvSetSV_nosteal_and(dst,src,finally) \
1069         STMT_START {                                    \
1070             if ((dst) != (src)) {                       \
1071                 U32 tMpF = SvFLAGS(src) & SVs_TEMP;     \
1072                 SvTEMP_off(src);                        \
1073                 sv_setsv(dst, src);                     \
1074                 SvFLAGS(src) |= tMpF;                   \
1075                 finally;                                \
1076             }                                           \
1077         } STMT_END
1078
1079 #define SvSetSV(dst,src) \
1080                 SvSetSV_and(dst,src,/*nothing*/;)
1081 #define SvSetSV_nosteal(dst,src) \
1082                 SvSetSV_nosteal_and(dst,src,/*nothing*/;)
1083
1084 #define SvSetMagicSV(dst,src) \
1085                 SvSetSV_and(dst,src,SvSETMAGIC(dst))
1086 #define SvSetMagicSV_nosteal(dst,src) \
1087                 SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst))
1088
1089 #ifdef DEBUGGING
1090 #define SvPEEK(sv) sv_peek(sv)
1091 #else
1092 #define SvPEEK(sv) ""
1093 #endif
1094
1095 #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no)
1096
1097 #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
1098
1099 #define isGV(sv) (SvTYPE(sv) == SVt_PVGV)
1100
1101 #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv))
1102 #define Sv_Grow sv_grow
1103