X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=sv.h;h=dd1350531379b104e978208734a23d6dd2b415c9;hb=ac09da3b9065d6e75850e3772d9b883653c64a70;hp=ba873ea5ee7dde10bb8459532b3ef00c4a153fbd;hpb=1fef4616ad97a72dc45194bd8ac11e63e518aba2;p=p5sagit%2Fp5-mst-13.2.git diff --git a/sv.h b/sv.h index ba873ea..dd13505 100644 --- a/sv.h +++ b/sv.h @@ -177,9 +177,8 @@ to return a meaningful value, or check for NULLness, so it's smaller and faster. =for apidoc Am|SV*|SvREFCNT_inc_simple|SV* sv -Same as SvREFCNT_inc, but can only be used with simple variables, not -expressions or pointer dereferences. Since we don't have to store a -temporary value, it's faster. +Same as SvREFCNT_inc, but can only be used with expressions without side +effects. Since we don't have to store a temporary value, it's faster. =for apidoc Am|SV*|SvREFCNT_inc_simple_NN|SV* sv Same as SvREFCNT_inc_simple, but can only be used if you know I @@ -345,15 +344,20 @@ perform the upgrade if necessary. See C. #define PRIVSHIFT 4 /* (SVp_?OK >> PRIVSHIFT) == SVf_?OK */ #define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ + +/* Ensure this value does not clash with the GV_ADD* flags in gv.h: */ #define SVf_UTF8 0x20000000 /* SvPV is UTF-8 encoded This is also set on RVs whose overloaded stringification is UTF-8. This might only happen as a side effect of SvPV() */ -/* Ensure this value does not clash with the GV_ADD* flags in gv.h */ /* Some private flags. */ +/* PVAV could probably use 0x2000000 without conflict. I assume that PVFM can + be UTF-8 encoded, and PVCVs could well have UTF-8 prototypes. PVIOs haven't + been restructured, so sometimes get used as string buffers. */ + /* PVHV */ #define SVphv_SHAREKEYS 0x20000000 /* PVHV keys live on shared string table */ /* PVNV, PVMG, presumably only inside pads */ @@ -1215,9 +1219,7 @@ the scalar's value cannot change unless written to. } STMT_END #ifdef PERL_DEBUG_COW -#define SvRV(sv) (0 + (sv)->sv_u.svu_rv) #else -#define SvRV(sv) ((sv)->sv_u.svu_rv) #endif #define SvRVx(sv) SvRV(sv) @@ -1227,6 +1229,7 @@ the scalar's value cannot change unless written to. # define SvIVX(sv) (0 + ((XPVIV*) SvANY(sv))->xiv_iv) # define SvUVX(sv) (0 + ((XPVUV*) SvANY(sv))->xuv_uv) # define SvNVX(sv) (-0.0 + ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv) +# define SvRV(sv) (0 + (sv)->sv_u.svu_rv) /* Don't test the core XS code yet. */ # if defined (PERL_CORE) && PERL_DEBUG_COW > 1 # define SvPVX(sv) (0 + (assert(!SvREADONLY(sv)), (sv)->sv_u.svu_pv)) @@ -1294,6 +1297,16 @@ the scalar's value cannot change unless written to. assert(!isGV_with_GP(_svi)); \ &(((XPVNV*) SvANY(_svi))->xnv_u.xnv_nv); \ })) +# define SvRV(sv) \ + (*({ SV *const _svi = (SV *) (sv); \ + assert(SvTYPE(_svi) >= SVt_RV); \ + assert(SvTYPE(_svi) != SVt_PVAV); \ + assert(SvTYPE(_svi) != SVt_PVHV); \ + assert(SvTYPE(_svi) != SVt_PVCV); \ + assert(SvTYPE(_svi) != SVt_PVFM); \ + assert(!isGV_with_GP(_svi)); \ + &((_svi)->sv_u.svu_rv); \ + })) # define SvMAGIC(sv) \ (*({ SV *const _svi = (SV *) (sv); \ assert(SvTYPE(_svi) >= SVt_PVMG); \ @@ -1312,6 +1325,7 @@ the scalar's value cannot change unless written to. # define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv # define SvUVX(sv) ((XPVUV*) SvANY(sv))->xuv_uv # define SvNVX(sv) ((XPVNV*) SvANY(sv))->xnv_u.xnv_nv +# define SvRV(sv) ((sv)->sv_u.svu_rv) # define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_u.xmg_magic # define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash # endif @@ -1371,6 +1385,10 @@ the scalar's value cannot change unless written to. (((XPVUV*)SvANY(sv))->xuv_uv = (val)); } STMT_END #define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ + assert(SvTYPE(sv) != SVt_PVAV); \ + assert(SvTYPE(sv) != SVt_PVHV); \ + assert(SvTYPE(sv) != SVt_PVCV); \ + assert(SvTYPE(sv) != SVt_PVFM); \ assert(!isGV_with_GP(sv)); \ ((sv)->sv_u.svu_rv = (val)); } STMT_END #define SvMAGIC_set(sv, val) \ @@ -1550,7 +1568,9 @@ stringified version becoming C. Handles 'get' magic. See also C for a version which guarantees to evaluate sv only once. =for apidoc Am|char*|SvPVx|SV* sv|STRLEN len -A version of C which guarantees to evaluate sv only once. +A version of C which guarantees to evaluate C only once. +Only use this if C is an expression with side effects, otherwise use the +more efficient C. =for apidoc Am|char*|SvPV_nomg|SV* sv|STRLEN len Like C but doesn't process magic. @@ -1569,7 +1589,8 @@ Like C but doesn't process magic. =for apidoc Am|IV|SvIVx|SV* sv Coerces the given SV to an integer and returns it. Guarantees to evaluate -sv only once. Use the more efficient C otherwise. +C only once. Only use this if C is an expression with side effects, +otherwise use the more efficient C. =for apidoc Am|NV|SvNV|SV* sv Coerce the given SV to a double and return it. See C for a version @@ -1577,7 +1598,8 @@ which guarantees to evaluate sv only once. =for apidoc Am|NV|SvNVx|SV* sv Coerces the given SV to a double and returns it. Guarantees to evaluate -sv only once. Use the more efficient C otherwise. +C only once. Only use this if C is an expression with side effects, +otherwise use the more efficient C. =for apidoc Am|UV|SvUV|SV* sv Coerces the given SV to an unsigned integer and returns it. See C @@ -1588,7 +1610,8 @@ Like C but doesn't process magic. =for apidoc Am|UV|SvUVx|SV* sv Coerces the given SV to an unsigned integer and returns it. Guarantees to -evaluate sv only once. Use the more efficient C otherwise. +C only once. Only use this if C is an expression with side effects, +otherwise use the more efficient C. =for apidoc Am|bool|SvTRUE|SV* sv Returns a boolean indicating whether Perl would evaluate the SV as true or @@ -1835,13 +1858,15 @@ Like C but doesn't process magic. #define SV_SMAGIC 128 #define SV_HAS_TRAILING_NUL 256 #define SV_COW_SHARED_HASH_KEYS 512 +/* This one is only enabled for PERL_OLD_COPY_ON_WRITE */ +#define SV_COW_OTHER_PVS 1024 /* The core is safe for this COW optimisation. XS code on CPAN may not be. So only default to doing the COW setup if we're in the core. */ #ifdef PERL_CORE # ifndef SV_DO_COW_SVSETSV -# define SV_DO_COW_SVSETSV SV_COW_SHARED_HASH_KEYS +# define SV_DO_COW_SVSETSV SV_COW_SHARED_HASH_KEYS|SV_COW_OTHER_PVS # endif #endif