Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1101 lines
36 KiB

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