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