| 1 | /* sv.h |
| 2 | * |
| 3 | * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
| 4 | * 2000, 2001, 2002, 2003, 2004, 2005, 2006 by Larry Wall and others |
| 5 | * |
| 6 | * You may distribute under the terms of either the GNU General Public |
| 7 | * License or the Artistic License, as specified in the README file. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #ifdef sv_flags |
| 12 | #undef sv_flags /* Convex has this in <signal.h> for sigvec() */ |
| 13 | #endif |
| 14 | |
| 15 | /* |
| 16 | =head1 SV Flags |
| 17 | |
| 18 | =for apidoc AmU||svtype |
| 19 | An enum of flags for Perl types. These are found in the file B<sv.h> |
| 20 | in the C<svtype> enum. Test these flags with the C<SvTYPE> macro. |
| 21 | |
| 22 | =for apidoc AmU||SVt_PV |
| 23 | Pointer type flag for scalars. See C<svtype>. |
| 24 | |
| 25 | =for apidoc AmU||SVt_IV |
| 26 | Integer type flag for scalars. See C<svtype>. |
| 27 | |
| 28 | =for apidoc AmU||SVt_NV |
| 29 | Double type flag for scalars. See C<svtype>. |
| 30 | |
| 31 | =for apidoc AmU||SVt_PVMG |
| 32 | Type flag for blessed scalars. See C<svtype>. |
| 33 | |
| 34 | =for apidoc AmU||SVt_PVAV |
| 35 | Type flag for arrays. See C<svtype>. |
| 36 | |
| 37 | =for apidoc AmU||SVt_PVHV |
| 38 | Type flag for hashes. See C<svtype>. |
| 39 | |
| 40 | =for apidoc AmU||SVt_PVCV |
| 41 | Type flag for code refs. See C<svtype>. |
| 42 | |
| 43 | =cut |
| 44 | */ |
| 45 | |
| 46 | typedef enum { |
| 47 | SVt_NULL, /* 0 */ |
| 48 | SVt_IV, /* 1 */ |
| 49 | SVt_NV, /* 2 */ |
| 50 | SVt_RV, /* 3 */ |
| 51 | SVt_PV, /* 4 */ |
| 52 | SVt_PVIV, /* 5 */ |
| 53 | SVt_PVNV, /* 6 */ |
| 54 | SVt_PVMG, /* 7 */ |
| 55 | SVt_PVBM, /* 8 */ |
| 56 | SVt_PVLV, /* 9 */ |
| 57 | SVt_PVAV, /* 10 */ |
| 58 | SVt_PVHV, /* 11 */ |
| 59 | SVt_PVCV, /* 12 */ |
| 60 | SVt_PVGV, /* 13 */ |
| 61 | SVt_PVFM, /* 14 */ |
| 62 | SVt_PVIO /* 15 */ |
| 63 | } svtype; |
| 64 | |
| 65 | /* Using C's structural equivalence to help emulate C++ inheritance here... */ |
| 66 | |
| 67 | struct STRUCT_SV { /* struct sv { */ |
| 68 | void* sv_any; /* pointer to something */ |
| 69 | U32 sv_refcnt; /* how many references to us */ |
| 70 | U32 sv_flags; /* what we are */ |
| 71 | }; |
| 72 | |
| 73 | struct gv { |
| 74 | XPVGV* sv_any; /* pointer to something */ |
| 75 | U32 sv_refcnt; /* how many references to us */ |
| 76 | U32 sv_flags; /* what we are */ |
| 77 | }; |
| 78 | |
| 79 | struct cv { |
| 80 | XPVCV* sv_any; /* pointer to something */ |
| 81 | U32 sv_refcnt; /* how many references to us */ |
| 82 | U32 sv_flags; /* what we are */ |
| 83 | }; |
| 84 | |
| 85 | struct av { |
| 86 | XPVAV* sv_any; /* pointer to something */ |
| 87 | U32 sv_refcnt; /* how many references to us */ |
| 88 | U32 sv_flags; /* what we are */ |
| 89 | }; |
| 90 | |
| 91 | struct hv { |
| 92 | XPVHV* sv_any; /* pointer to something */ |
| 93 | U32 sv_refcnt; /* how many references to us */ |
| 94 | U32 sv_flags; /* what we are */ |
| 95 | }; |
| 96 | |
| 97 | struct io { |
| 98 | XPVIO* sv_any; /* pointer to something */ |
| 99 | U32 sv_refcnt; /* how many references to us */ |
| 100 | U32 sv_flags; /* what we are */ |
| 101 | }; |
| 102 | |
| 103 | /* |
| 104 | =head1 SV Manipulation Functions |
| 105 | |
| 106 | =for apidoc Am|U32|SvREFCNT|SV* sv |
| 107 | Returns the value of the object's reference count. |
| 108 | |
| 109 | =for apidoc Am|SV*|SvREFCNT_inc|SV* sv |
| 110 | Increments the reference count of the given SV. |
| 111 | |
| 112 | =for apidoc Am|void|SvREFCNT_dec|SV* sv |
| 113 | Decrements the reference count of the given SV. |
| 114 | |
| 115 | =for apidoc Am|svtype|SvTYPE|SV* sv |
| 116 | Returns the type of the SV. See C<svtype>. |
| 117 | |
| 118 | =for apidoc Am|void|SvUPGRADE|SV* sv|svtype type |
| 119 | Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to |
| 120 | perform the upgrade if necessary. See C<svtype>. |
| 121 | |
| 122 | =cut |
| 123 | */ |
| 124 | |
| 125 | #define SvANY(sv) (sv)->sv_any |
| 126 | #define SvFLAGS(sv) (sv)->sv_flags |
| 127 | #define SvREFCNT(sv) (sv)->sv_refcnt |
| 128 | |
| 129 | #ifdef USE_5005THREADS |
| 130 | |
| 131 | # if defined(VMS) |
| 132 | # define ATOMIC_INC(count) __ATOMIC_INCREMENT_LONG(&count) |
| 133 | # define ATOMIC_DEC_AND_TEST(res,count) res=(1==__ATOMIC_DECREMENT_LONG(&count)) |
| 134 | # else |
| 135 | # ifdef EMULATE_ATOMIC_REFCOUNTS |
| 136 | # define ATOMIC_INC(count) STMT_START { \ |
| 137 | MUTEX_LOCK(&PL_svref_mutex); \ |
| 138 | ++count; \ |
| 139 | MUTEX_UNLOCK(&PL_svref_mutex); \ |
| 140 | } STMT_END |
| 141 | # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \ |
| 142 | MUTEX_LOCK(&PL_svref_mutex); \ |
| 143 | res = (--count == 0); \ |
| 144 | MUTEX_UNLOCK(&PL_svref_mutex); \ |
| 145 | } STMT_END |
| 146 | # else |
| 147 | # define ATOMIC_INC(count) atomic_inc(&count) |
| 148 | # define ATOMIC_DEC_AND_TEST(res,count) (res = atomic_dec_and_test(&count)) |
| 149 | # endif /* EMULATE_ATOMIC_REFCOUNTS */ |
| 150 | # endif /* VMS */ |
| 151 | #else |
| 152 | # define ATOMIC_INC(count) (++count) |
| 153 | # define ATOMIC_DEC_AND_TEST(res, count) (res = (--count == 0)) |
| 154 | #endif /* USE_5005THREADS */ |
| 155 | |
| 156 | #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC) |
| 157 | # define SvREFCNT_inc(sv) \ |
| 158 | ({ \ |
| 159 | SV * const _sv = (SV*)(sv); \ |
| 160 | if (_sv) \ |
| 161 | ATOMIC_INC(SvREFCNT(_sv)); \ |
| 162 | _sv; \ |
| 163 | }) |
| 164 | #else |
| 165 | # ifdef USE_5005THREADS |
| 166 | # if defined(VMS) && defined(__ALPHA) |
| 167 | # define SvREFCNT_inc(sv) \ |
| 168 | (PL_Sv=(SV*)(sv), (PL_Sv && __ATOMIC_INCREMENT_LONG(&(SvREFCNT(PL_Sv)))), (SV *)PL_Sv) |
| 169 | # else |
| 170 | # define SvREFCNT_inc(sv) sv_newref((SV*)sv) |
| 171 | # endif |
| 172 | # else |
| 173 | # define SvREFCNT_inc(sv) \ |
| 174 | ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv) |
| 175 | # endif |
| 176 | #endif |
| 177 | |
| 178 | #define SvREFCNT_dec(sv) sv_free((SV*)(sv)) |
| 179 | |
| 180 | #define SVTYPEMASK 0xff |
| 181 | #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) |
| 182 | |
| 183 | #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt)) |
| 184 | |
| 185 | #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */ |
| 186 | #define SVs_PADTMP 0x00000200 /* in use as tmp */ |
| 187 | #define SVs_PADMY 0x00000400 /* in use a "my" variable */ |
| 188 | #define SVs_TEMP 0x00000800 /* string is stealable? */ |
| 189 | #define SVs_OBJECT 0x00001000 /* is "blessed" */ |
| 190 | #define SVs_GMG 0x00002000 /* has magical get method */ |
| 191 | #define SVs_SMG 0x00004000 /* has magical set method */ |
| 192 | #define SVs_RMG 0x00008000 /* has random magical methods */ |
| 193 | |
| 194 | #define SVf_IOK 0x00010000 /* has valid public integer value */ |
| 195 | #define SVf_NOK 0x00020000 /* has valid public numeric value */ |
| 196 | #define SVf_POK 0x00040000 /* has valid public pointer value */ |
| 197 | #define SVf_ROK 0x00080000 /* has a valid reference pointer */ |
| 198 | |
| 199 | #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */ |
| 200 | #define SVf_OOK 0x00200000 /* has valid offset value */ |
| 201 | #define SVf_BREAK 0x00400000 /* refcnt is artificially low - used |
| 202 | * by SV's in final arena cleanup */ |
| 203 | #define SVf_READONLY 0x00800000 /* may not be modified */ |
| 204 | |
| 205 | |
| 206 | #define SVp_IOK 0x01000000 /* has valid non-public integer value */ |
| 207 | #define SVp_NOK 0x02000000 /* has valid non-public numeric value */ |
| 208 | #define SVp_POK 0x04000000 /* has valid non-public pointer value */ |
| 209 | #define SVp_SCREAM 0x08000000 /* has been studied? */ |
| 210 | |
| 211 | #define SVf_UTF8 0x20000000 /* SvPV is UTF-8 encoded */ |
| 212 | |
| 213 | #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE) |
| 214 | |
| 215 | #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ |
| 216 | SVp_IOK|SVp_NOK|SVp_POK) |
| 217 | |
| 218 | #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ |
| 219 | |
| 220 | #define PRIVSHIFT 8 /* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */ |
| 221 | |
| 222 | /* Some private flags. */ |
| 223 | |
| 224 | /* SVpad_OUR may be set on SVt_PV{NV,MG,GV} types */ |
| 225 | #define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */ |
| 226 | #define SVpad_TYPED 0x40000000 /* Typed Lexical */ |
| 227 | |
| 228 | #define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */ |
| 229 | |
| 230 | #define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */ |
| 231 | |
| 232 | #define SVpbm_VALID 0x80000000 |
| 233 | #define SVpbm_TAIL 0x40000000 |
| 234 | |
| 235 | #define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */ |
| 236 | |
| 237 | #define SVphv_CLONEABLE 0x08000000 /* for stashes: clone its objects */ |
| 238 | #define SVphv_REHASH 0x10000000 /* HV is recalculating hash values */ |
| 239 | #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ |
| 240 | #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */ |
| 241 | #define SVphv_HASKFLAGS 0x80000000 /* keys have flag byte after hash */ |
| 242 | |
| 243 | #define SVprv_WEAKREF 0x80000000 /* Weak reference */ |
| 244 | |
| 245 | struct xrv { |
| 246 | SV * xrv_rv; /* pointer to another SV */ |
| 247 | }; |
| 248 | |
| 249 | struct xpv { |
| 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 | }; |
| 254 | |
| 255 | struct xpviv { |
| 256 | char * xpv_pv; /* pointer to malloced string */ |
| 257 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 258 | STRLEN xpv_len; /* allocated size */ |
| 259 | IV xiv_iv; /* integer value or pv offset */ |
| 260 | }; |
| 261 | |
| 262 | struct xpvuv { |
| 263 | char * xpv_pv; /* pointer to malloced string */ |
| 264 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 265 | STRLEN xpv_len; /* allocated size */ |
| 266 | UV xuv_uv; /* unsigned value or pv offset */ |
| 267 | }; |
| 268 | |
| 269 | struct xpvnv { |
| 270 | char * xpv_pv; /* pointer to malloced string */ |
| 271 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 272 | STRLEN xpv_len; /* allocated size */ |
| 273 | IV xiv_iv; /* integer value or pv offset */ |
| 274 | NV xnv_nv; /* numeric value, if any */ |
| 275 | }; |
| 276 | |
| 277 | /* These structure must match the beginning of struct xpvhv in hv.h. */ |
| 278 | struct xpvmg { |
| 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 | |
| 288 | struct xpvlv { |
| 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 | |
| 297 | STRLEN xlv_targoff; |
| 298 | STRLEN xlv_targlen; |
| 299 | SV* xlv_targ; |
| 300 | char xlv_type; /* k=keys .=pos x=substr v=vec /=join/re |
| 301 | * y=alem/helem/iter t=tie T=tied HE */ |
| 302 | }; |
| 303 | |
| 304 | struct xpvgv { |
| 305 | char * xpv_pv; /* pointer to malloced string */ |
| 306 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 307 | STRLEN xpv_len; /* allocated size */ |
| 308 | IV xiv_iv; /* integer value or pv offset */ |
| 309 | NV xnv_nv; /* numeric value, if any */ |
| 310 | MAGIC* xmg_magic; /* linked list of magicalness */ |
| 311 | HV* xmg_stash; /* class package */ |
| 312 | |
| 313 | GP* xgv_gp; |
| 314 | char* xgv_name; |
| 315 | STRLEN xgv_namelen; |
| 316 | HV* xgv_stash; |
| 317 | U8 xgv_flags; |
| 318 | }; |
| 319 | |
| 320 | struct xpvbm { |
| 321 | char * xpv_pv; /* pointer to malloced string */ |
| 322 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 323 | STRLEN xpv_len; /* allocated size */ |
| 324 | IV xiv_iv; /* integer value or pv offset */ |
| 325 | NV xnv_nv; /* numeric value, if any */ |
| 326 | MAGIC* xmg_magic; /* linked list of magicalness */ |
| 327 | HV* xmg_stash; /* class package */ |
| 328 | |
| 329 | I32 xbm_useful; /* is this constant pattern being useful? */ |
| 330 | U16 xbm_previous; /* how many characters in string before rare? */ |
| 331 | U8 xbm_rare; /* rarest character in string */ |
| 332 | }; |
| 333 | |
| 334 | /* This structure must match XPVCV in cv.h */ |
| 335 | |
| 336 | typedef U16 cv_flags_t; |
| 337 | |
| 338 | struct xpvfm { |
| 339 | char * xpv_pv; /* pointer to malloced string */ |
| 340 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 341 | STRLEN xpv_len; /* allocated size */ |
| 342 | IV xiv_iv; /* integer value or pv offset */ |
| 343 | NV xnv_nv; /* numeric value, if any */ |
| 344 | MAGIC* xmg_magic; /* linked list of magicalness */ |
| 345 | HV* xmg_stash; /* class package */ |
| 346 | |
| 347 | HV * xcv_stash; |
| 348 | OP * xcv_start; |
| 349 | OP * xcv_root; |
| 350 | void (*xcv_xsub)(pTHX_ CV*); |
| 351 | ANY xcv_xsubany; |
| 352 | GV * xcv_gv; |
| 353 | char * xcv_file; |
| 354 | long xcv_depth; /* >= 2 indicates recursive call */ |
| 355 | AV * xcv_padlist; |
| 356 | CV * xcv_outside; |
| 357 | #ifdef USE_5005THREADS |
| 358 | perl_mutex *xcv_mutexp; /* protects xcv_owner */ |
| 359 | struct perl_thread *xcv_owner; /* current owner thread */ |
| 360 | #endif /* USE_5005THREADS */ |
| 361 | cv_flags_t xcv_flags; |
| 362 | U32 xcv_outside_seq; /* the COP sequence (at the point of our |
| 363 | * compilation) in the lexically enclosing |
| 364 | * sub */ |
| 365 | IV xfm_lines; |
| 366 | }; |
| 367 | |
| 368 | struct xpvio { |
| 369 | char * xpv_pv; /* pointer to malloced string */ |
| 370 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
| 371 | STRLEN xpv_len; /* allocated size */ |
| 372 | IV xiv_iv; /* integer value or pv offset */ |
| 373 | NV xnv_nv; /* numeric value, if any */ |
| 374 | MAGIC* xmg_magic; /* linked list of magicalness */ |
| 375 | HV* xmg_stash; /* class package */ |
| 376 | |
| 377 | PerlIO * xio_ifp; /* ifp and ofp are normally the same */ |
| 378 | PerlIO * xio_ofp; /* but sockets need separate streams */ |
| 379 | /* Cray addresses everything by word boundaries (64 bits) and |
| 380 | * code and data pointers cannot be mixed (which is exactly what |
| 381 | * Perl_filter_add() tries to do with the dirp), hence the following |
| 382 | * union trick (as suggested by Gurusamy Sarathy). |
| 383 | * For further information see Geir Johansen's problem report titled |
| 384 | [ID 20000612.002] Perl problem on Cray system |
| 385 | * The any pointer (known as IoANY()) will also be a good place |
| 386 | * to hang any IO disciplines to. |
| 387 | */ |
| 388 | union { |
| 389 | DIR * xiou_dirp; /* for opendir, readdir, etc */ |
| 390 | void * xiou_any; /* for alignment */ |
| 391 | } xio_dirpu; |
| 392 | IV xio_lines; /* $. */ |
| 393 | IV xio_page; /* $% */ |
| 394 | IV xio_page_len; /* $= */ |
| 395 | IV xio_lines_left; /* $- */ |
| 396 | char * xio_top_name; /* $^ */ |
| 397 | GV * xio_top_gv; /* $^ */ |
| 398 | char * xio_fmt_name; /* $~ */ |
| 399 | GV * xio_fmt_gv; /* $~ */ |
| 400 | char * xio_bottom_name;/* $^B */ |
| 401 | GV * xio_bottom_gv; /* $^B */ |
| 402 | short xio_subprocess; /* -| or |- */ |
| 403 | char xio_type; |
| 404 | char xio_flags; |
| 405 | }; |
| 406 | #define xio_dirp xio_dirpu.xiou_dirp |
| 407 | #define xio_any xio_dirpu.xiou_any |
| 408 | |
| 409 | #define IOf_ARGV 1 /* this fp iterates over ARGV */ |
| 410 | #define IOf_START 2 /* check for null ARGV and substitute '-' */ |
| 411 | #define IOf_FLUSH 4 /* this fp wants a flush after write op */ |
| 412 | #define IOf_DIDTOP 8 /* just did top of form */ |
| 413 | #define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */ |
| 414 | #define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */ |
| 415 | #define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */ |
| 416 | |
| 417 | /* The following macros define implementation-independent predicates on SVs. */ |
| 418 | |
| 419 | /* |
| 420 | =for apidoc Am|bool|SvNIOK|SV* sv |
| 421 | Returns a boolean indicating whether the SV contains a number, integer or |
| 422 | double. |
| 423 | |
| 424 | =for apidoc Am|bool|SvNIOKp|SV* sv |
| 425 | Returns a boolean indicating whether the SV contains a number, integer or |
| 426 | double. Checks the B<private> setting. Use C<SvNIOK>. |
| 427 | |
| 428 | =for apidoc Am|void|SvNIOK_off|SV* sv |
| 429 | Unsets the NV/IV status of an SV. |
| 430 | |
| 431 | =for apidoc Am|bool|SvOK|SV* sv |
| 432 | Returns a boolean indicating whether the value is an SV. It also tells |
| 433 | whether the value is defined or not. |
| 434 | |
| 435 | =for apidoc Am|bool|SvIOKp|SV* sv |
| 436 | Returns a boolean indicating whether the SV contains an integer. Checks |
| 437 | the B<private> setting. Use C<SvIOK>. |
| 438 | |
| 439 | =for apidoc Am|bool|SvNOKp|SV* sv |
| 440 | Returns a boolean indicating whether the SV contains a double. Checks the |
| 441 | B<private> setting. Use C<SvNOK>. |
| 442 | |
| 443 | =for apidoc Am|bool|SvPOKp|SV* sv |
| 444 | Returns a boolean indicating whether the SV contains a character string. |
| 445 | Checks the B<private> setting. Use C<SvPOK>. |
| 446 | |
| 447 | =for apidoc Am|bool|SvIOK|SV* sv |
| 448 | Returns a boolean indicating whether the SV contains an integer. |
| 449 | |
| 450 | =for apidoc Am|void|SvIOK_on|SV* sv |
| 451 | Tells an SV that it is an integer. |
| 452 | |
| 453 | =for apidoc Am|void|SvIOK_off|SV* sv |
| 454 | Unsets the IV status of an SV. |
| 455 | |
| 456 | =for apidoc Am|void|SvIOK_only|SV* sv |
| 457 | Tells an SV that it is an integer and disables all other OK bits. |
| 458 | |
| 459 | =for apidoc Am|void|SvIOK_only_UV|SV* sv |
| 460 | Tells and SV that it is an unsigned integer and disables all other OK bits. |
| 461 | |
| 462 | =for apidoc Am|bool|SvIOK_UV|SV* sv |
| 463 | Returns a boolean indicating whether the SV contains an unsigned integer. |
| 464 | |
| 465 | =for apidoc Am|void|SvUOK|SV* sv |
| 466 | Returns a boolean indicating whether the SV contains an unsigned integer. |
| 467 | |
| 468 | =for apidoc Am|bool|SvIOK_notUV|SV* sv |
| 469 | Returns a boolean indicating whether the SV contains a signed integer. |
| 470 | |
| 471 | =for apidoc Am|bool|SvNOK|SV* sv |
| 472 | Returns a boolean indicating whether the SV contains a double. |
| 473 | |
| 474 | =for apidoc Am|void|SvNOK_on|SV* sv |
| 475 | Tells an SV that it is a double. |
| 476 | |
| 477 | =for apidoc Am|void|SvNOK_off|SV* sv |
| 478 | Unsets the NV status of an SV. |
| 479 | |
| 480 | =for apidoc Am|void|SvNOK_only|SV* sv |
| 481 | Tells an SV that it is a double and disables all other OK bits. |
| 482 | |
| 483 | =for apidoc Am|bool|SvPOK|SV* sv |
| 484 | Returns a boolean indicating whether the SV contains a character |
| 485 | string. |
| 486 | |
| 487 | =for apidoc Am|void|SvPOK_on|SV* sv |
| 488 | Tells an SV that it is a string. |
| 489 | |
| 490 | =for apidoc Am|void|SvPOK_off|SV* sv |
| 491 | Unsets the PV status of an SV. |
| 492 | |
| 493 | =for apidoc Am|void|SvPOK_only|SV* sv |
| 494 | Tells an SV that it is a string and disables all other OK bits. |
| 495 | Will also turn off the UTF-8 status. |
| 496 | |
| 497 | =for apidoc Am|bool|SvOOK|SV* sv |
| 498 | Returns a boolean indicating whether the SvIVX is a valid offset value for |
| 499 | the SvPVX. This hack is used internally to speed up removal of characters |
| 500 | from the beginning of a SvPV. When SvOOK is true, then the start of the |
| 501 | allocated string buffer is really (SvPVX - SvIVX). |
| 502 | |
| 503 | =for apidoc Am|bool|SvROK|SV* sv |
| 504 | Tests if the SV is an RV. |
| 505 | |
| 506 | =for apidoc Am|void|SvROK_on|SV* sv |
| 507 | Tells an SV that it is an RV. |
| 508 | |
| 509 | =for apidoc Am|void|SvROK_off|SV* sv |
| 510 | Unsets the RV status of an SV. |
| 511 | |
| 512 | =for apidoc Am|SV*|SvRV|SV* sv |
| 513 | Dereferences an RV to return the SV. |
| 514 | |
| 515 | =for apidoc Am|IV|SvIVX|SV* sv |
| 516 | Returns the raw value in the SV's IV slot, without checks or conversions. |
| 517 | Only use when you are sure SvIOK is true. See also C<SvIV()>. |
| 518 | |
| 519 | =for apidoc Am|UV|SvUVX|SV* sv |
| 520 | Returns the raw value in the SV's UV slot, without checks or conversions. |
| 521 | Only use when you are sure SvIOK is true. See also C<SvUV()>. |
| 522 | |
| 523 | =for apidoc Am|NV|SvNVX|SV* sv |
| 524 | Returns the raw value in the SV's NV slot, without checks or conversions. |
| 525 | Only use when you are sure SvNOK is true. See also C<SvNV()>. |
| 526 | |
| 527 | =for apidoc Am|char*|SvPVX|SV* sv |
| 528 | Returns a pointer to the physical string in the SV. The SV must contain a |
| 529 | string. |
| 530 | |
| 531 | =for apidoc Am|STRLEN|SvCUR|SV* sv |
| 532 | Returns the length of the string which is in the SV. See C<SvLEN>. |
| 533 | |
| 534 | =for apidoc Am|STRLEN|SvLEN|SV* sv |
| 535 | Returns the size of the string buffer in the SV, not including any part |
| 536 | attributable to C<SvOOK>. See C<SvCUR>. |
| 537 | |
| 538 | =for apidoc Am|char*|SvEND|SV* sv |
| 539 | Returns a pointer to the last character in the string which is in the SV. |
| 540 | See C<SvCUR>. Access the character as *(SvEND(sv)). |
| 541 | |
| 542 | =for apidoc Am|HV*|SvSTASH|SV* sv |
| 543 | Returns the stash of the SV. |
| 544 | |
| 545 | =for apidoc Am|void|SvIV_set|SV* sv|IV val |
| 546 | Set the value of the IV pointer in sv to val. It is possible to perform |
| 547 | the same function of this macro with an lvalue assignment to C<SvIVX>. |
| 548 | With future Perls, however, it will be more efficient to use |
| 549 | C<SvIV_set> instead of the lvalue assignment to C<SvIVX>. |
| 550 | |
| 551 | =for apidoc Am|void|SvNV_set|SV* sv|NV val |
| 552 | Set the value of the NV pointer in sv to val. See C<SvIV_set>. |
| 553 | |
| 554 | =for apidoc Am|void|SvPV_set|SV* sv|char* val |
| 555 | Set the value of the PV pointer in sv to val. See C<SvIV_set>. |
| 556 | |
| 557 | =for apidoc Am|void|SvUV_set|SV* sv|UV val |
| 558 | Set the value of the UV pointer in sv to val. See C<SvIV_set>. |
| 559 | |
| 560 | =for apidoc Am|void|SvRV_set|SV* sv|SV* val |
| 561 | Set the value of the RV pointer in sv to val. See C<SvIV_set>. |
| 562 | |
| 563 | =for apidoc Am|void|SvMAGIC_set|SV* sv|MAGIC* val |
| 564 | Set the value of the MAGIC pointer in sv to val. See C<SvIV_set>. |
| 565 | |
| 566 | =for apidoc Am|void|SvSTASH_set|SV* sv|STASH* val |
| 567 | Set the value of the STASH pointer in sv to val. See C<SvIV_set>. |
| 568 | |
| 569 | =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len |
| 570 | Set the current length of the string which is in the SV. See C<SvCUR> |
| 571 | and C<SvIV_set>. |
| 572 | |
| 573 | =for apidoc Am|void|SvLEN_set|SV* sv|STRLEN len |
| 574 | Set the actual length of the string which is in the SV. See C<SvIV_set>. |
| 575 | |
| 576 | =cut |
| 577 | */ |
| 578 | |
| 579 | #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) |
| 580 | #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) |
| 581 | #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ |
| 582 | SVp_IOK|SVp_NOK|SVf_IVisUV)) |
| 583 | |
| 584 | #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) |
| 585 | #define assert_not_ROK(sv) ({assert(!SvROK(sv) || !SvRV(sv));}), |
| 586 | #else |
| 587 | #define assert_not_ROK(sv) |
| 588 | #endif |
| 589 | |
| 590 | #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) |
| 591 | #define SvOK_off(sv) (assert_not_ROK(sv) \ |
| 592 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ |
| 593 | SVf_IVisUV|SVf_UTF8), \ |
| 594 | SvOOK_off(sv)) |
| 595 | #define SvOK_off_exc_UV(sv) (assert_not_ROK(sv) \ |
| 596 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ |
| 597 | SVf_UTF8), \ |
| 598 | SvOOK_off(sv)) |
| 599 | |
| 600 | #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) |
| 601 | #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) |
| 602 | #define SvIOKp_on(sv) ((void)SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) |
| 603 | #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) |
| 604 | #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) |
| 605 | #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) |
| 606 | #define SvPOKp_on(sv) (assert_not_ROK(sv) \ |
| 607 | SvFLAGS(sv) |= SVp_POK) |
| 608 | |
| 609 | #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) |
| 610 | #define SvIOK_on(sv) ((void)SvOOK_off(sv), \ |
| 611 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
| 612 | #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV)) |
| 613 | #define SvIOK_only(sv) (SvOK_off(sv), \ |
| 614 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
| 615 | #define SvIOK_only_UV(sv) (SvOK_off_exc_UV(sv), \ |
| 616 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
| 617 | |
| 618 | #define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \ |
| 619 | == (SVf_IOK|SVf_IVisUV)) |
| 620 | #define SvUOK(sv) SvIOK_UV(sv) |
| 621 | #define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \ |
| 622 | == SVf_IOK) |
| 623 | |
| 624 | #define SvVOK(sv) (SvMAGICAL(sv) && mg_find(sv,'V')) |
| 625 | #define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV) |
| 626 | #define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV) |
| 627 | #define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV) |
| 628 | |
| 629 | #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) |
| 630 | #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
| 631 | #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK)) |
| 632 | #define SvNOK_only(sv) (SvOK_off(sv), \ |
| 633 | SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
| 634 | |
| 635 | /* |
| 636 | =for apidoc Am|bool|SvUTF8|SV* sv |
| 637 | Returns a boolean indicating whether the SV contains UTF-8 encoded data. |
| 638 | |
| 639 | =for apidoc Am|void|SvUTF8_on|SV *sv |
| 640 | Turn on the UTF-8 status of an SV (the data is not changed, just the flag). |
| 641 | Do not use frivolously. |
| 642 | |
| 643 | =for apidoc Am|void|SvUTF8_off|SV *sv |
| 644 | Unsets the UTF-8 status of an SV. |
| 645 | |
| 646 | =for apidoc Am|void|SvPOK_only_UTF8|SV* sv |
| 647 | Tells an SV that it is a string and disables all other OK bits, |
| 648 | and leaves the UTF-8 status as it was. |
| 649 | |
| 650 | =cut |
| 651 | */ |
| 652 | |
| 653 | #define SvUTF8(sv) (SvFLAGS(sv) & SVf_UTF8) |
| 654 | #define SvUTF8_on(sv) (SvFLAGS(sv) |= (SVf_UTF8)) |
| 655 | #define SvUTF8_off(sv) (SvFLAGS(sv) &= ~(SVf_UTF8)) |
| 656 | |
| 657 | #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) |
| 658 | #define SvPOK_on(sv) (assert_not_ROK(sv) \ |
| 659 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
| 660 | #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) |
| 661 | #define SvPOK_only(sv) (assert_not_ROK(sv) \ |
| 662 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ |
| 663 | SVf_IVisUV|SVf_UTF8), \ |
| 664 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
| 665 | #define SvPOK_only_UTF8(sv) (assert_not_ROK(sv) \ |
| 666 | SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ |
| 667 | SVf_IVisUV), \ |
| 668 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
| 669 | |
| 670 | #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) |
| 671 | #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) |
| 672 | #define SvOOK_off(sv) ((void)(SvOOK(sv) && sv_backoff(sv))) |
| 673 | |
| 674 | #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE) |
| 675 | #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE) |
| 676 | #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) |
| 677 | |
| 678 | #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) |
| 679 | #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) |
| 680 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) |
| 681 | |
| 682 | #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) |
| 683 | #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) |
| 684 | #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG)) |
| 685 | |
| 686 | #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG) |
| 687 | #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG) |
| 688 | #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG) |
| 689 | |
| 690 | #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG) |
| 691 | #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG) |
| 692 | #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG) |
| 693 | |
| 694 | #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG) |
| 695 | #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) |
| 696 | #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) |
| 697 | |
| 698 | #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) |
| 699 | #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) |
| 700 | #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) |
| 701 | |
| 702 | #define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC)) |
| 703 | |
| 704 | /* |
| 705 | #define Gv_AMG(stash) \ |
| 706 | (HV_AMAGICmb(stash) && \ |
| 707 | ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) |
| 708 | */ |
| 709 | #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash)) |
| 710 | |
| 711 | #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \ |
| 712 | == (SVf_ROK|SVprv_WEAKREF)) |
| 713 | #define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF)) |
| 714 | #define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF)) |
| 715 | |
| 716 | #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) |
| 717 | |
| 718 | #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY) |
| 719 | |
| 720 | #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP) |
| 721 | #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY) |
| 722 | #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP) |
| 723 | |
| 724 | #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY) |
| 725 | #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY) |
| 726 | |
| 727 | #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP) |
| 728 | #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP) |
| 729 | #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP) |
| 730 | |
| 731 | #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT) |
| 732 | #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT) |
| 733 | #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT) |
| 734 | |
| 735 | #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY) |
| 736 | #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY) |
| 737 | #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY) |
| 738 | |
| 739 | #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM) |
| 740 | #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM) |
| 741 | #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM) |
| 742 | |
| 743 | #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED) |
| 744 | #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) |
| 745 | #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) |
| 746 | |
| 747 | #define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL) |
| 748 | #define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL) |
| 749 | #define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL) |
| 750 | |
| 751 | #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) |
| 752 | #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) |
| 753 | #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) |
| 754 | |
| 755 | #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID) |
| 756 | #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID) |
| 757 | #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID) |
| 758 | |
| 759 | #ifdef USE_ITHREADS |
| 760 | /* The following uses the FAKE flag to show that a regex pointer is infact |
| 761 | its own offset in the regexpad for ithreads */ |
| 762 | #define SvREPADTMP(sv) (SvFLAGS(sv) & SVf_FAKE) |
| 763 | #define SvREPADTMP_on(sv) (SvFLAGS(sv) |= SVf_FAKE) |
| 764 | #define SvREPADTMP_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) |
| 765 | #endif |
| 766 | |
| 767 | #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv |
| 768 | #define SvRVx(sv) SvRV(sv) |
| 769 | |
| 770 | #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv |
| 771 | #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv |
| 772 | #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv |
| 773 | #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv |
| 774 | /* Given that these two are new, there can't be any existing code using them |
| 775 | * as LVALUEs */ |
| 776 | #define SvPVX_mutable(sv) (0 + SvPVX(sv)) |
| 777 | #define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) |
| 778 | #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur |
| 779 | #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len |
| 780 | #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) |
| 781 | |
| 782 | #define SvIVXx(sv) SvIVX(sv) |
| 783 | #define SvUVXx(sv) SvUVX(sv) |
| 784 | #define SvNVXx(sv) SvNVX(sv) |
| 785 | #define SvPVXx(sv) SvPVX(sv) |
| 786 | #define SvLENx(sv) SvLEN(sv) |
| 787 | #define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv)) |
| 788 | #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic |
| 789 | #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash |
| 790 | |
| 791 | /* Ask a scalar nicely to try to become an IV, if possible. |
| 792 | Not guaranteed to stay returning void */ |
| 793 | /* Macro won't actually call sv_2iv if already IOK */ |
| 794 | #define SvIV_please(sv) \ |
| 795 | STMT_START {if (!SvIOKp(sv) && (SvNOK(sv) || SvPOK(sv))) \ |
| 796 | (void) SvIV(sv); } STMT_END |
| 797 | /* Put the asserts back at some point and figure out where they reveal bugs |
| 798 | */ |
| 799 | #define SvIV_set(sv, val) \ |
| 800 | STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ |
| 801 | (((XPVIV*) SvANY(sv))->xiv_iv = (val)); } STMT_END |
| 802 | #define SvNV_set(sv, val) \ |
| 803 | STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \ |
| 804 | (((XPVNV*)SvANY(sv))->xnv_nv = (val)); } STMT_END |
| 805 | /* assert(SvTYPE(sv) >= SVt_PV); */ |
| 806 | #define SvPV_set(sv, val) \ |
| 807 | STMT_START { \ |
| 808 | (((XPV*) SvANY(sv))->xpv_pv = (val)); } STMT_END |
| 809 | /* assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); */ |
| 810 | #define SvUV_set(sv, val) \ |
| 811 | STMT_START { \ |
| 812 | (((XPVUV*)SvANY(sv))->xuv_uv = (val)); } STMT_END |
| 813 | /* assert(SvTYPE(sv) >= SVt_RV); */ |
| 814 | #define SvRV_set(sv, val) \ |
| 815 | STMT_START { \ |
| 816 | (((XRV*)SvANY(sv))->xrv_rv = (val)); } STMT_END |
| 817 | /* assert(SvTYPE(sv) >= SVt_PVMG); */ |
| 818 | #define SvMAGIC_set(sv, val) \ |
| 819 | STMT_START { \ |
| 820 | (((XPVMG*)SvANY(sv))->xmg_magic = (val)); } STMT_END |
| 821 | /* assert(SvTYPE(sv) >= SVt_PVMG); */ |
| 822 | #define SvSTASH_set(sv, val) \ |
| 823 | STMT_START { \ |
| 824 | (((XPVMG*) SvANY(sv))->xmg_stash = (val)); } STMT_END |
| 825 | /* assert(SvTYPE(sv) >= SVt_PV); */ |
| 826 | #define SvCUR_set(sv, val) \ |
| 827 | STMT_START { \ |
| 828 | (((XPV*) SvANY(sv))->xpv_cur = (val)); } STMT_END |
| 829 | /* assert(SvTYPE(sv) >= SVt_PV); */ |
| 830 | #define SvLEN_set(sv, val) \ |
| 831 | STMT_START { \ |
| 832 | (((XPV*) SvANY(sv))->xpv_len = (val)); } STMT_END |
| 833 | #define SvEND_set(sv, val) \ |
| 834 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
| 835 | (SvCUR(sv) = (val) - SvPVX(sv)); } STMT_END |
| 836 | |
| 837 | #define SvPV_renew(sv,n) \ |
| 838 | STMT_START { SvLEN_set(sv, n); \ |
| 839 | SvPV_set((sv), (MEM_WRAP_CHECK_(n,char) \ |
| 840 | (char*)saferealloc((Malloc_t)SvPVX(sv), \ |
| 841 | (MEM_SIZE)((n))))); \ |
| 842 | } STMT_END |
| 843 | |
| 844 | #define SvPV_shrink_to_cur(sv) STMT_START { \ |
| 845 | const STRLEN _lEnGtH = SvCUR(sv) + 1; \ |
| 846 | SvPV_renew(sv, _lEnGtH); \ |
| 847 | } STMT_END |
| 848 | |
| 849 | #define SvPV_free(sv) \ |
| 850 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
| 851 | if (SvLEN(sv)) { \ |
| 852 | if(SvOOK(sv)) { \ |
| 853 | Safefree(SvPVX(sv) - SvIVX(sv)); \ |
| 854 | SvFLAGS(sv) &= ~SVf_OOK; \ |
| 855 | } else { \ |
| 856 | Safefree(SvPVX(sv)); \ |
| 857 | } \ |
| 858 | } \ |
| 859 | } STMT_END |
| 860 | |
| 861 | #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare |
| 862 | #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful |
| 863 | #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous |
| 864 | |
| 865 | #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines |
| 866 | |
| 867 | #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type |
| 868 | #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ |
| 869 | #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff |
| 870 | #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen |
| 871 | |
| 872 | #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp |
| 873 | #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp |
| 874 | #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp |
| 875 | #define IoANY(sv) ((XPVIO*) SvANY(sv))->xio_any |
| 876 | #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines |
| 877 | #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page |
| 878 | #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len |
| 879 | #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left |
| 880 | #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name |
| 881 | #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv |
| 882 | #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name |
| 883 | #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv |
| 884 | #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name |
| 885 | #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv |
| 886 | #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess |
| 887 | #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type |
| 888 | #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags |
| 889 | |
| 890 | /* IoTYPE(sv) is a single character telling the type of I/O connection. */ |
| 891 | #define IoTYPE_RDONLY '<' |
| 892 | #define IoTYPE_WRONLY '>' |
| 893 | #define IoTYPE_RDWR '+' |
| 894 | #define IoTYPE_APPEND 'a' |
| 895 | #define IoTYPE_PIPE '|' |
| 896 | #define IoTYPE_STD '-' /* stdin or stdout */ |
| 897 | #define IoTYPE_SOCKET 's' |
| 898 | #define IoTYPE_CLOSED ' ' |
| 899 | #define IoTYPE_IMPLICIT 'I' /* stdin or stdout or stderr */ |
| 900 | #define IoTYPE_NUMERIC '#' /* fdopen */ |
| 901 | |
| 902 | /* |
| 903 | =for apidoc Am|bool|SvTAINTED|SV* sv |
| 904 | Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if |
| 905 | not. |
| 906 | |
| 907 | =for apidoc Am|void|SvTAINTED_on|SV* sv |
| 908 | Marks an SV as tainted if tainting is enabled. |
| 909 | |
| 910 | =for apidoc Am|void|SvTAINTED_off|SV* sv |
| 911 | Untaints an SV. Be I<very> careful with this routine, as it short-circuits |
| 912 | some of Perl's fundamental security features. XS module authors should not |
| 913 | use this function unless they fully understand all the implications of |
| 914 | unconditionally untainting the value. Untainting should be done in the |
| 915 | standard perl fashion, via a carefully crafted regexp, rather than directly |
| 916 | untainting variables. |
| 917 | |
| 918 | =for apidoc Am|void|SvTAINT|SV* sv |
| 919 | Taints an SV if tainting is enabled. |
| 920 | |
| 921 | =cut |
| 922 | */ |
| 923 | |
| 924 | #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv)) |
| 925 | #define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END |
| 926 | #define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END |
| 927 | |
| 928 | #define SvTAINT(sv) \ |
| 929 | STMT_START { \ |
| 930 | if (PL_tainting) { \ |
| 931 | if (PL_tainted) \ |
| 932 | SvTAINTED_on(sv); \ |
| 933 | } \ |
| 934 | } STMT_END |
| 935 | |
| 936 | /* |
| 937 | =for apidoc Am|char*|SvPV_force|SV* sv|STRLEN len |
| 938 | Like C<SvPV> but will force the SV into containing just a string |
| 939 | (C<SvPOK_only>). You want force if you are going to update the C<SvPVX> |
| 940 | directly. |
| 941 | |
| 942 | =for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN len |
| 943 | Like C<SvPV> but will force the SV into containing just a string |
| 944 | (C<SvPOK_only>). You want force if you are going to update the C<SvPVX> |
| 945 | directly. Doesn't process magic. |
| 946 | |
| 947 | =for apidoc Am|char*|SvPV|SV* sv|STRLEN len |
| 948 | Returns a pointer to the string in the SV, or a stringified form of |
| 949 | the SV if the SV does not contain a string. The SV may cache the |
| 950 | stringified version becoming C<SvPOK>. Handles 'get' magic. See also |
| 951 | C<SvPVx> for a version which guarantees to evaluate sv only once. |
| 952 | |
| 953 | =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len |
| 954 | A version of C<SvPV> which guarantees to evaluate sv only once. |
| 955 | |
| 956 | =for apidoc Am|char*|SvPV_nolen|SV* sv |
| 957 | Returns a pointer to the string in the SV, or a stringified form of |
| 958 | the SV if the SV does not contain a string. The SV may cache the |
| 959 | stringified form becoming C<SvPOK>. Handles 'get' magic. |
| 960 | |
| 961 | =for apidoc Am|IV|SvIV|SV* sv |
| 962 | Coerces the given SV to an integer and returns it. See C<SvIVx> for a |
| 963 | version which guarantees to evaluate sv only once. |
| 964 | |
| 965 | =for apidoc Am|IV|SvIVx|SV* sv |
| 966 | Coerces the given SV to an integer and returns it. Guarantees to evaluate |
| 967 | sv only once. Use the more efficient C<SvIV> otherwise. |
| 968 | |
| 969 | =for apidoc Am|NV|SvNV|SV* sv |
| 970 | Coerce the given SV to a double and return it. See C<SvNVx> for a version |
| 971 | which guarantees to evaluate sv only once. |
| 972 | |
| 973 | =for apidoc Am|NV|SvNVx|SV* sv |
| 974 | Coerces the given SV to a double and returns it. Guarantees to evaluate |
| 975 | sv only once. Use the more efficient C<SvNV> otherwise. |
| 976 | |
| 977 | =for apidoc Am|UV|SvUV|SV* sv |
| 978 | Coerces the given SV to an unsigned integer and returns it. See C<SvUVx> |
| 979 | for a version which guarantees to evaluate sv only once. |
| 980 | |
| 981 | =for apidoc Am|UV|SvUVx|SV* sv |
| 982 | Coerces the given SV to an unsigned integer and returns it. Guarantees to |
| 983 | evaluate sv only once. Use the more efficient C<SvUV> otherwise. |
| 984 | |
| 985 | =for apidoc Am|bool|SvTRUE|SV* sv |
| 986 | Returns a boolean indicating whether Perl would evaluate the SV as true or |
| 987 | false, defined or undefined. Does not handle 'get' magic. |
| 988 | |
| 989 | =for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN len |
| 990 | Like C<SvPV_force>, but converts sv to utf8 first if necessary. |
| 991 | |
| 992 | =for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN len |
| 993 | Like C<SvPV>, but converts sv to utf8 first if necessary. |
| 994 | |
| 995 | =for apidoc Am|char*|SvPVutf8_nolen|SV* sv |
| 996 | Like C<SvPV_nolen>, but converts sv to utf8 first if necessary. |
| 997 | |
| 998 | =for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN len |
| 999 | Like C<SvPV_force>, but converts sv to byte representation first if necessary. |
| 1000 | |
| 1001 | =for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN len |
| 1002 | Like C<SvPV>, but converts sv to byte representation first if necessary. |
| 1003 | |
| 1004 | =for apidoc Am|char*|SvPVbyte_nolen|SV* sv |
| 1005 | Like C<SvPV_nolen>, but converts sv to byte representation first if necessary. |
| 1006 | |
| 1007 | =for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN len |
| 1008 | Like C<SvPV_force>, but converts sv to utf8 first if necessary. |
| 1009 | Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force> |
| 1010 | otherwise. |
| 1011 | |
| 1012 | =for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN len |
| 1013 | Like C<SvPV>, but converts sv to utf8 first if necessary. |
| 1014 | Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8> |
| 1015 | otherwise. |
| 1016 | |
| 1017 | =for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN len |
| 1018 | Like C<SvPV_force>, but converts sv to byte representation first if necessary. |
| 1019 | Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force> |
| 1020 | otherwise. |
| 1021 | |
| 1022 | =for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN len |
| 1023 | Like C<SvPV>, but converts sv to byte representation first if necessary. |
| 1024 | Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte> |
| 1025 | otherwise. |
| 1026 | |
| 1027 | =for apidoc Am|bool|SvIsCOW|SV* sv |
| 1028 | Returns a boolean indicating whether the SV is Copy-On-Write. (either shared |
| 1029 | hash key scalars, or full Copy On Write scalars if 5.9.0 is configured for |
| 1030 | COW) |
| 1031 | |
| 1032 | =for apidoc Am|bool|SvIsCOW_shared_hash|SV* sv |
| 1033 | Returns a boolean indicating whether the SV is Copy-On-Write shared hash key |
| 1034 | scalar. |
| 1035 | |
| 1036 | =for apidoc Am|void|sv_catpvn_nomg|SV* sv|const char* ptr|STRLEN len |
| 1037 | Like C<sv_catpvn> but doesn't process magic. |
| 1038 | |
| 1039 | =for apidoc Am|void|sv_setsv_nomg|SV* dsv|SV* ssv |
| 1040 | Like C<sv_setsv> but doesn't process magic. |
| 1041 | |
| 1042 | =for apidoc Am|void|sv_catsv_nomg|SV* dsv|SV* ssv |
| 1043 | Like C<sv_catsv> but doesn't process magic. |
| 1044 | |
| 1045 | =cut |
| 1046 | */ |
| 1047 | |
| 1048 | /* Let us hope that bitmaps for UV and IV are the same */ |
| 1049 | #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) |
| 1050 | #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) |
| 1051 | #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)) |
| 1052 | |
| 1053 | /* ----*/ |
| 1054 | |
| 1055 | #define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC) |
| 1056 | #define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC) |
| 1057 | #define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC) |
| 1058 | |
| 1059 | #define SvPV_flags(sv, lp, flags) \ |
| 1060 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
| 1061 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) |
| 1062 | #define SvPV_flags_const(sv, lp, flags) \ |
| 1063 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
| 1064 | ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ |
| 1065 | (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN)) |
| 1066 | #define SvPV_flags_const_nolen(sv, flags) \ |
| 1067 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
| 1068 | ? SvPVX_const(sv) : \ |
| 1069 | (const char*) sv_2pv_flags(sv, 0, flags|SV_CONST_RETURN)) |
| 1070 | #define SvPV_flags_mutable(sv, lp, flags) \ |
| 1071 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
| 1072 | ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ |
| 1073 | sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) |
| 1074 | |
| 1075 | #define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) |
| 1076 | #define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC) |
| 1077 | #define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC) |
| 1078 | |
| 1079 | #define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) |
| 1080 | #define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0) |
| 1081 | |
| 1082 | #define SvPV_force_flags(sv, lp, flags) \ |
| 1083 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
| 1084 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) |
| 1085 | #define SvPV_force_flags_nolen(sv, flags) \ |
| 1086 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
| 1087 | ? SvPVX(sv) : sv_pvn_force_flags(sv, 0, flags)) |
| 1088 | #define SvPV_force_flags_mutable(sv, lp, flags) \ |
| 1089 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
| 1090 | ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ |
| 1091 | : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) |
| 1092 | |
| 1093 | #define SvPV_nolen(sv) \ |
| 1094 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
| 1095 | ? SvPVX(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC)) |
| 1096 | |
| 1097 | #define SvPV_nolen_const(sv) \ |
| 1098 | ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ |
| 1099 | ? SvPVX_const(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC|SV_CONST_RETURN)) |
| 1100 | |
| 1101 | #define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) |
| 1102 | #define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0) |
| 1103 | #define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0) |
| 1104 | |
| 1105 | /* ----*/ |
| 1106 | |
| 1107 | #define SvPVutf8(sv, lp) \ |
| 1108 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \ |
| 1109 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp)) |
| 1110 | |
| 1111 | #define SvPVutf8_force(sv, lp) \ |
| 1112 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \ |
| 1113 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp)) |
| 1114 | |
| 1115 | |
| 1116 | #define SvPVutf8_nolen(sv) \ |
| 1117 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\ |
| 1118 | ? SvPVX(sv) : sv_2pvutf8(sv, 0)) |
| 1119 | |
| 1120 | /* ----*/ |
| 1121 | |
| 1122 | #define SvPVbyte(sv, lp) \ |
| 1123 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ |
| 1124 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) |
| 1125 | |
| 1126 | #define SvPVbyte_force(sv, lp) \ |
| 1127 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \ |
| 1128 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyten_force(sv, &lp)) |
| 1129 | |
| 1130 | #define SvPVbyte_nolen(sv) \ |
| 1131 | ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\ |
| 1132 | ? SvPVX(sv) : sv_2pvbyte(sv, 0)) |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | /* define FOOx(): idempotent versions of FOO(). If possible, use a local |
| 1137 | * var to evaluate the arg once; failing that, use a global if possible; |
| 1138 | * failing that, call a function to do the work |
| 1139 | */ |
| 1140 | |
| 1141 | #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp) |
| 1142 | #define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp) |
| 1143 | #define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp) |
| 1144 | |
| 1145 | #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) |
| 1146 | |
| 1147 | # define SvIVx(sv) ({SV *_sv = (SV*)(sv); SvIV(_sv); }) |
| 1148 | # define SvUVx(sv) ({SV *_sv = (SV*)(sv); SvUV(_sv); }) |
| 1149 | # define SvNVx(sv) ({SV *_sv = (SV*)(sv); SvNV(_sv); }) |
| 1150 | # define SvPVx(sv, lp) ({SV *_sv = (sv); SvPV(_sv, lp); }) |
| 1151 | # define SvPVx_const(sv, lp) ({SV *_sv = (sv); SvPV_const(_sv, lp); }) |
| 1152 | # define SvPVx_nolen(sv) ({SV *_sv = (sv); SvPV_nolen(_sv); }) |
| 1153 | # define SvPVx_nolen_const(sv) ({SV *_sv = (sv); SvPV_nolen_const(_sv); }) |
| 1154 | # define SvPVutf8x(sv, lp) ({SV *_sv = (sv); SvPVutf8(_sv, lp); }) |
| 1155 | # define SvPVbytex(sv, lp) ({SV *_sv = (sv); SvPVbyte(_sv, lp); }) |
| 1156 | # define SvPVbytex_nolen(sv) ({SV *_sv = (sv); SvPVbyte_nolen(_sv); }) |
| 1157 | # define SvTRUE(sv) ( \ |
| 1158 | !sv \ |
| 1159 | ? 0 \ |
| 1160 | : SvPOK(sv) \ |
| 1161 | ? (({XPV *nxpv = (XPV*)SvANY(sv); \ |
| 1162 | nxpv && \ |
| 1163 | (nxpv->xpv_cur > 1 || \ |
| 1164 | (nxpv->xpv_cur && *nxpv->xpv_pv != '0')); }) \ |
| 1165 | ? 1 \ |
| 1166 | : 0) \ |
| 1167 | : \ |
| 1168 | SvIOK(sv) \ |
| 1169 | ? SvIVX(sv) != 0 \ |
| 1170 | : SvNOK(sv) \ |
| 1171 | ? SvNVX(sv) != 0.0 \ |
| 1172 | : sv_2bool(sv) ) |
| 1173 | # define SvTRUEx(sv) ({SV *_sv = (sv); SvTRUE(_sv); }) |
| 1174 | |
| 1175 | #else /* __GNUC__ */ |
| 1176 | |
| 1177 | # ifdef USE_5005THREADS |
| 1178 | # define SvIVx(sv) sv_iv(sv) |
| 1179 | # define SvUVx(sv) sv_uv(sv) |
| 1180 | # define SvNVx(sv) sv_nv(sv) |
| 1181 | # define SvPVx(sv, lp) sv_pvn(sv, &lp) |
| 1182 | # define SvPVutf8x(sv, lp) sv_pvutf8n(sv, &lp) |
| 1183 | # define SvPVbytex(sv, lp) sv_pvbyten(sv, &lp) |
| 1184 | # define SvTRUE(sv) SvTRUEx(sv) |
| 1185 | # define SvTRUEx(sv) sv_true(sv) |
| 1186 | |
| 1187 | # else /* USE_5005THREADS */ |
| 1188 | |
| 1189 | /* These inlined macros use globals, which will require a thread |
| 1190 | * declaration in user code, so we avoid them under threads */ |
| 1191 | |
| 1192 | # define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv)) |
| 1193 | # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) |
| 1194 | # define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv)) |
| 1195 | # define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp)) |
| 1196 | # define SvPVx_const(sv, lp) ((PL_Sv = (sv)), SvPV_const(PL_Sv, lp)) |
| 1197 | # define SvPVx_nolen(sv) ((PL_Sv = (sv)), SvPV_nolen(PL_Sv)) |
| 1198 | # define SvPVx_nolen_const(sv) ((PL_Sv = (sv)), SvPV_nolen_const(PL_Sv)) |
| 1199 | # define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp)) |
| 1200 | # define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp)) |
| 1201 | # define SvPVbytex_nolen(sv) ((PL_Sv = (sv)), SvPVbyte_nolen(PL_Sv)) |
| 1202 | # define SvTRUE(sv) ( \ |
| 1203 | !sv \ |
| 1204 | ? 0 \ |
| 1205 | : SvPOK(sv) \ |
| 1206 | ? ((PL_Xpv = (XPV*)SvANY(sv)) && \ |
| 1207 | (PL_Xpv->xpv_cur > 1 || \ |
| 1208 | (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \ |
| 1209 | ? 1 \ |
| 1210 | : 0) \ |
| 1211 | : \ |
| 1212 | SvIOK(sv) \ |
| 1213 | ? SvIVX(sv) != 0 \ |
| 1214 | : SvNOK(sv) \ |
| 1215 | ? SvNVX(sv) != 0.0 \ |
| 1216 | : sv_2bool(sv) ) |
| 1217 | # define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv)) |
| 1218 | # endif /* USE_5005THREADS */ |
| 1219 | #endif /* __GNU__ */ |
| 1220 | |
| 1221 | #define SvIsCOW(sv) ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \ |
| 1222 | (SVf_FAKE | SVf_READONLY)) |
| 1223 | #define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0) |
| 1224 | |
| 1225 | #define SvSHARED_HASH(sv) (0 + SvUVX(sv)) |
| 1226 | |
| 1227 | /* flag values for sv_*_flags functions */ |
| 1228 | #define SV_IMMEDIATE_UNREF 1 |
| 1229 | #define SV_GMAGIC 2 |
| 1230 | #define SV_COW_DROP_PV 4 /* Unused in Perl 5.8.x */ |
| 1231 | #define SV_UTF8_NO_ENCODING 8 |
| 1232 | #define SV_NOSTEAL 16 |
| 1233 | #define SV_CONST_RETURN 32 |
| 1234 | #define SV_MUTABLE_RETURN 64 |
| 1235 | |
| 1236 | /* all these 'functions' are now just macros */ |
| 1237 | |
| 1238 | #define sv_pv(sv) SvPV_nolen(sv) |
| 1239 | #define sv_pvutf8(sv) SvPVutf8_nolen(sv) |
| 1240 | #define sv_pvbyte(sv) SvPVbyte_nolen(sv) |
| 1241 | |
| 1242 | #define sv_pvn_force_nomg(sv, lp) sv_pvn_force_flags(sv, lp, 0) |
| 1243 | #define sv_utf8_upgrade_nomg(sv) sv_utf8_upgrade_flags(sv, 0) |
| 1244 | #define sv_catpvn_nomg(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, 0) |
| 1245 | #define sv_setsv(dsv, ssv) sv_setsv_flags(dsv, ssv, SV_GMAGIC) |
| 1246 | #define sv_setsv_nomg(dsv, ssv) sv_setsv_flags(dsv, ssv, 0) |
| 1247 | #define sv_catsv(dsv, ssv) sv_catsv_flags(dsv, ssv, SV_GMAGIC) |
| 1248 | #define sv_catsv_nomg(dsv, ssv) sv_catsv_flags(dsv, ssv, 0) |
| 1249 | #define sv_catpvn(dsv, sstr, slen) sv_catpvn_flags(dsv, sstr, slen, SV_GMAGIC) |
| 1250 | #define sv_2pv(sv, lp) sv_2pv_flags(sv, lp, SV_GMAGIC) |
| 1251 | #define sv_2pv_nomg(sv, lp) sv_2pv_flags(sv, lp, 0) |
| 1252 | #define sv_pvn_force(sv, lp) sv_pvn_force_flags(sv, lp, SV_GMAGIC) |
| 1253 | #define sv_utf8_upgrade(sv) sv_utf8_upgrade_flags(sv, SV_GMAGIC) |
| 1254 | |
| 1255 | /* Should be named SvCatPVN_utf8_upgrade? */ |
| 1256 | #define sv_catpvn_utf8_upgrade(dsv, sstr, slen, nsv) \ |
| 1257 | STMT_START { \ |
| 1258 | if (!(nsv)) \ |
| 1259 | nsv = sv_2mortal(newSVpvn(sstr, slen)); \ |
| 1260 | else \ |
| 1261 | sv_setpvn(nsv, sstr, slen); \ |
| 1262 | SvUTF8_off(nsv); \ |
| 1263 | sv_utf8_upgrade(nsv); \ |
| 1264 | sv_catsv(dsv, nsv); \ |
| 1265 | } STMT_END |
| 1266 | |
| 1267 | /* |
| 1268 | =for apidoc Am|SV*|newRV_inc|SV* sv |
| 1269 | |
| 1270 | Creates an RV wrapper for an SV. The reference count for the original SV is |
| 1271 | incremented. |
| 1272 | |
| 1273 | =cut |
| 1274 | */ |
| 1275 | |
| 1276 | #define newRV_inc(sv) newRV(sv) |
| 1277 | |
| 1278 | /* the following macros update any magic values this sv is associated with */ |
| 1279 | |
| 1280 | /* |
| 1281 | =head1 Magical Functions |
| 1282 | |
| 1283 | =for apidoc Am|void|SvGETMAGIC|SV* sv |
| 1284 | Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its |
| 1285 | argument more than once. |
| 1286 | |
| 1287 | =for apidoc Am|void|SvSETMAGIC|SV* sv |
| 1288 | Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its |
| 1289 | argument more than once. |
| 1290 | |
| 1291 | =for apidoc Am|void|SvSetSV|SV* dsb|SV* ssv |
| 1292 | Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments |
| 1293 | more than once. |
| 1294 | |
| 1295 | =for apidoc Am|void|SvSetSV_nosteal|SV* dsv|SV* ssv |
| 1296 | Calls a non-destructive version of C<sv_setsv> if dsv is not the same as |
| 1297 | ssv. May evaluate arguments more than once. |
| 1298 | |
| 1299 | =for apidoc Am|void|SvSetMagicSV|SV* dsb|SV* ssv |
| 1300 | Like C<SvSetSV>, but does any set magic required afterwards. |
| 1301 | |
| 1302 | =for apidoc Am|void|SvSetMagicSV_nosteal|SV* dsv|SV* ssv |
| 1303 | Like C<SvSetSV_nosteal>, but does any set magic required afterwards. |
| 1304 | |
| 1305 | =for apidoc Am|void|SvSHARE|SV* sv |
| 1306 | Arranges for sv to be shared between threads if a suitable module |
| 1307 | has been loaded. |
| 1308 | |
| 1309 | =for apidoc Am|void|SvLOCK|SV* sv |
| 1310 | Arranges for a mutual exclusion lock to be obtained on sv if a suitable module |
| 1311 | has been loaded. |
| 1312 | |
| 1313 | =for apidoc Am|void|SvUNLOCK|SV* sv |
| 1314 | Releases a mutual exclusion lock on sv if a suitable module |
| 1315 | has been loaded. |
| 1316 | |
| 1317 | =head1 SV Manipulation Functions |
| 1318 | |
| 1319 | =for apidoc Am|char *|SvGROW|SV* sv|STRLEN len |
| 1320 | Expands the character buffer in the SV so that it has room for the |
| 1321 | indicated number of bytes (remember to reserve space for an extra trailing |
| 1322 | NUL character). Calls C<sv_grow> to perform the expansion if necessary. |
| 1323 | Returns a pointer to the character buffer. |
| 1324 | |
| 1325 | =cut |
| 1326 | */ |
| 1327 | |
| 1328 | #define SvSHARE(sv) CALL_FPTR(PL_sharehook)(aTHX_ sv) |
| 1329 | #define SvLOCK(sv) CALL_FPTR(PL_lockhook)(aTHX_ sv) |
| 1330 | #define SvUNLOCK(sv) CALL_FPTR(PL_unlockhook)(aTHX_ sv) |
| 1331 | |
| 1332 | #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END |
| 1333 | #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END |
| 1334 | |
| 1335 | #define SvSetSV_and(dst,src,finally) \ |
| 1336 | STMT_START { \ |
| 1337 | if ((dst) != (src)) { \ |
| 1338 | sv_setsv(dst, src); \ |
| 1339 | finally; \ |
| 1340 | } \ |
| 1341 | } STMT_END |
| 1342 | #define SvSetSV_nosteal_and(dst,src,finally) \ |
| 1343 | STMT_START { \ |
| 1344 | if ((dst) != (src)) { \ |
| 1345 | sv_setsv_flags(dst, src, SV_GMAGIC | SV_NOSTEAL); \ |
| 1346 | finally; \ |
| 1347 | } \ |
| 1348 | } STMT_END |
| 1349 | |
| 1350 | #define SvSetSV(dst,src) \ |
| 1351 | SvSetSV_and(dst,src,/*nothing*/;) |
| 1352 | #define SvSetSV_nosteal(dst,src) \ |
| 1353 | SvSetSV_nosteal_and(dst,src,/*nothing*/;) |
| 1354 | |
| 1355 | #define SvSetMagicSV(dst,src) \ |
| 1356 | SvSetSV_and(dst,src,SvSETMAGIC(dst)) |
| 1357 | #define SvSetMagicSV_nosteal(dst,src) \ |
| 1358 | SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst)) |
| 1359 | |
| 1360 | |
| 1361 | #if !defined(SKIP_DEBUGGING) |
| 1362 | #define SvPEEK(sv) sv_peek(sv) |
| 1363 | #else |
| 1364 | #define SvPEEK(sv) "" |
| 1365 | #endif |
| 1366 | |
| 1367 | #define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no || (sv)==&PL_sv_placeholder) |
| 1368 | |
| 1369 | #define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) |
| 1370 | |
| 1371 | #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) |
| 1372 | |
| 1373 | #define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) |
| 1374 | #define SvGROW_mutable(sv,len) \ |
| 1375 | (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX_mutable(sv)) |
| 1376 | #define Sv_Grow sv_grow |
| 1377 | |
| 1378 | #define CLONEf_COPY_STACKS 1 |
| 1379 | #define CLONEf_KEEP_PTR_TABLE 2 |
| 1380 | #define CLONEf_CLONE_HOST 4 |
| 1381 | #define CLONEf_JOIN_IN 8 |
| 1382 | |
| 1383 | struct clone_params { |
| 1384 | AV* stashes; |
| 1385 | UV flags; |
| 1386 | PerlInterpreter *proto_perl; |
| 1387 | }; |
| 1388 | |
| 1389 | #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) sv_force_normal(sv) |