X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/3666098248b43282bda1153dae2f4c1e4af38d09..5920a0ba1d561db9223b9544f4285f9725073039:/sv.h diff --git a/sv.h b/sv.h index ca3a2df..e9d6893 100644 --- a/sv.h +++ b/sv.h @@ -1,6 +1,6 @@ /* sv.h * - * Copyright (c) 1991-1997, Larry Wall + * Copyright (c) 1991-1999, Larry Wall * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. @@ -74,20 +74,16 @@ struct io { #ifdef USE_THREADS -# ifndef EMULATE_ATOMIC_REFCOUNTS -# include "atomic.h" -# endif - # ifdef EMULATE_ATOMIC_REFCOUNTS # define ATOMIC_INC(count) STMT_START { \ - MUTEX_LOCK(&svref_mutex); \ + MUTEX_LOCK(&PL_svref_mutex); \ ++count; \ - MUTEX_UNLOCK(&svref_mutex); \ + MUTEX_UNLOCK(&PL_svref_mutex); \ } STMT_END # define ATOMIC_DEC_AND_TEST(res,count) STMT_START { \ - MUTEX_LOCK(&svref_mutex); \ + MUTEX_LOCK(&PL_svref_mutex); \ res = (--count == 0); \ - MUTEX_UNLOCK(&svref_mutex); \ + MUTEX_UNLOCK(&PL_svref_mutex); \ } STMT_END # else # define ATOMIC_INC(count) atomic_inc(&count) @@ -111,7 +107,7 @@ struct io { # define SvREFCNT_inc(sv) sv_newref((SV*)sv) # else # define SvREFCNT_inc(sv) \ - ((Sv=(SV*)(sv)), (Sv && ATOMIC_INC(SvREFCNT(Sv))), (SV*)Sv) + ((PL_Sv=(SV*)(sv)), (PL_Sv && ATOMIC_INC(SvREFCNT(PL_Sv))), (SV*)PL_Sv) # endif #endif @@ -141,7 +137,7 @@ struct io { #define SVf_BREAK 0x00400000 /* refcnt is artificially low */ #define SVf_READONLY 0x00800000 /* may not be modified */ -#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK) +#define SVf_THINKFIRST (SVf_READONLY|SVf_ROK|SVf_FAKE) #define SVp_IOK 0x01000000 /* has valid non-public integer value */ #define SVp_NOK 0x02000000 /* has valid non-public numeric value */ @@ -151,22 +147,28 @@ struct io { #define SVf_OK (SVf_IOK|SVf_NOK|SVf_POK|SVf_ROK| \ SVp_IOK|SVp_NOK|SVp_POK) -#ifdef OVERLOAD -#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ -#endif /* OVERLOAD */ +#define SVf_AMAGIC 0x10000000 /* has magical overloaded methods */ #define PRIVSHIFT 8 /* Some private flags. */ -#define SVpfm_COMPILED 0x80000000 +#define SVpad_OUR 0x80000000 /* pad name is "our" instead of "my" */ + +#define SVf_IVisUV 0x80000000 /* use XPVUV instead of XPVIV */ + +#define SVpfm_COMPILED 0x80000000 /* FORMLINE is compiled */ #define SVpbm_VALID 0x80000000 #define SVpbm_TAIL 0x40000000 +#define SVrepl_EVAL 0x40000000 /* Replacement part of s///e */ + #define SVphv_SHAREKEYS 0x20000000 /* keys live on shared string table */ #define SVphv_LAZYDEL 0x40000000 /* entry in xhv_eiter must be deleted */ +#define SVprv_WEAKREF 0x80000000 /* Weak reference */ + struct xrv { SV * xrv_rv; /* pointer to another SV */ }; @@ -196,7 +198,7 @@ struct xpvnv { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ }; /* These structure must match the beginning of struct xpvhv in hv.h. */ @@ -205,7 +207,7 @@ struct xpvmg { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_stash; /* class package */ }; @@ -215,7 +217,7 @@ struct xpvlv { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_stash; /* class package */ @@ -230,7 +232,7 @@ struct xpvgv { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_stash; /* class package */ @@ -246,7 +248,7 @@ struct xpvbm { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_stash; /* class package */ @@ -255,7 +257,7 @@ struct xpvbm { U8 xbm_rare; /* rarest character in string */ }; -/* This structure much match XPVCV */ +/* This structure much match XPVCV in cv.h */ typedef U16 cv_flags_t; @@ -264,18 +266,18 @@ struct xpvfm { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_stash; /* class package */ HV * xcv_stash; OP * xcv_start; OP * xcv_root; - void (*xcv_xsub)_((CV* _CPERLproto)); + void (*xcv_xsub)(pTHXo_ CV*); ANY xcv_xsubany; GV * xcv_gv; - GV * xcv_filegv; - long xcv_depth; /* >= 2 indicates recursive call */ + char * xcv_file; + long xcv_depth; /* >= 2 indicates recursive call */ AV * xcv_padlist; CV * xcv_outside; #ifdef USE_THREADS @@ -292,7 +294,7 @@ struct xpvio { STRLEN xpv_cur; /* length of xpv_pv as a C string */ STRLEN xpv_len; /* allocated size */ IV xiv_iv; /* integer value or pv offset */ - double xnv_nv; /* numeric value, if any */ + NV xnv_nv; /* numeric value, if any */ MAGIC* xmg_magic; /* linked list of magicalness */ HV* xmg_stash; /* class package */ @@ -314,27 +316,27 @@ struct xpvio { char xio_flags; }; -#define IOf_ARGV 1 /* this fp iterates over ARGV */ -#define IOf_START 2 /* check for null ARGV and substitute '-' */ -#define IOf_FLUSH 4 /* this fp wants a flush after write op */ -#define IOf_DIDTOP 8 /* just did top of form */ -#define IOf_UNTAINT 16 /* consider this fp (and it's data) "safe" */ +#define IOf_ARGV 1 /* this fp iterates over ARGV */ +#define IOf_START 2 /* check for null ARGV and substitute '-' */ +#define IOf_FLUSH 4 /* this fp wants a flush after write op */ +#define IOf_DIDTOP 8 /* just did top of form */ +#define IOf_UNTAINT 16 /* consider this fp (and its data) "safe" */ +#define IOf_NOLINE 32 /* slurped a pseudo-line from empty file */ +#define IOf_FAKE_DIRP 64 /* xio_dirp is fake (source filters kludge) */ /* The following macros define implementation-independent predicates on SVs. */ #define SvNIOK(sv) (SvFLAGS(sv) & (SVf_IOK|SVf_NOK)) #define SvNIOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK)) #define SvNIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK| \ - SVp_IOK|SVp_NOK)) + SVp_IOK|SVp_NOK|SVf_IVisUV)) #define SvOK(sv) (SvFLAGS(sv) & SVf_OK) - -#ifdef OVERLOAD -#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ +#define SvOK_off(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC| \ + SVf_IVisUV), \ + SvOOK_off(sv)) +#define SvOK_off_exc_UV(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ SvOOK_off(sv)) -#else -#define SvOK_off(sv) (SvFLAGS(sv) &= ~SVf_OK, SvOOK_off(sv)) -#endif /* OVERLOAD */ #define SvOKp(sv) (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) #define SvIOKp(sv) (SvFLAGS(sv) & SVp_IOK) @@ -347,9 +349,20 @@ struct xpvio { #define SvIOK(sv) (SvFLAGS(sv) & SVf_IOK) #define SvIOK_on(sv) (SvOOK_off(sv), \ SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) -#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK)) -#define SvIOK_only(sv) (SvOOK_off(sv), SvOK_off(sv), \ +#define SvIOK_off(sv) (SvFLAGS(sv) &= ~(SVf_IOK|SVp_IOK|SVf_IVisUV)) +#define SvIOK_only(sv) (SvOK_off(sv), \ + SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) +#define SvIOK_only_UV(sv) (SvOK_off_exc_UV(sv), \ SvFLAGS(sv) |= (SVf_IOK|SVp_IOK)) + +#define SvIOK_UV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \ + == (SVf_IOK|SVf_IVisUV)) +#define SvIOK_notUV(sv) ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) \ + == SVf_IOK) + +#define SvIsUV(sv) (SvFLAGS(sv) & SVf_IVisUV) +#define SvIsUV_on(sv) (SvFLAGS(sv) |= SVf_IVisUV) +#define SvIsUV_off(sv) (SvFLAGS(sv) &= ~SVf_IVisUV) #define SvNOK(sv) (SvFLAGS(sv) & SVf_NOK) #define SvNOK_on(sv) (SvFLAGS(sv) |= (SVf_NOK|SVp_NOK)) @@ -360,14 +373,8 @@ struct xpvio { #define SvPOK(sv) (SvFLAGS(sv) & SVf_POK) #define SvPOK_on(sv) (SvFLAGS(sv) |= (SVf_POK|SVp_POK)) #define SvPOK_off(sv) (SvFLAGS(sv) &= ~(SVf_POK|SVp_POK)) - -#ifdef OVERLOAD -#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC), \ - SvFLAGS(sv) |= (SVf_POK|SVp_POK)) -#else -#define SvPOK_only(sv) (SvFLAGS(sv) &= ~SVf_OK, \ +#define SvPOK_only(sv) (SvFLAGS(sv) &= ~(SVf_OK|SVf_AMAGIC|SVf_IVisUV), \ SvFLAGS(sv) |= (SVf_POK|SVp_POK)) -#endif /* OVERLOAD */ #define SvOOK(sv) (SvFLAGS(sv) & SVf_OOK) #define SvOOK_on(sv) (SvIOK_off(sv), SvFLAGS(sv) |= SVf_OOK) @@ -379,12 +386,7 @@ struct xpvio { #define SvROK(sv) (SvFLAGS(sv) & SVf_ROK) #define SvROK_on(sv) (SvFLAGS(sv) |= SVf_ROK) - -#ifdef OVERLOAD #define SvROK_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVf_AMAGIC)) -#else -#define SvROK_off(sv) (SvFLAGS(sv) &= ~SVf_ROK) -#endif /* OVERLOAD */ #define SvMAGICAL(sv) (SvFLAGS(sv) & (SVs_GMG|SVs_SMG|SVs_RMG)) #define SvMAGICAL_on(sv) (SvFLAGS(sv) |= (SVs_GMG|SVs_SMG|SVs_RMG)) @@ -402,18 +404,21 @@ struct xpvio { #define SvRMAGICAL_on(sv) (SvFLAGS(sv) |= SVs_RMG) #define SvRMAGICAL_off(sv) (SvFLAGS(sv) &= ~SVs_RMG) -#ifdef OVERLOAD -#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) -#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) -#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) +#define SvAMAGIC(sv) (SvFLAGS(sv) & SVf_AMAGIC) +#define SvAMAGIC_on(sv) (SvFLAGS(sv) |= SVf_AMAGIC) +#define SvAMAGIC_off(sv) (SvFLAGS(sv) &= ~SVf_AMAGIC) /* #define Gv_AMG(stash) \ (HV_AMAGICmb(stash) && \ ((!HV_AMAGICbad(stash) && HV_AMAGIC(stash)) || Gv_AMupdate(stash))) */ -#define Gv_AMG(stash) (amagic_generation && Gv_AMupdate(stash)) -#endif /* OVERLOAD */ +#define Gv_AMG(stash) (PL_amagic_generation && Gv_AMupdate(stash)) + +#define SvWEAKREF(sv) ((SvFLAGS(sv) & (SVf_ROK|SVprv_WEAKREF)) \ + == (SVf_ROK|SVprv_WEAKREF)) +#define SvWEAKREF_on(sv) (SvFLAGS(sv) |= (SVf_ROK|SVprv_WEAKREF)) +#define SvWEAKREF_off(sv) (SvFLAGS(sv) &= ~(SVf_ROK|SVprv_WEAKREF)) #define SvTHINKFIRST(sv) (SvFLAGS(sv) & SVf_THINKFIRST) @@ -446,6 +451,10 @@ struct xpvio { #define SvCOMPILED_on(sv) (SvFLAGS(sv) |= SVpfm_COMPILED) #define SvCOMPILED_off(sv) (SvFLAGS(sv) &= ~SVpfm_COMPILED) +#define SvEVALED(sv) (SvFLAGS(sv) & SVrepl_EVAL) +#define SvEVALED_on(sv) (SvFLAGS(sv) |= SVrepl_EVAL) +#define SvEVALED_off(sv) (SvFLAGS(sv) &= ~SVrepl_EVAL) + #define SvTAIL(sv) (SvFLAGS(sv) & SVpbm_TAIL) #define SvTAIL_on(sv) (SvFLAGS(sv) |= SVpbm_TAIL) #define SvTAIL_off(sv) (SvFLAGS(sv) &= ~SVpbm_TAIL) @@ -469,7 +478,7 @@ struct xpvio { #define SvLEN(sv) ((XPV*) SvANY(sv))->xpv_len #define SvLENx(sv) SvLEN(sv) #define SvEND(sv)(((XPV*) SvANY(sv))->xpv_pv + ((XPV*)SvANY(sv))->xpv_cur) -#define SvENDx(sv) ((Sv = (sv)), SvEND(Sv)) +#define SvENDx(sv) ((PL_Sv = (sv)), SvEND(PL_Sv)) #define SvMAGIC(sv) ((XPVMG*) SvANY(sv))->xmg_magic #define SvSTASH(sv) ((XPVMG*) SvANY(sv))->xmg_stash @@ -521,20 +530,21 @@ struct xpvio { #define IoFLAGS(sv) ((XPVIO*) SvANY(sv))->xio_flags #define SvTAINTED(sv) (SvMAGICAL(sv) && sv_tainted(sv)) -#define SvTAINTED_on(sv) STMT_START{ if(tainting){sv_taint(sv);} }STMT_END -#define SvTAINTED_off(sv) STMT_START{ if(tainting){sv_untaint(sv);} }STMT_END +#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 (tainting) { \ + if (PL_tainting) { \ dTHR; \ - if (tainted) \ + if (PL_tainted) \ SvTAINTED_on(sv); \ } \ } STMT_END #define SvPV_force(sv, lp) sv_pvn_force(sv, &lp) #define SvPV(sv, lp) sv_pvn(sv, &lp) +#define SvPV_nolen(sv) sv_pv(sv) #define SvIVx(sv) sv_iv(sv) #define SvUVx(sv) sv_uv(sv) #define SvNVx(sv) sv_nv(sv) @@ -544,12 +554,13 @@ struct xpvio { #define SvIV(sv) SvIVx(sv) #define SvNV(sv) SvNVx(sv) -#define SvUV(sv) SvIVx(sv) +#define SvUV(sv) SvUVx(sv) #define SvTRUE(sv) SvTRUEx(sv) #ifndef CRIPPLED_CC /* redefine some things to more efficient inlined versions */ +/* Let us hope that bitmaps for UV and IV are the same */ #undef SvIV #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) @@ -568,6 +579,10 @@ struct xpvio { ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force(sv, &lp)) +#undef SvPV_nolen +#define SvPV_nolen(sv) \ + (SvPOK(sv) ? SvPVX(sv) : sv_2pv_nolen(sv)) + #ifdef __GNUC__ # undef SvIVx # undef SvUVx @@ -608,18 +623,18 @@ struct xpvio { # undef SvPVx # undef SvTRUE # undef SvTRUEx -# define SvIVx(sv) ((Sv = (sv)), SvIV(Sv)) -# define SvUVx(sv) ((Sv = (sv)), SvUV(Sv)) -# define SvNVx(sv) ((Sv = (sv)), SvNV(Sv)) -# define SvPVx(sv, lp) ((Sv = (sv)), SvPV(Sv, lp)) +# 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 SvTRUE(sv) ( \ !sv \ ? 0 \ : SvPOK(sv) \ - ? ((Xpv = (XPV*)SvANY(sv)) && \ - (*Xpv->xpv_pv > '0' || \ - Xpv->xpv_cur > 1 || \ - (Xpv->xpv_cur && *Xpv->xpv_pv != '0')) \ + ? ((PL_Xpv = (XPV*)SvANY(sv)) && \ + (*PL_Xpv->xpv_pv > '0' || \ + PL_Xpv->xpv_cur > 1 || \ + (PL_Xpv->xpv_cur && *PL_Xpv->xpv_pv != '0')) \ ? 1 \ : 0) \ : \ @@ -628,22 +643,12 @@ struct xpvio { : SvNOK(sv) \ ? SvNVX(sv) != 0.0 \ : sv_2bool(sv) ) -# define SvTRUEx(sv) ((Sv = (sv)), SvTRUE(Sv)) +# define SvTRUEx(sv) ((PL_Sv = (sv)), SvTRUE(PL_Sv)) #endif /* !USE_THREADS */ #endif /* !__GNU__ */ #endif /* !CRIPPLED_CC */ #define newRV_inc(sv) newRV(sv) -#ifdef __GNUC__ -# undef newRV_noinc -# define newRV_noinc(sv) ({SV *nsv=newRV((sv)); --SvREFCNT(SvRV(nsv)); nsv;}) -#else -# if defined(CRIPPLED_CC) || defined(USE_THREADS) || defined(PERL_OBJECT) -# else -# undef newRV_noinc -# define newRV_noinc(sv) ((Sv = newRV(sv)), --SvREFCNT(SvRV(Sv)), Sv) -# endif -#endif /* __GNUC__ */ /* the following macros update any magic values this sv is associated with */ @@ -678,20 +683,17 @@ struct xpvio { #define SvSetMagicSV_nosteal(dst,src) \ SvSetSV_nosteal_and(dst,src,SvSETMAGIC(dst)) +#ifdef DEBUGGING #define SvPEEK(sv) sv_peek(sv) +#else +#define SvPEEK(sv) "" +#endif -#define SvIMMORTAL(sv) ((sv)==&sv_undef || (sv)==&sv_yes || (sv)==&sv_no) +#define SvIMMORTAL(sv) ((sv)==&PL_sv_undef || (sv)==&PL_sv_yes || (sv)==&PL_sv_no) -#define boolSV(b) ((b) ? &sv_yes : &sv_no) +#define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) #define isGV(sv) (SvTYPE(sv) == SVt_PVGV) -#ifndef DOSISH -# define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) -# define Sv_Grow sv_grow -#else - /* extra parentheses intentionally NOT placed around "len"! */ -# define SvGROW(sv,len) ((SvLEN(sv) < (unsigned long)len) \ - ? sv_grow(sv,(unsigned long)len) : SvPVX(sv)) -# define Sv_Grow(sv,len) sv_grow(sv,(unsigned long)(len)) -#endif /* DOSISH */ +#define SvGROW(sv,len) (SvLEN(sv) < (len) ? sv_grow(sv,len) : SvPVX(sv)) +#define Sv_Grow sv_grow