[10723] | 1 | /* sv.h |
---|
| 2 | * |
---|
| 3 | * Copyright (c) 1991-1997, Larry Wall |
---|
| 4 | * |
---|
| 5 | * You may distribute under the terms of either the GNU General Public |
---|
| 6 | * License or the Artistic License, as specified in the README file. |
---|
| 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifdef sv_flags |
---|
| 11 | #undef sv_flags /* Convex has this in <signal.h> for sigvec() */ |
---|
| 12 | #endif |
---|
| 13 | |
---|
| 14 | typedef enum { |
---|
| 15 | SVt_NULL, /* 0 */ |
---|
| 16 | SVt_IV, /* 1 */ |
---|
| 17 | SVt_NV, /* 2 */ |
---|
| 18 | SVt_RV, /* 3 */ |
---|
| 19 | SVt_PV, /* 4 */ |
---|
| 20 | SVt_PVIV, /* 5 */ |
---|
| 21 | SVt_PVNV, /* 6 */ |
---|
| 22 | SVt_PVMG, /* 7 */ |
---|
| 23 | SVt_PVBM, /* 8 */ |
---|
| 24 | SVt_PVLV, /* 9 */ |
---|
| 25 | SVt_PVAV, /* 10 */ |
---|
| 26 | SVt_PVHV, /* 11 */ |
---|
| 27 | SVt_PVCV, /* 12 */ |
---|
| 28 | SVt_PVGV, /* 13 */ |
---|
| 29 | SVt_PVFM, /* 14 */ |
---|
| 30 | SVt_PVIO /* 15 */ |
---|
| 31 | } svtype; |
---|
| 32 | |
---|
| 33 | /* Using C's structural equivalence to help emulate C++ inheritance here... */ |
---|
| 34 | |
---|
| 35 | struct sv { |
---|
| 36 | void* sv_any; /* pointer to something */ |
---|
| 37 | U32 sv_refcnt; /* how many references to us */ |
---|
| 38 | U32 sv_flags; /* what we are */ |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | struct gv { |
---|
| 42 | XPVGV* sv_any; /* pointer to something */ |
---|
| 43 | U32 sv_refcnt; /* how many references to us */ |
---|
| 44 | U32 sv_flags; /* what we are */ |
---|
| 45 | }; |
---|
| 46 | |
---|
| 47 | struct cv { |
---|
| 48 | XPVCV* sv_any; /* pointer to something */ |
---|
| 49 | U32 sv_refcnt; /* how many references to us */ |
---|
| 50 | U32 sv_flags; /* what we are */ |
---|
| 51 | }; |
---|
| 52 | |
---|
| 53 | struct av { |
---|
| 54 | XPVAV* sv_any; /* pointer to something */ |
---|
| 55 | U32 sv_refcnt; /* how many references to us */ |
---|
| 56 | U32 sv_flags; /* what we are */ |
---|
| 57 | }; |
---|
| 58 | |
---|
| 59 | struct hv { |
---|
| 60 | XPVHV* sv_any; /* pointer to something */ |
---|
| 61 | U32 sv_refcnt; /* how many references to us */ |
---|
| 62 | U32 sv_flags; /* what we are */ |
---|
| 63 | }; |
---|
| 64 | |
---|
| 65 | struct io { |
---|
| 66 | XPVIO* sv_any; /* pointer to something */ |
---|
| 67 | U32 sv_refcnt; /* how many references to us */ |
---|
| 68 | U32 sv_flags; /* what we are */ |
---|
| 69 | }; |
---|
| 70 | |
---|
| 71 | #define SvANY(sv) (sv)->sv_any |
---|
| 72 | #define SvFLAGS(sv) (sv)->sv_flags |
---|
| 73 | |
---|
| 74 | #define SvREFCNT(sv) (sv)->sv_refcnt |
---|
| 75 | #ifdef CRIPPLED_CC |
---|
| 76 | #define SvREFCNT_inc(sv) sv_newref((SV*)sv) |
---|
| 77 | #define SvREFCNT_dec(sv) sv_free((SV*)sv) |
---|
| 78 | #else |
---|
| 79 | #define SvREFCNT_inc(sv) ((Sv = (SV*)(sv)), \ |
---|
| 80 | (Sv && ++SvREFCNT(Sv)), (SV*)Sv) |
---|
| 81 | #define SvREFCNT_dec(sv) sv_free((SV*)sv) |
---|
| 82 | #endif |
---|
| 83 | |
---|
| 84 | #define SVTYPEMASK 0xff |
---|
| 85 | #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) |
---|
| 86 | |
---|
| 87 | #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt)) |
---|
| 88 | |
---|
| 89 | #define SVs_PADBUSY 0x00000100 /* reserved for tmp or my already */ |
---|
| 90 | #define SVs_PADTMP 0x00000200 /* in use as tmp */ |
---|
| 91 | #define SVs_PADMY 0x00000400 /* in use a "my" variable */ |
---|
| 92 | #define SVs_TEMP 0x00000800 /* string is stealable? */ |
---|
| 93 | #define SVs_OBJECT 0x00001000 /* is "blessed" */ |
---|
| 94 | #define SVs_GMG 0x00002000 /* has magical get method */ |
---|
| 95 | #define SVs_SMG 0x00004000 /* has magical set method */ |
---|
| 96 | #define SVs_RMG 0x00008000 /* has random magical methods */ |
---|
| 97 | |
---|
| 98 | #define SVf_IOK 0x00010000 /* has valid public integer value */ |
---|
| 99 | #define SVf_NOK 0x00020000 /* has valid public numeric value */ |
---|
| 100 | #define SVf_POK 0x00040000 /* has valid public pointer value */ |
---|
| 101 | #define SVf_ROK 0x00080000 /* has a valid reference pointer */ |
---|
| 102 | |
---|
| 103 | #define SVf_FAKE 0x00100000 /* glob or lexical is just a copy */ |
---|
| 104 | #define SVf_OOK 0x00200000 /* has valid offset value */ |
---|
| 105 | #define SVf_BREAK 0x00400000 /* refcnt is artificially low */ |
---|
| 106 | #define SVf_READONLY 0x00800000 /* may not be modified */ |
---|
| 107 | |
---|
| 108 | #define SVf_THINKFIRST (SVf_READONLY|SVf_ROK) |
---|
| 109 | |
---|
| 110 | #define SVp_IOK 0x01000000 /* has valid non-public integer value */ |
---|
| 111 | #define SVp_NOK 0x02000000 /* has valid non-public numeric value */ |
---|
| 112 | #define SVp_POK 0x04000000 /* has valid non-public pointer value */ |
---|
| 113 | #define SVp_SCREAM 0x08000000 /* has been studied? */ |
---|
| 114 | |
---|
| 115 | #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ |
---|
| 116 | SVp_IOK|SVp_NOK|SVp_POK) |
---|
| 117 | |
---|
| 118 | #ifdef OVERLOAD |
---|
| 119 | #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ |
---|
| 120 | #endif /* OVERLOAD */ |
---|
| 121 | |
---|
| 122 | #define PRIVSHIFT 8 |
---|
| 123 | |
---|
| 124 | /* Some private flags. */ |
---|
| 125 | |
---|
| 126 | #define SVpfm_COMPILED 0x80000000 |
---|
| 127 | |
---|
| 128 | #define SVpbm_VALID 0x80000000 |
---|
| 129 | #define SVpbm_TAIL 0x40000000 |
---|
| 130 | |
---|
| 131 | #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ |
---|
| 132 | #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */ |
---|
| 133 | |
---|
| 134 | struct xrv { |
---|
| 135 | SV * xrv_rv; /* pointer to another SV */ |
---|
| 136 | }; |
---|
| 137 | |
---|
| 138 | struct xpv { |
---|
| 139 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 140 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 141 | STRLEN xpv_len; /* allocated size */ |
---|
| 142 | }; |
---|
| 143 | |
---|
| 144 | struct xpviv { |
---|
| 145 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 146 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 147 | STRLEN xpv_len; /* allocated size */ |
---|
| 148 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 149 | }; |
---|
| 150 | |
---|
| 151 | struct xpvuv { |
---|
| 152 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 153 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 154 | STRLEN xpv_len; /* allocated size */ |
---|
| 155 | UV xuv_uv; /* unsigned value or pv offset */ |
---|
| 156 | }; |
---|
| 157 | |
---|
| 158 | struct xpvnv { |
---|
| 159 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 160 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 161 | STRLEN xpv_len; /* allocated size */ |
---|
| 162 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 163 | double xnv_nv; /* numeric value, if any */ |
---|
| 164 | }; |
---|
| 165 | |
---|
| 166 | struct xpvmg { |
---|
| 167 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 168 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 169 | STRLEN xpv_len; /* allocated size */ |
---|
| 170 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 171 | double xnv_nv; /* numeric value, if any */ |
---|
| 172 | MAGIC* xmg_magic; /* linked list of magicalness */ |
---|
| 173 | HV* xmg_stash; /* class package */ |
---|
| 174 | }; |
---|
| 175 | |
---|
| 176 | struct xpvlv { |
---|
| 177 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 178 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 179 | STRLEN xpv_len; /* allocated size */ |
---|
| 180 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 181 | double xnv_nv; /* numeric value, if any */ |
---|
| 182 | MAGIC* xmg_magic; /* linked list of magicalness */ |
---|
| 183 | HV* xmg_stash; /* class package */ |
---|
| 184 | |
---|
| 185 | STRLEN xlv_targoff; |
---|
| 186 | STRLEN xlv_targlen; |
---|
| 187 | SV* xlv_targ; |
---|
| 188 | char xlv_type; |
---|
| 189 | }; |
---|
| 190 | |
---|
| 191 | struct xpvgv { |
---|
| 192 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 193 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 194 | STRLEN xpv_len; /* allocated size */ |
---|
| 195 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 196 | double xnv_nv; /* numeric value, if any */ |
---|
| 197 | MAGIC* xmg_magic; /* linked list of magicalness */ |
---|
| 198 | HV* xmg_stash; /* class package */ |
---|
| 199 | |
---|
| 200 | GP* xgv_gp; |
---|
| 201 | char* xgv_name; |
---|
| 202 | STRLEN xgv_namelen; |
---|
| 203 | HV* xgv_stash; |
---|
| 204 | U8 xgv_flags; |
---|
| 205 | }; |
---|
| 206 | |
---|
| 207 | struct xpvbm { |
---|
| 208 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 209 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 210 | STRLEN xpv_len; /* allocated size */ |
---|
| 211 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 212 | double xnv_nv; /* numeric value, if any */ |
---|
| 213 | MAGIC* xmg_magic; /* linked list of magicalness */ |
---|
| 214 | HV* xmg_stash; /* class package */ |
---|
| 215 | |
---|
| 216 | I32 xbm_useful; /* is this constant pattern being useful? */ |
---|
| 217 | U16 xbm_previous; /* how many characters in string before rare? */ |
---|
| 218 | U8 xbm_rare; /* rarest character in string */ |
---|
| 219 | }; |
---|
| 220 | |
---|
| 221 | /* This structure much match XPVCV */ |
---|
| 222 | |
---|
| 223 | struct xpvfm { |
---|
| 224 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 225 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 226 | STRLEN xpv_len; /* allocated size */ |
---|
| 227 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 228 | double xnv_nv; /* numeric value, if any */ |
---|
| 229 | MAGIC* xmg_magic; /* linked list of magicalness */ |
---|
| 230 | HV* xmg_stash; /* class package */ |
---|
| 231 | |
---|
| 232 | HV * xcv_stash; |
---|
| 233 | OP * xcv_start; |
---|
| 234 | OP * xcv_root; |
---|
| 235 | void (*xcv_xsub)_((CV*)); |
---|
| 236 | ANY xcv_xsubany; |
---|
| 237 | GV * xcv_gv; |
---|
| 238 | GV * xcv_filegv; |
---|
| 239 | long xcv_depth; /* >= 2 indicates recursive call */ |
---|
| 240 | AV * xcv_padlist; |
---|
| 241 | CV * xcv_outside; |
---|
| 242 | U8 xcv_flags; |
---|
| 243 | |
---|
| 244 | I32 xfm_lines; |
---|
| 245 | }; |
---|
| 246 | |
---|
| 247 | struct xpvio { |
---|
| 248 | char * xpv_pv; /* pointer to malloced string */ |
---|
| 249 | STRLEN xpv_cur; /* length of xpv_pv as a C string */ |
---|
| 250 | STRLEN xpv_len; /* allocated size */ |
---|
| 251 | IV xiv_iv; /* integer value or pv offset */ |
---|
| 252 | double xnv_nv; /* numeric value, if any */ |
---|
| 253 | MAGIC* xmg_magic; /* linked list of magicalness */ |
---|
| 254 | HV* xmg_stash; /* class package */ |
---|
| 255 | |
---|
| 256 | PerlIO * xio_ifp; /* ifp and ofp are normally the same */ |
---|
| 257 | PerlIO * xio_ofp; /* but sockets need separate streams */ |
---|
| 258 | DIR * xio_dirp; /* for opendir, readdir, etc */ |
---|
| 259 | long xio_lines; /* $. */ |
---|
| 260 | long xio_page; /* $% */ |
---|
| 261 | long xio_page_len; /* $= */ |
---|
| 262 | long xio_lines_left; /* $- */ |
---|
| 263 | char * xio_top_name; /* $^ */ |
---|
| 264 | GV * xio_top_gv; /* $^ */ |
---|
| 265 | char * xio_fmt_name; /* $~ */ |
---|
| 266 | GV * xio_fmt_gv; /* $~ */ |
---|
| 267 | char * xio_bottom_name;/* $^B */ |
---|
| 268 | GV * xio_bottom_gv; /* $^B */ |
---|
| 269 | short xio_subprocess; /* -| or |- */ |
---|
| 270 | char xio_type; |
---|
| 271 | char xio_flags; |
---|
| 272 | }; |
---|
| 273 | |
---|
| 274 | #define IOf_ARGV 1 /* this fp iterates over ARGV */ |
---|
| 275 | #define IOf_START 2 /* check for null ARGV and substitute '-' */ |
---|
| 276 | #define IOf_FLUSH 4 /* this fp wants a flush after write op */ |
---|
| 277 | #define IOf_DIDTOP 8 /* just did top of form */ |
---|
| 278 | #define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */ |
---|
| 279 | |
---|
| 280 | /* The following macros define implementation-independent predicates on SVs. */ |
---|
| 281 | |
---|
| 282 | #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) |
---|
| 283 | #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) |
---|
| 284 | #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ |
---|
| 285 | SVp_IOK|SVp_NOK)) |
---|
| 286 | |
---|
| 287 | #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) |
---|
| 288 | |
---|
| 289 | #ifdef OVERLOAD |
---|
| 290 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ |
---|
| 291 | SvOOK_off(sv)) |
---|
| 292 | #else |
---|
| 293 | #define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv)) |
---|
| 294 | #endif /* OVERLOAD */ |
---|
| 295 | |
---|
| 296 | #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) |
---|
| 297 | #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) |
---|
| 298 | #define SvIOKp_on(sv) (SvOOK_off(sv), SvFLAGS(sv) |= SVp_IOK) |
---|
| 299 | #define SvNOKp(sv) (SvFLAGS(sv) & SVp_NOK) |
---|
| 300 | #define SvNOKp_on(sv) (SvFLAGS(sv) |= SVp_NOK) |
---|
| 301 | #define SvPOKp(sv) (SvFLAGS(sv) & SVp_POK) |
---|
| 302 | #define SvPOKp_on(sv) (SvFLAGS(sv) |= SVp_POK) |
---|
| 303 | |
---|
| 304 | #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) |
---|
| 305 | #define SvIOK_on(sv) (SvOOK_off(sv), \ |
---|
| 306 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
---|
| 307 | #define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK)) |
---|
| 308 | #define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \ |
---|
| 309 | SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) |
---|
| 310 | |
---|
| 311 | #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) |
---|
| 312 | #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
---|
| 313 | #define SvNOK_off(sv) (SvFLAGS(sv) &= ~(SVf_NOK|SVp_NOK)) |
---|
| 314 | #define SvNOK_only(sv) (SvOK_off(sv), \ |
---|
| 315 | SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) |
---|
| 316 | |
---|
| 317 | #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) |
---|
| 318 | #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
---|
| 319 | #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) |
---|
| 320 | |
---|
| 321 | #ifdef OVERLOAD |
---|
| 322 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ |
---|
| 323 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
---|
| 324 | #else |
---|
| 325 | #define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \ |
---|
| 326 | SvFLAGS(sv) |= (SVf_POK|SVp_POK)) |
---|
| 327 | #endif /* OVERLOAD */ |
---|
| 328 | |
---|
| 329 | #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) |
---|
| 330 | #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) |
---|
| 331 | #define SvOOK_off(sv) (SvOOK(sv) && sv_backoff(sv)) |
---|
| 332 | |
---|
| 333 | #define SvFAKE(sv) (SvFLAGS(sv) & SVf_FAKE) |
---|
| 334 | #define SvFAKE_on(sv) (SvFLAGS(sv) |= SVf_FAKE) |
---|
| 335 | #define SvFAKE_off(sv) (SvFLAGS(sv) &= ~SVf_FAKE) |
---|
| 336 | |
---|
| 337 | #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) |
---|
| 338 | #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) |
---|
| 339 | |
---|
| 340 | #ifdef OVERLOAD |
---|
| 341 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) |
---|
| 342 | #else |
---|
| 343 | #define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK) |
---|
| 344 | #endif /* OVERLOAD */ |
---|
| 345 | |
---|
| 346 | #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) |
---|
| 347 | #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) |
---|
| 348 | #define SvMAGICAL_off(sv) (SvFLAGS(sv) &= ~(SVs_GMG|SVs_SMG|SVs_RMG)) |
---|
| 349 | |
---|
| 350 | #define SvGMAGICAL(sv) (SvFLAGS(sv) & SVs_GMG) |
---|
| 351 | #define SvGMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_GMG) |
---|
| 352 | #define SvGMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_GMG) |
---|
| 353 | |
---|
| 354 | #define SvSMAGICAL(sv) (SvFLAGS(sv) & SVs_SMG) |
---|
| 355 | #define SvSMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_SMG) |
---|
| 356 | #define SvSMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_SMG) |
---|
| 357 | |
---|
| 358 | #define SvRMAGICAL(sv) (SvFLAGS(sv) & SVs_RMG) |
---|
| 359 | #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) |
---|
| 360 | #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) |
---|
| 361 | |
---|
| 362 | #ifdef OVERLOAD |
---|
| 363 | #define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) |
---|
| 364 | #define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) |
---|
| 365 | #define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) |
---|
| 366 | |
---|
| 367 | /* |
---|
| 368 | #define Gv_AMG(stash) \ |
---|
| 369 | (HV_AMAGICmb(stash) && \ |
---|
| 370 | ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) |
---|
| 371 | */ |
---|
| 372 | #define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash)) |
---|
| 373 | #endif /* OVERLOAD */ |
---|
| 374 | |
---|
| 375 | #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) |
---|
| 376 | |
---|
| 377 | #define SvPADBUSY(sv) (SvFLAGS(sv) & SVs_PADBUSY) |
---|
| 378 | |
---|
| 379 | #define SvPADTMP(sv) (SvFLAGS(sv) & SVs_PADTMP) |
---|
| 380 | #define SvPADTMP_on(sv) (SvFLAGS(sv) |= SVs_PADTMP|SVs_PADBUSY) |
---|
| 381 | #define SvPADTMP_off(sv) (SvFLAGS(sv) &= ~SVs_PADTMP) |
---|
| 382 | |
---|
| 383 | #define SvPADMY(sv) (SvFLAGS(sv) & SVs_PADMY) |
---|
| 384 | #define SvPADMY_on(sv) (SvFLAGS(sv) |= SVs_PADMY|SVs_PADBUSY) |
---|
| 385 | |
---|
| 386 | #define SvTEMP(sv) (SvFLAGS(sv) & SVs_TEMP) |
---|
| 387 | #define SvTEMP_on(sv) (SvFLAGS(sv) |= SVs_TEMP) |
---|
| 388 | #define SvTEMP_off(sv) (SvFLAGS(sv) &= ~SVs_TEMP) |
---|
| 389 | |
---|
| 390 | #define SvOBJECT(sv) (SvFLAGS(sv) & SVs_OBJECT) |
---|
| 391 | #define SvOBJECT_on(sv) (SvFLAGS(sv) |= SVs_OBJECT) |
---|
| 392 | #define SvOBJECT_off(sv) (SvFLAGS(sv) &= ~SVs_OBJECT) |
---|
| 393 | |
---|
| 394 | #define SvREADONLY(sv) (SvFLAGS(sv) & SVf_READONLY) |
---|
| 395 | #define SvREADONLY_on(sv) (SvFLAGS(sv) |= SVf_READONLY) |
---|
| 396 | #define SvREADONLY_off(sv) (SvFLAGS(sv) &= ~SVf_READONLY) |
---|
| 397 | |
---|
| 398 | #define SvSCREAM(sv) (SvFLAGS(sv) & SVp_SCREAM) |
---|
| 399 | #define SvSCREAM_on(sv) (SvFLAGS(sv) |= SVp_SCREAM) |
---|
| 400 | #define SvSCREAM_off(sv) (SvFLAGS(sv) &= ~SVp_SCREAM) |
---|
| 401 | |
---|
| 402 | #define SvCOMPILED(sv) (SvFLAGS(sv) & SVpfm_COMPILED) |
---|
| 403 | #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) |
---|
| 404 | #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) |
---|
| 405 | |
---|
| 406 | #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) |
---|
| 407 | #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) |
---|
| 408 | #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) |
---|
| 409 | |
---|
| 410 | #define SvVALID(sv) (SvFLAGS(sv) & SVpbm_VALID) |
---|
| 411 | #define SvVALID_on(sv) (SvFLAGS(sv) |= SVpbm_VALID) |
---|
| 412 | #define SvVALID_off(sv) (SvFLAGS(sv) &= ~SVpbm_VALID) |
---|
| 413 | |
---|
| 414 | #define SvRV(sv) ((XRV*) SvANY(sv))->xrv_rv |
---|
| 415 | #define SvRVx(sv) SvRV(sv) |
---|
| 416 | |
---|
| 417 | #define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv |
---|
| 418 | #define SvIVXx(sv) SvIVX(sv) |
---|
| 419 | #define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv |
---|
| 420 | #define SvUVXx(sv) SvUVX(sv) |
---|
| 421 | #define SvNVX(sv) ((XPVNV*)SvANY(sv))->xnv_nv |
---|
| 422 | #define SvNVXx(sv) SvNVX(sv) |
---|
| 423 | #define SvPVX(sv) ((XPV*) SvANY(sv))->xpv_pv |
---|
| 424 | #define SvPVXx(sv) SvPVX(sv) |
---|
| 425 | #define SvCUR(sv) ((XPV*) SvANY(sv))->xpv_cur |
---|
| 426 | #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len |
---|
| 427 | #define SvLENx(sv) SvLEN(sv) |
---|
| 428 | #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) |
---|
| 429 | #define SvENDx(sv) ((Sv = (sv)), SvEND(Sv)) |
---|
| 430 | #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic |
---|
| 431 | #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash |
---|
| 432 | |
---|
| 433 | #define SvIV_set(sv, val) \ |
---|
| 434 | STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ |
---|
| 435 | (((XPVIV*) SvANY(sv))->xiv_iv = val); } STMT_END |
---|
| 436 | #define SvNV_set(sv, val) \ |
---|
| 437 | STMT_START { assert(SvTYPE(sv) == SVt_NV || SvTYPE(sv) >= SVt_PVNV); \ |
---|
| 438 | (((XPVNV*) SvANY(sv))->xnv_nv = val); } STMT_END |
---|
| 439 | #define SvPV_set(sv, val) \ |
---|
| 440 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
---|
| 441 | (((XPV*) SvANY(sv))->xpv_pv = val); } STMT_END |
---|
| 442 | #define SvCUR_set(sv, val) \ |
---|
| 443 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
---|
| 444 | (((XPV*) SvANY(sv))->xpv_cur = val); } STMT_END |
---|
| 445 | #define SvLEN_set(sv, val) \ |
---|
| 446 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
---|
| 447 | (((XPV*) SvANY(sv))->xpv_len = val); } STMT_END |
---|
| 448 | #define SvEND_set(sv, val) \ |
---|
| 449 | STMT_START { assert(SvTYPE(sv) >= SVt_PV); \ |
---|
| 450 | (((XPV*) SvANY(sv))->xpv_cur = val - SvPVX(sv)); } STMT_END |
---|
| 451 | |
---|
| 452 | #define BmRARE(sv) ((XPVBM*) SvANY(sv))->xbm_rare |
---|
| 453 | #define BmUSEFUL(sv) ((XPVBM*) SvANY(sv))->xbm_useful |
---|
| 454 | #define BmPREVIOUS(sv) ((XPVBM*) SvANY(sv))->xbm_previous |
---|
| 455 | |
---|
| 456 | #define FmLINES(sv) ((XPVFM*) SvANY(sv))->xfm_lines |
---|
| 457 | |
---|
| 458 | #define LvTYPE(sv) ((XPVLV*) SvANY(sv))->xlv_type |
---|
| 459 | #define LvTARG(sv) ((XPVLV*) SvANY(sv))->xlv_targ |
---|
| 460 | #define LvTARGOFF(sv) ((XPVLV*) SvANY(sv))->xlv_targoff |
---|
| 461 | #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen |
---|
| 462 | |
---|
| 463 | #define IoIFP(sv) ((XPVIO*) SvANY(sv))->xio_ifp |
---|
| 464 | #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp |
---|
| 465 | #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp |
---|
| 466 | #define IoLINES(sv) ((XPVIO*) SvANY(sv))->xio_lines |
---|
| 467 | #define IoPAGE(sv) ((XPVIO*) SvANY(sv))->xio_page |
---|
| 468 | #define IoPAGE_LEN(sv) ((XPVIO*) SvANY(sv))->xio_page_len |
---|
| 469 | #define IoLINES_LEFT(sv)((XPVIO*) SvANY(sv))->xio_lines_left |
---|
| 470 | #define IoTOP_NAME(sv) ((XPVIO*) SvANY(sv))->xio_top_name |
---|
| 471 | #define IoTOP_GV(sv) ((XPVIO*) SvANY(sv))->xio_top_gv |
---|
| 472 | #define IoFMT_NAME(sv) ((XPVIO*) SvANY(sv))->xio_fmt_name |
---|
| 473 | #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv |
---|
| 474 | #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name |
---|
| 475 | #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv |
---|
| 476 | #define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess |
---|
| 477 | #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type |
---|
| 478 | #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags |
---|
| 479 | |
---|
| 480 | #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv)) |
---|
| 481 | #define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END |
---|
| 482 | #define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END |
---|
| 483 | |
---|
| 484 | #define SvTAINT(sv) STMT_START{ if(tainted){SvTAINTED_on(sv);} }STMT_END |
---|
| 485 | |
---|
| 486 | #ifdef CRIPPLED_CC |
---|
| 487 | |
---|
| 488 | IV SvIV _((SV* sv)); |
---|
| 489 | UV SvUV _((SV* sv)); |
---|
| 490 | double SvNV _((SV* sv)); |
---|
| 491 | #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp) |
---|
| 492 | #define SvPV(sv, lp) sv_pvn(sv, &lp) |
---|
| 493 | char *sv_pvn _((SV *, STRLEN *)); |
---|
| 494 | I32 SvTRUE _((SV *)); |
---|
| 495 | |
---|
| 496 | #define SvIVx(sv) SvIV(sv) |
---|
| 497 | #define SvUVx(sv) SvUV(sv) |
---|
| 498 | #define SvNVx(sv) SvNV(sv) |
---|
| 499 | #define SvPVx(sv, lp) sv_pvn(sv, &lp) |
---|
| 500 | #define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp) |
---|
| 501 | #define SvTRUEx(sv) SvTRUE(sv) |
---|
| 502 | |
---|
| 503 | #else /* !CRIPPLED_CC */ |
---|
| 504 | |
---|
| 505 | #undef SvIV |
---|
| 506 | #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) |
---|
| 507 | |
---|
| 508 | #undef SvUV |
---|
| 509 | #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) |
---|
| 510 | |
---|
| 511 | #undef SvNV |
---|
| 512 | #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv)) |
---|
| 513 | |
---|
| 514 | #undef SvPV |
---|
| 515 | #define SvPV(sv, lp) \ |
---|
| 516 | (SvPOK(sv) ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv(sv, &lp)) |
---|
| 517 | |
---|
| 518 | #undef SvPV_force |
---|
| 519 | #define SvPV_force(sv, lp) \ |
---|
| 520 | ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ |
---|
| 521 | ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp)) |
---|
| 522 | |
---|
| 523 | #undef SvTRUE |
---|
| 524 | #define SvTRUE(sv) ( \ |
---|
| 525 | !sv \ |
---|
| 526 | ? 0 \ |
---|
| 527 | : SvPOK(sv) \ |
---|
| 528 | ? ((Xpv = (XPV*)SvANY(sv)) && \ |
---|
| 529 | (*Xpv->xpv_pv > '0' || \ |
---|
| 530 | Xpv->xpv_cur > 1 || \ |
---|
| 531 | (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \ |
---|
| 532 | ? 1 \ |
---|
| 533 | : 0) \ |
---|
| 534 | : \ |
---|
| 535 | SvIOK(sv) \ |
---|
| 536 | ? SvIVX(sv) != 0 \ |
---|
| 537 | : SvNOK(sv) \ |
---|
| 538 | ? SvNVX(sv) != 0.0 \ |
---|
| 539 | : sv_2bool(sv) ) |
---|
| 540 | |
---|
| 541 | #define SvIVx(sv) ((Sv = (sv)), SvIV(Sv)) |
---|
| 542 | #define SvUVx(sv) ((Sv = (sv)), SvUV(Sv)) |
---|
| 543 | #define SvNVx(sv) ((Sv = (sv)), SvNV(Sv)) |
---|
| 544 | #define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp)) |
---|
| 545 | #define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv)) |
---|
| 546 | |
---|
| 547 | #endif /* CRIPPLED_CC */ |
---|
| 548 | |
---|
| 549 | #define newRV_inc(sv) newRV(sv) |
---|
| 550 | #ifdef CRIPPLED_CC |
---|
| 551 | SV *newRV_noinc _((SV *)); |
---|
| 552 | #else |
---|
| 553 | #define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv) |
---|
| 554 | #endif |
---|
| 555 | |
---|
| 556 | /* the following macro updates any magic values this sv is associated with */ |
---|
| 557 | |
---|
| 558 | #define SvSETMAGIC(x) if (SvSMAGICAL(x)) mg_set(x) |
---|
| 559 | |
---|
| 560 | #define SvSetSV_and(dst,src,finally) \ |
---|
| 561 | if ((dst) != (src)) { \ |
---|
| 562 | sv_setsv(dst, src); \ |
---|
| 563 | finally; \ |
---|
| 564 | } |
---|
| 565 | #define SvSetSV_nosteal_and(dst,src,finally) \ |
---|
| 566 | if ((dst) != (src)) { \ |
---|
| 567 | U32 tMpF = SvFLAGS(src) & SVs_TEMP; \ |
---|
| 568 | SvTEMP_off(src); \ |
---|
| 569 | sv_setsv(dst, src); \ |
---|
| 570 | SvFLAGS(src) |= tMpF; \ |
---|
| 571 | finally; \ |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | #define SvSetSV(dst,src) \ |
---|
| 575 | SvSetSV_and(dst,src,/*nothing*/;) |
---|
| 576 | #define SvSetSV_nosteal(dst,src) \ |
---|
| 577 | SvSetSV_nosteal_and(dst,src,/*nothing*/;) |
---|
| 578 | |
---|
| 579 | #define SvSetMagicSV(dst,src) \ |
---|
| 580 | SvSetSV_and(dst,src,SvSETMAGIC(dst)) |
---|
| 581 | #define SvSetMagicSV_nosteal(dst,src) \ |
---|
| 582 | SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst)) |
---|
| 583 | |
---|
| 584 | #define SvPEEK(sv) sv_peek(sv) |
---|
| 585 | |
---|
| 586 | #define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no) |
---|
| 587 | |
---|
| 588 | #define boolSV(b) ((b) ? &sv_yes : &sv_no) |
---|
| 589 | |
---|
| 590 | #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) |
---|
| 591 | |
---|
| 592 | #ifndef DOSISH |
---|
| 593 | # define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) |
---|
| 594 | # define Sv_Grow sv_grow |
---|
| 595 | #else |
---|
| 596 | /* extra parentheses intentionally NOT placed around "len"! */ |
---|
| 597 | # define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \ |
---|
| 598 | ? sv_grow(sv,(unsigned long)len) : SvPVX(sv)) |
---|
| 599 | # define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len)) |
---|
| 600 | #endif /* DOSISH */ |
---|