home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / sv.h < prev    next >
C/C++ Source or Header  |  2000-03-09  |  33KB  |  1,035 lines

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