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