📄 sv.h
字号:
some of Perl's fundamental security features. XS module authors should notuse this function unless they fully understand all the implications ofunconditionally untainting the value. Untainting should be done in thestandard perl fashion, via a carefully crafted regexp, rather than directlyuntainting variables.=for apidoc Am|void|SvTAINT|SV* svTaints an SV if tainting is enabled.=cut*/#define sv_taint(sv) sv_magic((sv), NULL, PERL_MAGIC_taint, NULL, 0)#define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv))#define SvTAINTED_on(sv) STMT_START{ if(PL_tainting){sv_taint(sv);} }STMT_END#define SvTAINTED_off(sv) STMT_START{ if(PL_tainting){sv_untaint(sv);} }STMT_END#define SvTAINT(sv) \ STMT_START { \ if (PL_tainting) { \ if (PL_tainted) \ SvTAINTED_on(sv); \ } \ } STMT_END/*=for apidoc Am|char*|SvPV_force|SV* sv|STRLEN lenLike C<SvPV> but will force the SV into containing just a string(C<SvPOK_only>). You want force if you are going to update the C<SvPVX>directly.=for apidoc Am|char*|SvPV_force_nomg|SV* sv|STRLEN lenLike C<SvPV> but will force the SV into containing just a string(C<SvPOK_only>). You want force if you are going to update the C<SvPVX>directly. Doesn't process magic.=for apidoc Am|char*|SvPV|SV* sv|STRLEN lenReturns a pointer to the string in the SV, or a stringified form ofthe SV if the SV does not contain a string. The SV may cache thestringified version becoming C<SvPOK>. Handles 'get' magic. See alsoC<SvPVx> for a version which guarantees to evaluate sv only once.=for apidoc Am|char*|SvPVx|SV* sv|STRLEN lenA version of C<SvPV> which guarantees to evaluate C<sv> only once.Only use this if C<sv> is an expression with side effects, otherwise use themore efficient C<SvPVX>.=for apidoc Am|char*|SvPV_nomg|SV* sv|STRLEN lenLike C<SvPV> but doesn't process magic.=for apidoc Am|char*|SvPV_nolen|SV* svReturns a pointer to the string in the SV, or a stringified form ofthe SV if the SV does not contain a string. The SV may cache thestringified form becoming C<SvPOK>. Handles 'get' magic.=for apidoc Am|IV|SvIV|SV* svCoerces the given SV to an integer and returns it. See C<SvIVx> for aversion which guarantees to evaluate sv only once.=for apidoc Am|IV|SvIV_nomg|SV* svLike C<SvIV> but doesn't process magic.=for apidoc Am|IV|SvIVx|SV* svCoerces the given SV to an integer and returns it. Guarantees to evaluateC<sv> only once. Only use this if C<sv> is an expression with side effects,otherwise use the more efficient C<SvIV>.=for apidoc Am|NV|SvNV|SV* svCoerce the given SV to a double and return it. See C<SvNVx> for a versionwhich guarantees to evaluate sv only once.=for apidoc Am|NV|SvNVx|SV* svCoerces the given SV to a double and returns it. Guarantees to evaluateC<sv> only once. Only use this if C<sv> is an expression with side effects,otherwise use the more efficient C<SvNV>.=for apidoc Am|UV|SvUV|SV* svCoerces the given SV to an unsigned integer and returns it. See C<SvUVx>for a version which guarantees to evaluate sv only once.=for apidoc Am|UV|SvUV_nomg|SV* svLike C<SvUV> but doesn't process magic.=for apidoc Am|UV|SvUVx|SV* svCoerces the given SV to an unsigned integer and returns it. Guarantees toC<sv> only once. Only use this if C<sv> is an expression with side effects,otherwise use the more efficient C<SvUV>.=for apidoc Am|bool|SvTRUE|SV* svReturns a boolean indicating whether Perl would evaluate the SV as true orfalse, defined or undefined. Does not handle 'get' magic.=for apidoc Am|char*|SvPVutf8_force|SV* sv|STRLEN lenLike C<SvPV_force>, but converts sv to utf8 first if necessary.=for apidoc Am|char*|SvPVutf8|SV* sv|STRLEN lenLike C<SvPV>, but converts sv to utf8 first if necessary.=for apidoc Am|char*|SvPVutf8_nolen|SV* svLike C<SvPV_nolen>, but converts sv to utf8 first if necessary.=for apidoc Am|char*|SvPVbyte_force|SV* sv|STRLEN lenLike C<SvPV_force>, but converts sv to byte representation first if necessary.=for apidoc Am|char*|SvPVbyte|SV* sv|STRLEN lenLike C<SvPV>, but converts sv to byte representation first if necessary.=for apidoc Am|char*|SvPVbyte_nolen|SV* svLike C<SvPV_nolen>, but converts sv to byte representation first if necessary.=for apidoc Am|char*|SvPVutf8x_force|SV* sv|STRLEN lenLike C<SvPV_force>, but converts sv to utf8 first if necessary.Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>otherwise.=for apidoc Am|char*|SvPVutf8x|SV* sv|STRLEN lenLike C<SvPV>, but converts sv to utf8 first if necessary.Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>otherwise.=for apidoc Am|char*|SvPVbytex_force|SV* sv|STRLEN lenLike C<SvPV_force>, but converts sv to byte representation first if necessary.Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>otherwise.=for apidoc Am|char*|SvPVbytex|SV* sv|STRLEN lenLike C<SvPV>, but converts sv to byte representation first if necessary.Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>otherwise.=for apidoc Am|bool|SvIsCOW|SV* svReturns a boolean indicating whether the SV is Copy-On-Write. (either sharedhash key scalars, or full Copy On Write scalars if 5.9.0 is configured forCOW)=for apidoc Am|bool|SvIsCOW_shared_hash|SV* svReturns a boolean indicating whether the SV is Copy-On-Write shared hash keyscalar.=for apidoc Am|void|sv_catpvn_nomg|SV* sv|const char* ptr|STRLEN lenLike C<sv_catpvn> but doesn't process magic.=for apidoc Am|void|sv_setsv_nomg|SV* dsv|SV* ssvLike C<sv_setsv> but doesn't process magic.=for apidoc Am|void|sv_catsv_nomg|SV* dsv|SV* ssvLike C<sv_catsv> but doesn't process magic.=cut*//* Let us hope that bitmaps for UV and IV are the same */#define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))#define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))#define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))#define SvIV_nomg(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv_flags(sv, 0))#define SvUV_nomg(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv_flags(sv, 0))/* ----*/#define SvPV(sv, lp) SvPV_flags(sv, lp, SV_GMAGIC)#define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC)#define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC)#define SvPV_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags))#define SvPV_flags_const(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN))#define SvPV_flags_const_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : \ (const char*) sv_2pv_flags(sv, 0, flags|SV_CONST_RETURN))#define SvPV_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN))#define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC)#define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC)#define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC)#define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0)#define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0)#define SvPV_force_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags))#define SvPV_force_flags_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? SvPVX(sv) : sv_pvn_force_flags(sv, 0, flags))#define SvPV_force_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN))#define SvPV_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC))#define SvPV_nolen_const(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : sv_2pv_flags(sv, 0, SV_GMAGIC|SV_CONST_RETURN))#define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0)#define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0)#define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0)/* ----*/#define SvPVutf8(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvutf8(sv, &lp))#define SvPVutf8_force(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == (SVf_POK|SVf_UTF8) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvutf8n_force(sv, &lp))#define SvPVutf8_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK|SVf_UTF8)\ ? SvPVX(sv) : sv_2pvutf8(sv, 0))/* ----*/#define SvPVbyte(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp))#define SvPVbyte_force(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8|SVf_THINKFIRST)) == (SVf_POK) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvbyten_force(sv, &lp))#define SvPVbyte_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK)\ ? SvPVX(sv) : sv_2pvbyte(sv, 0)) /* define FOOx(): idempotent versions of FOO(). If possible, use a local * var to evaluate the arg once; failing that, use a global if possible; * failing that, call a function to do the work */#define SvPVx_force(sv, lp) sv_pvn_force(sv, &lp)#define SvPVutf8x_force(sv, lp) sv_pvutf8n_force(sv, &lp)#define SvPVbytex_force(sv, lp) sv_pvbyten_force(sv, &lp)#if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN)# define SvIVx(sv) ({SV *_sv = (SV*)(sv); SvIV(_sv); })# define SvUVx(sv) ({SV *_sv = (SV*)(sv); SvUV(_sv); })# define SvNVx(sv) ({SV *_sv = (SV*)(sv); SvNV(_sv); })# define SvPVx(sv, lp) ({SV *_sv = (sv); SvPV(_sv, lp); })# define SvPVx_const(sv, lp) ({SV *_sv = (sv); SvPV_const(_sv, lp); })# define SvPVx_nolen(sv) ({SV *_sv = (sv); SvPV_nolen(_sv); })# define SvPVx_nolen_const(sv) ({SV *_sv = (sv); SvPV_nolen_const(_sv); })# define SvPVutf8x(sv, lp) ({SV *_sv = (sv); SvPVutf8(_sv, lp); })# define SvPVbytex(sv, lp) ({SV *_sv = (sv); SvPVbyte(_sv, lp); })# define SvPVbytex_nolen(sv) ({SV *_sv = (sv); SvPVbyte_nolen(_sv); })# define SvTRUE(sv) ( \ !sv \ ? 0 \ : SvPOK(sv) \ ? (({XPV *nxpv = (XPV*)SvANY(sv); \ nxpv && \ (nxpv->xpv_cur > 1 || \ (nxpv->xpv_cur && *(sv)->sv_u.svu_pv != '0')); }) \ ? 1 \ : 0) \ : \ SvIOK(sv) \ ? SvIVX(sv) != 0 \ : SvNOK(sv) \ ? SvNVX(sv) != 0.0 \ : sv_2bool(sv) )# define SvTRUEx(sv) ({SV *_sv = (sv); SvTRUE(_sv); })#else /* __GNUC__ *//* These inlined macros use globals, which will require a thread * declaration in user code, so we avoid them under threads */# define SvIVx(sv) ((PL_Sv = (sv)), SvIV(PL_Sv))# define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv))# define SvNVx(sv) ((PL_Sv = (sv)), SvNV(PL_Sv))# define SvPVx(sv, lp) ((PL_Sv = (sv)), SvPV(PL_Sv, lp))# define SvPVx_const(sv, lp) ((PL_Sv = (sv)), SvPV_const(PL_Sv, lp))# define SvPVx_nolen(sv) ((PL_Sv = (sv)), SvPV_nolen(PL_Sv))# define SvPVx_nolen_const(sv) ((PL_Sv = (sv)), SvPV_nolen_const(PL_Sv))# define SvPVutf8x(sv, lp) ((PL_Sv = (sv)), SvPVutf8(PL_Sv, lp))# define SvPVbytex(sv, lp) ((PL_Sv = (sv)), SvPVbyte(PL_Sv, lp))# define SvPVbytex_nolen(sv) ((PL_Sv = (sv)), SvPVbyte_nolen(PL_Sv))# define SvTRUE(sv) ( \ !sv \ ? 0 \ : SvPOK(sv) \ ? ((PL_Xpv = (XPV*)SvANY(PL_Sv = (sv))) && \ (PL_Xpv->xpv_cur > 1 || \ (PL_Xpv->xpv_cur && *PL_Sv->sv_u.svu_pv != '0')) \ ? 1 \ : 0) \ : \ SvIOK(sv) \ ? SvIVX(sv) != 0 \ : SvNOK(sv) \ ? SvNVX(sv) != 0.0 \ : sv_2bool(sv) )# define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv))#endif /* __GNU__ */#define SvIsCOW(sv) ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \ (SVf_FAKE | SVf_READONLY))#define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0)#define SvSHARED_HEK_FROM_PV(pvx) \ ((struct hek*)(pvx - STRUCT_OFFSET(struct hek, hek_key)))#define SvSHARED_HASH(sv) (0 + SvSHARED_HEK_FROM_PV(SvPVX_const(sv))->hek_hash)/* flag values for sv_*_flags functions */#define SV_IMMEDIATE_UNREF 1#define SV_GMAGIC 2#define SV_COW_DROP_PV 4#define SV_UTF8_NO_ENCODING 8#define SV_NOSTEAL 16#define SV_CONST_RETURN 32#define SV_MUTABLE_RETURN 64#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|SV_COW_OTHER_PVS# endif#endif#ifndef SV_DO_COW_SVSETSV# define SV_DO_COW_SVSETSV 0#endif#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 the value is about to get thrown away, so drop the PV rather than go to the effort of making a read-write copy only for it to get immediately discarded. */#define SV_CHECK_THINKFIRST_COW_DROP(sv) if (SvTHINKFIRST(sv)) \ sv_force_normal_flags(sv, SV_COW_DROP_PV)#ifdef PERL_OLD_COPY_ON_WRITE#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)#endif /* PERL_OLD_COPY_ON_WRITE */#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)#define CAN_COW_FLAGS (SVp_POK|SVf_P
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -