📄 sv.h
字号:
/* sv.h * * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, * 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. * */#ifdef sv_flags#undef sv_flags /* Convex has this in <signal.h> for sigvec() */#endif/*=head1 SV Flags=for apidoc AmU||svtypeAn enum of flags for Perl types. These are found in the file B<sv.h>in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.=for apidoc AmU||SVt_PVPointer type flag for scalars. See C<svtype>.=for apidoc AmU||SVt_IVInteger type flag for scalars. See C<svtype>.=for apidoc AmU||SVt_NVDouble type flag for scalars. See C<svtype>.=for apidoc AmU||SVt_PVMGType flag for blessed scalars. See C<svtype>.=for apidoc AmU||SVt_PVAVType flag for arrays. See C<svtype>.=for apidoc AmU||SVt_PVHVType flag for hashes. See C<svtype>.=for apidoc AmU||SVt_PVCVType flag for code refs. See C<svtype>.=cut*/typedef enum { SVt_NULL, /* 0 */ SVt_BIND, /* 1 */ SVt_IV, /* 2 */ SVt_NV, /* 3 */ SVt_RV, /* 4 */ SVt_PV, /* 5 */ SVt_PVIV, /* 6 */ SVt_PVNV, /* 7 */ SVt_PVMG, /* 8 */ /* PVBM was here, before BIND replaced it. */ SVt_PVGV, /* 9 */ SVt_PVLV, /* 10 */ SVt_PVAV, /* 11 */ SVt_PVHV, /* 12 */ SVt_PVCV, /* 13 */ SVt_PVFM, /* 14 */ SVt_PVIO, /* 15 */ SVt_LAST /* keep last in enum. used to size arrays */} svtype;#ifndef PERL_CORE/* Although Fast Boyer Moore tables are now being stored in PVGVs, for most purposes eternal code wanting to consider PVBM probably needs to think of PVMG instead. */# define SVt_PVBM SVt_PVMG#endif/* There is collusion here with sv_clear - sv_clear exits early for SVt_NULL and SVt_IV, so never reaches the clause at the end that uses sv_type_details->body_size to determine whether to call safefree(). Hence body_size can be set no-zero to record the size of PTEs and HEs, without fear of bogus frees. */#ifdef PERL_IN_SV_C#define PTE_SVSLOT SVt_IV#endif#if defined(PERL_IN_HV_C) || defined(PERL_IN_XS_APITEST)#define HE_SVSLOT SVt_NULL#endif#define PERL_ARENA_ROOTS_SIZE (SVt_LAST)/* typedefs to eliminate some typing */typedef struct he HE;typedef struct hek HEK;/* Using C's structural equivalence to help emulate C++ inheritance here... *//* start with 2 sv-head building blocks */#define _SV_HEAD(ptrtype) \ ptrtype sv_any; /* pointer to body */ \ U32 sv_refcnt; /* how many references to us */ \ U32 sv_flags /* what we are */#define _SV_HEAD_UNION \ union { \ IV svu_iv; \ UV svu_uv; \ SV* svu_rv; /* pointer to another SV */ \ char* svu_pv; /* pointer to malloced string */ \ SV** svu_array; \ HE** svu_hash; \ GP* svu_gp; \ } sv_ustruct STRUCT_SV { /* struct sv { */ _SV_HEAD(void*); _SV_HEAD_UNION;#ifdef DEBUG_LEAKING_SCALARS unsigned sv_debug_optype:9; /* the type of OP that allocated us */ unsigned sv_debug_inpad:1; /* was allocated in a pad for an OP */ unsigned sv_debug_cloned:1; /* was cloned for an ithread */ unsigned sv_debug_line:16; /* the line where we were allocated */ char * sv_debug_file; /* the file where we were allocated */#endif};struct gv { _SV_HEAD(XPVGV*); /* pointer to xpvgv body */ _SV_HEAD_UNION;};struct cv { _SV_HEAD(XPVCV*); /* pointer to xpvcv body */ _SV_HEAD_UNION;};struct av { _SV_HEAD(XPVAV*); /* pointer to xpvav body */ _SV_HEAD_UNION;};struct hv { _SV_HEAD(XPVHV*); /* pointer to xpvhv body */ _SV_HEAD_UNION;};struct io { _SV_HEAD(XPVIO*); /* pointer to xpvio body */ _SV_HEAD_UNION;};#undef _SV_HEAD#undef _SV_HEAD_UNION /* ensure no pollution *//*=head1 SV Manipulation Functions=for apidoc Am|U32|SvREFCNT|SV* svReturns the value of the object's reference count.=for apidoc Am|SV*|SvREFCNT_inc|SV* svIncrements the reference count of the given SV.All of the following SvREFCNT_inc* macros are optimized versions ofSvREFCNT_inc, and can be replaced with SvREFCNT_inc.=for apidoc Am|SV*|SvREFCNT_inc_NN|SV* svSame as SvREFCNT_inc, but can only be used if you know I<sv>is not NULL. Since we don't have to check the NULLness, it's fasterand smaller.=for apidoc Am|void|SvREFCNT_inc_void|SV* svSame as SvREFCNT_inc, but can only be used if you don't need thereturn value. The macro doesn't need to return a meaningful value.=for apidoc Am|void|SvREFCNT_inc_void_NN|SV* svSame as SvREFCNT_inc, but can only be used if you don't need the returnvalue, and you know that I<sv> is not NULL. The macro doesn't needto return a meaningful value, or check for NULLness, so it's smallerand faster.=for apidoc Am|SV*|SvREFCNT_inc_simple|SV* svSame as SvREFCNT_inc, but can only be used with expressions without sideeffects. Since we don't have to store a temporary value, it's faster.=for apidoc Am|SV*|SvREFCNT_inc_simple_NN|SV* svSame as SvREFCNT_inc_simple, but can only be used if you know I<sv>is not NULL. Since we don't have to check the NULLness, it's fasterand smaller.=for apidoc Am|void|SvREFCNT_inc_simple_void|SV* svSame as SvREFCNT_inc_simple, but can only be used if you don't need thereturn value. The macro doesn't need to return a meaningful value.=for apidoc Am|void|SvREFCNT_inc_simple_void_NN|SV* svSame as SvREFCNT_inc, but can only be used if you don't need the returnvalue, and you know that I<sv> is not NULL. The macro doesn't needto return a meaningful value, or check for NULLness, so it's smallerand faster.=for apidoc Am|void|SvREFCNT_dec|SV* svDecrements the reference count of the given SV.=for apidoc Am|svtype|SvTYPE|SV* svReturns the type of the SV. See C<svtype>.=for apidoc Am|void|SvUPGRADE|SV* sv|svtype typeUsed to upgrade an SV to a more complex form. Uses C<sv_upgrade> toperform the upgrade if necessary. See C<svtype>.=cut*/#define SvANY(sv) (sv)->sv_any#define SvFLAGS(sv) (sv)->sv_flags#define SvREFCNT(sv) (sv)->sv_refcnt#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)# define SvREFCNT_inc(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (SvREFCNT(_sv))++; \ _sv; \ })# define SvREFCNT_inc_simple(sv) \ ({ \ if (sv) \ (SvREFCNT(sv))++; \ (SV *)(sv); \ })# define SvREFCNT_inc_NN(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ SvREFCNT(_sv)++; \ _sv; \ })# define SvREFCNT_inc_void(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (void)(SvREFCNT(_sv)++); \ })#else# define SvREFCNT_inc(sv) \ ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL)# define SvREFCNT_inc_simple(sv) \ ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL)# define SvREFCNT_inc_NN(sv) \ (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv)# define SvREFCNT_inc_void(sv) \ (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0)#endif/* These guys don't need the curly blocks */#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)))#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(PERL_GCC_PEDANTIC)# define SvREFCNT_dec(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) { \ if (SvREFCNT(_sv)) { \ if (--(SvREFCNT(_sv)) == 0) \ Perl_sv_free2(aTHX_ _sv); \ } else { \ sv_free(_sv); \ } \ } \ })#else#define SvREFCNT_dec(sv) sv_free((SV*)(sv))#endif#define SVTYPEMASK 0xff#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 them all by using a consistent macro. */#define SvIS_FREED(sv) ((sv)->sv_flags == SVTYPEMASK)#define SvUPGRADE(sv, mt) (SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt), 1))#define SVf_IOK 0x00000100 /* has valid public integer value */#define SVf_NOK 0x00000200 /* has valid public numeric value */#define SVf_POK 0x00000400 /* has valid public pointer value */#define SVf_ROK 0x00000800 /* has a valid reference pointer */#define SVp_IOK 0x00001000 /* has valid non-public integer value */#define SVp_NOK 0x00002000 /* has valid non-public numeric value */#define SVp_POK 0x00004000 /* has valid non-public pointer value */#define SVp_SCREAM 0x00008000 /* has been studied? */#define SVphv_CLONEABLE SVp_SCREAM /* PVHV (stashes) clone its objects */#define SVpgv_GP SVp_SCREAM /* GV has a valid GP */#define SVprv_PCS_IMPORTED SVp_SCREAM /* RV is a proxy for a constant subroutine in another package. Set the CvIMPORTED_CV_ON() if it needs to be expanded to a real GV */#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 */#define SVpad_OUR 0x00040000 /* pad name is "our" instead of "my" */#define SVs_TEMP 0x00080000 /* string is stealable? */#define SVs_OBJECT 0x00100000 /* is "blessed" */#define SVs_GMG 0x00200000 /* has magical get method */#define SVs_SMG 0x00400000 /* has magical set method */#define SVs_RMG 0x00800000 /* has random magical methods */#define SVf_FAKE 0x01000000 /* 0: glob or lexical is just a copy 1: SV head arena wasn't malloc()ed 2: in conjunction with SVf_READONLY marks a shared hash key scalar (SvLEN == 0) or a copy on write string (SvLEN != 0) [SvIsCOW(sv)] 3: For PVCV, whether CvUNIQUE(cv) refers to an eval or once only [CvEVAL(cv), CvSPECIAL(cv)] 4: Whether the regexp pointer is in 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". */#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 main array */#define SVf_BREAK 0x04000000 /* refcnt is artificially low - used by SV's in final arena cleanup */#define SVf_READONLY 0x08000000 /* may not be modified */#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE)#define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ SVp_IOK|SVp_NOK|SVp_POK|SVpgv_GP)#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() */ /* 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 */#define SVpad_NAME 0x40000000 /* This SV is a name in the PAD, so SVpad_TYPED, SVpad_OUR and SVpad_STATE apply *//* PVAV */#define SVpav_REAL 0x40000000 /* free old entries *//* PVHV */#define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted *//* This is only set true on a PVGV when it's playing "PVBM", but is tested for on any regular scalar (anything <= PVLV) */#define SVpbm_VALID 0x40000000/* ??? */#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e *//* IV, PVIV, PVNV, PVMG, PVGV and (I assume) PVLV *//* Presumably IVs aren't stored in pads */#define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV *//* PVAV */#define SVpav_REIFY 0x80000000 /* can become real */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -