X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=sv.h;h=7098088463c9bcc57d4092f91a25603ea909faa3;hb=959037a055713bbf644c83e4acd1a40a7f4d58c7;hp=276144d0e6641f2a68a1b76cc808e34b244ca10a;hpb=fbf9f98379663b1157bb1fda639aa04bc8781c89;p=p5sagit%2Fp5-mst-13.2.git diff --git a/sv.h b/sv.h index 276144d..7098088 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 @@ -274,7 +273,7 @@ perform the upgrade if necessary. See C. #endif #define SVTYPEMASK 0xff -#define SvTYPE(sv) (svtype)((sv)->sv_flags & SVTYPEMASK) +#define SvTYPE(sv) ((svtype)((sv)->sv_flags & SVTYPEMASK)) /* Sadly there are some parts of the core that have pointers to already-freed SV heads, and rely on being able to tell that they are now free. So mark @@ -331,7 +330,7 @@ perform the upgrade if necessary. See C. means that a hv_aux struct is present after the main array */ #define SVf_BREAK 0x04000000 /* refcnt is artificially low - used by - SV's in final arena cleanup */ + SV's in final arena cleanup */ #define SVf_READONLY 0x08000000 /* may not be modified */ @@ -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 */ @@ -741,9 +745,8 @@ struct xpvio { GV * xio_fmt_gv; /* $~ */ char * xio_bottom_name;/* $^B */ GV * xio_bottom_gv; /* $^B */ - short xio_subprocess; /* -| or |- */ char xio_type; - char xio_flags; + U8 xio_flags; }; #define xio_dirp xio_dirpu.xiou_dirp #define xio_any xio_dirpu.xiou_any @@ -1215,9 +1218,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 +1228,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 +1296,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 +1324,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 +1384,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) \ @@ -1480,7 +1497,6 @@ the scalar's value cannot change unless written to. #define IoFMT_GV(sv) ((XPVIO*) SvANY(sv))->xio_fmt_gv #define IoBOTTOM_NAME(sv)((XPVIO*) SvANY(sv))->xio_bottom_name #define IoBOTTOM_GV(sv) ((XPVIO*) SvANY(sv))->xio_bottom_gv -#define IoSUBPROCESS(sv)((XPVIO*) SvANY(sv))->xio_subprocess #define IoTYPE(sv) ((XPVIO*) SvANY(sv))->xio_type #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags @@ -1550,7 +1566,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. @@ -1561,7 +1579,7 @@ the SV if the SV does not contain a string. The SV may cache the stringified form becoming C. Handles 'get' magic. =for apidoc Am|IV|SvIV|SV* sv -Coerces the given SV to an integer and returns it. See C for a +Coerces the given SV to an integer and returns it. See C for a version which guarantees to evaluate sv only once. =for apidoc Am|IV|SvIV_nomg|SV* sv @@ -1569,15 +1587,17 @@ 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 +Coerce the given SV to a double and return it. See C for a version 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 +1608,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 +1856,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 @@ -1865,8 +1888,8 @@ Like C but doesn't process magic. sv_force_normal_flags(sv, SV_COW_DROP_PV) #ifdef PERL_OLD_COPY_ON_WRITE -# define SvRELEASE_IVX(sv) ((void)((SvFLAGS(sv) & (SVf_OOK|SVf_READONLY|SVf_FAKE)) \ - && Perl_sv_release_IVX(aTHX_ sv))) +#define SvRELEASE_IVX(sv) \ + ((SvIsCOW(sv) ? sv_force_normal_flags(sv, 0) : (void) 0), SvOOK_off(sv)) # define SvIsCOW_normal(sv) (SvIsCOW(sv) && SvLEN(sv)) #else # define SvRELEASE_IVX(sv) SvOOK_off(sv) @@ -1985,6 +2008,7 @@ Returns a pointer to the character buffer. #define SvSHARE(sv) CALL_FPTR(PL_sharehook)(aTHX_ sv) #define SvLOCK(sv) CALL_FPTR(PL_lockhook)(aTHX_ sv) #define SvUNLOCK(sv) CALL_FPTR(PL_unlockhook)(aTHX_ sv) +#define SvDESTROYABLE(sv) CALL_FPTR(PL_destroyhook)(aTHX_ sv) #define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END #define SvSETMAGIC(x) STMT_START { if (SvSMAGICAL(x)) mg_set(x); } STMT_END