X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=sv.h;h=ab09bba30660f48e4e9e137d47aa436302319847;hb=ac9dac7f0e1dffa602850506b980a255334a4f40;hp=fc49f23b4996ca66ec7f78d22b42c04ee542d3ba;hpb=b37c2d43c8bccbefe3985273e9661833102148d0;p=p5sagit%2Fp5-mst-13.2.git diff --git a/sv.h b/sv.h index fc49f23..ab09bba 100644 --- a/sv.h +++ b/sv.h @@ -158,11 +158,11 @@ Same as SvREFCNT_inc, but can only be used if you know I is not NULL. Since we don't have to check the NULLness, it's faster and smaller. -=for apidoc Am|SV*|SvREFCNT_inc_void|SV* sv +=for apidoc Am|void|SvREFCNT_inc_void|SV* sv Same as SvREFCNT_inc, but can only be used if you don't need the return value. The macro doesn't need to return a meaningful value. -=for apidoc Am|SV*|SvREFCNT_inc_void_NN|SV* sv +=for apidoc Am|void|SvREFCNT_inc_void_NN|SV* sv Same as SvREFCNT_inc, but can only be used if you don't need the return value, and you know that I is not NULL. The macro doesn't need to return a meaningful value, or check for NULLness, so it's smaller @@ -178,12 +178,15 @@ Same as SvREFCNT_inc_simple, but can only be used if you know I is not NULL. Since we don't have to check the NULLness, it's faster and smaller. -=for apidoc Am|SV*|SvREFCNT_inc_simple_void|SV* sv +=for apidoc Am|void|SvREFCNT_inc_simple_void|SV* sv Same as SvREFCNT_inc_simple, but can only be used if you don't need the return value. The macro doesn't need to return a meaningful value. -=for apidoc Am|SV*|SvREFCNT_inc|SV* sv -Increments the reference count of the given SV. +=for apidoc Am|void|SvREFCNT_inc_simple_void_NN|SV* sv +Same as SvREFCNT_inc, but can only be used if you don't need the return +value, and you know that I is not NULL. The macro doesn't need +to return a meaningful value, or check for NULLness, so it's smaller +and faster. =for apidoc Am|void|SvREFCNT_dec|SV* sv Decrements the reference count of the given SV. @@ -214,7 +217,7 @@ perform the upgrade if necessary. See C. ({ \ if (sv) \ (SvREFCNT(sv))++; \ - sv; \ + (SV *)(sv); \ }) # define SvREFCNT_inc_NN(sv) \ ({ \ @@ -240,7 +243,7 @@ perform the upgrade if necessary. See C. #endif /* These guys don't need the curly blocks */ -#define SvREFCNT_inc_simple_void(sv) if (sv) (SvREFCNT(sv)++); +#define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END #define SvREFCNT_inc_simple_NN(sv) (++(SvREFCNT(sv)),(SV*)(sv)) #define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) @@ -263,7 +266,7 @@ perform the upgrade if necessary. See C. #endif #define SVTYPEMASK 0xff -#define SvTYPE(sv) ((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 @@ -284,6 +287,7 @@ perform the upgrade if necessary. See C. #define SVphv_CLONEABLE 0x00008000 /* PVHV (stashes) clone its objects */ #define SVs_PADSTALE 0x00010000 /* lexical has gone out of scope */ +#define SVpad_STATE 0x00010000 /* pad name is a "state" var */ #define SVs_PADTMP 0x00020000 /* in use as tmp */ #define SVpad_TYPED 0x00020000 /* pad name is a Typed Lexical */ #define SVs_PADMY 0x00040000 /* in use a "my" variable */ @@ -307,8 +311,9 @@ perform the upgrade if necessary. See C. fact an offset [SvREPADTMP(sv)] 5: On a pad name SV, that slot in the frame AV is a REFCNT'ed reference - to a lexical from "outside". - */ + to a lexical from "outside". */ +#define SVphv_REHASH SVf_FAKE /* 6: On a PVHV, hash values are being + recalculated */ #define SVf_OOK 0x02000000 /* has valid offset value For a PVHV this means that a hv_aux struct is present after the @@ -334,13 +339,12 @@ perform the upgrade if necessary. See C. /* Some private flags. */ /* PVHV */ -#define SVphv_REHASH 0x10000000 /* PVHV is recalculating hash values */ -/* PVHV */ #define SVphv_SHAREKEYS 0x20000000 /* PVHV keys live on shared string table */ /* PVNV, PVMG, PVGV, presumably only inside pads */ #define SVpad_NAME 0x40000000 /* This SV is a name in the PAD, so - SVpad_TYPED and SVpad_OUR apply */ + SVpad_TYPED, SVpad_OUR and + SVpad_STATE apply */ /* PVAV */ #define SVpav_REAL 0x40000000 /* free old entries */ /* PVHV */ @@ -395,6 +399,7 @@ struct xpviv { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; }; @@ -409,6 +414,7 @@ typedef struct { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; } xpviv_allocated; #endif @@ -426,6 +432,7 @@ struct xpvuv { IV xuvu_iv; UV xuvu_uv; /* unsigned value or pv offset */ void * xuvu_p1; + HEK * xivu_namehek; } xuv_u; }; @@ -443,6 +450,7 @@ struct xpvnv { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; }; @@ -459,6 +467,7 @@ struct xpvmg { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -479,6 +488,7 @@ struct xpvlv { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; /* GvNAME */ } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -486,10 +496,6 @@ struct xpvlv { } xmg_u; HV* xmg_stash; /* class package */ - /* a full glob fits into this */ - char* xgv_name; - STRLEN xgv_namelen; - STRLEN xlv_targoff; STRLEN xlv_targlen; SV* xlv_targ; @@ -505,10 +511,11 @@ struct xpvgv { STRLEN xpv_cur; /* xgv_flags */ STRLEN xpv_len; /* 0 */ union { - IV xivu_iv; /* integer value or pv offset */ + IV xivu_iv; UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; /* GvNAME */ } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -516,8 +523,6 @@ struct xpvgv { } xmg_u; HV* xmg_stash; /* class package */ - char* xgv_name; - STRLEN xgv_namelen; }; struct xpvbm { @@ -532,6 +537,7 @@ struct xpvbm { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -560,6 +566,7 @@ struct xpvfm { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -595,6 +602,7 @@ typedef struct { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -634,6 +642,7 @@ struct xpvio { UV xivu_uv; void * xivu_p1; I32 xivu_i32; + HEK * xivu_namehek; } xiv_u; union { MAGIC* xmg_magic; /* linked list of magicalness */ @@ -833,7 +842,7 @@ Set the value of the RV pointer in sv to val. See C. =for apidoc Am|void|SvMAGIC_set|SV* sv|MAGIC* val Set the value of the MAGIC pointer in sv to val. See C. -=for apidoc Am|void|SvSTASH_set|SV* sv|STASH* val +=for apidoc Am|void|SvSTASH_set|SV* sv|HV* val Set the value of the STASH pointer in sv to val. See C. =for apidoc Am|void|SvCUR_set|SV* sv|STRLEN len @@ -861,11 +870,11 @@ Set the actual length of the string which is in the SV. See C. #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) #define SvOK_off(sv) (assert_not_ROK(sv) assert_not_glob(sv) \ - SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ + SvFLAGS(sv) &= ~(SVf_OK| \ SVf_IVisUV|SVf_UTF8), \ SvOOK_off(sv)) #define SvOK_off_exc_UV(sv) (assert_not_ROK(sv) \ - SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ + SvFLAGS(sv) &= ~(SVf_OK| \ SVf_UTF8), \ SvOOK_off(sv)) @@ -934,16 +943,20 @@ in gv.h: */ SvFLAGS(sv) |= (SVf_POK|SVp_POK)) #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) #define SvPOK_only(sv) (assert_not_ROK(sv) assert_not_glob(sv) \ - SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ + SvFLAGS(sv) &= ~(SVf_OK| \ SVf_IVisUV|SVf_UTF8), \ SvFLAGS(sv) |= (SVf_POK|SVp_POK)) #define SvPOK_only_UTF8(sv) (assert_not_ROK(sv) assert_not_glob(sv) \ - SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ + SvFLAGS(sv) &= ~(SVf_OK| \ SVf_IVisUV), \ SvFLAGS(sv) |= (SVf_POK|SVp_POK)) #define SvVOK(sv) (SvMAGICAL(sv) \ + && mg_find(sv,PERL_MAGIC_vstring)) +/* returns the vstring magic, if any */ +#define SvVSTRING_mg(sv) (SvMAGICAL(sv) \ ? mg_find(sv,PERL_MAGIC_vstring) : NULL) + #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) #define SvOOK_on(sv) ((void)SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) #define SvOOK_off(sv) ((void)(SvOOK(sv) && sv_backoff(sv))) @@ -954,7 +967,7 @@ in gv.h: */ #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) -#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) +#define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK)) #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) @@ -972,17 +985,36 @@ in gv.h: */ #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) -#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) -#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) -#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) - -#define SvGAMAGIC(sv) (SvFLAGS(sv) & (SVs_GMG|SVf_AMAGIC)) +#define SvAMAGIC(sv) (SvROK(sv) && (SvFLAGS(SvRV(sv)) & SVf_AMAGIC)) +#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) +# define SvAMAGIC_on(sv) ({ SV * const kloink = sv; \ + assert(SvROK(kloink)); \ + SvFLAGS(SvRV(kloink)) |= SVf_AMAGIC; \ + }) +# define SvAMAGIC_off(sv) ({ SV * const kloink = sv; \ + if(SvROK(kloink)) \ + SvFLAGS(SvRV(kloink)) &= ~SVf_AMAGIC;\ + }) +#else +# define SvAMAGIC_on(sv) (SvFLAGS(SvRV(sv)) |= SVf_AMAGIC) +# define SvAMAGIC_off(sv) \ + (SvROK(sv) && (SvFLAGS(SvRV(sv)) &= ~SVf_AMAGIC)) +#endif /* -#define Gv_AMG(stash) \ - (HV_AMAGICmb(stash) && \ - ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) +=for apidoc Am|char*|SvGAMAGIC|SV* sv + +Returns true if the SV has get magic or overloading. If either is true then +the scalar is active data, and has the potential to return a new value every +time it is accessed. Hence you must be careful to only read it once per user +logical operation and work with that returned value. If neither is true then +the scalar's value cannot change unless written to. + +=cut */ + +#define SvGAMAGIC(sv) (SvGMAGICAL(sv) || SvAMAGIC(sv)) + #define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash)) #define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \ @@ -1051,6 +1083,10 @@ in gv.h: */ ((SvFLAGS(sv) & (SVpad_NAME|SVpad_OUR)) == (SVpad_NAME|SVpad_OUR)) #define SvPAD_OUR_on(sv) (SvFLAGS(sv) |= SVpad_NAME|SVpad_OUR) +#define SvPAD_STATE(sv) \ + ((SvFLAGS(sv) & (SVpad_NAME|SVpad_STATE)) == (SVpad_NAME|SVpad_STATE)) +#define SvPAD_STATE_on(sv) (SvFLAGS(sv) |= SVpad_NAME|SVpad_STATE) + #define OURSTASH(sv) \ (SvPAD_OUR(sv) ? ((XPVMG*) SvANY(sv))->xmg_u.xmg_ourstash : NULL) #define OURSTASH_set(sv, st) \ @@ -1141,6 +1177,8 @@ in gv.h: */ # define SvMAGIC(sv) \ (*({ SV *const _svi = (SV *) sv; \ assert(SvTYPE(_svi) >= SVt_PVMG); \ + if(SvTYPE(_svi) == SVt_PVMG) \ + assert(!SvPAD_OUR(_svi)); \ &(((XPVMG*) SvANY(_svi))->xmg_u.xmg_magic); \ })) # define SvSTASH(sv) \ @@ -1626,9 +1664,12 @@ Like C but doesn't process magic. #define SV_CONST_RETURN 32 #define SV_MUTABLE_RETURN 64 #define SV_SMAGIC 128 +#define SV_HAS_TRAILING_NUL 256 #define sv_unref(sv) sv_unref_flags(sv, 0) #define sv_force_normal(sv) sv_force_normal_flags(sv, 0) +#define sv_usepvn(sv, p, l) sv_usepvn_flags(sv, p, l, 0) +#define sv_usepvn_mg(sv, p, l) sv_usepvn_flags(sv, p, l, SV_SMAGIC) /* We are about to replace the SV's current value. So if it's copy on write we need to normalise it. Use the SV_COW_DROP_PV flag hint to say that @@ -1649,7 +1690,7 @@ Like C but doesn't process magic. #define CAN_COW_MASK (SVs_OBJECT|SVs_GMG|SVs_SMG|SVs_RMG|SVf_IOK|SVf_NOK| \ SVf_POK|SVf_ROK|SVp_IOK|SVp_NOK|SVp_POK|SVf_FAKE| \ - SVf_OOK|SVf_BREAK|SVf_READONLY|SVf_AMAGIC) + SVf_OOK|SVf_BREAK|SVf_READONLY) #define CAN_COW_FLAGS (SVp_POK|SVf_POK) #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) \