From b063b0a874bbc4724894885b0a633865675db9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= Date: Fri, 31 Mar 2017 15:04:15 +0100 Subject: [PATCH] Define and use symbolic constants for LvFLAGS --- doop.c | 4 ++-- mg.c | 10 +++++----- pp.c | 10 +++++----- sv.h | 4 ++++ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/doop.c b/doop.c index 0dd4bdf6031b..0a546cce8f94 100644 --- a/doop.c +++ b/doop.c @@ -927,8 +927,8 @@ Perl_do_vecset(pTHX_ SV *sv) /* some out-of-range errors have been deferred if/until the LV is * actually written to: f(vec($s,-1,8)) is not always fatal */ if (errflags) { - assert(!(errflags & ~(1|4))); - if (errflags & 1) + assert(!(errflags & ~(LVf_NEG_OFF|LVf_OUT_OF_RANGE))); + if (errflags & LVf_NEG_OFF) Perl_croak_nocontext("Negative offset to vec in lvalue context"); Perl_croak_nocontext("Out of memory!"); } diff --git a/mg.c b/mg.c index 969d183d6a5a..99c7aa2c1434 100644 --- a/mg.c +++ b/mg.c @@ -2197,8 +2197,8 @@ Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg) const char * const tmps = SvPV_const(lsv,len); STRLEN offs = LvTARGOFF(sv); STRLEN rem = LvTARGLEN(sv); - const bool negoff = LvFLAGS(sv) & 1; - const bool negrem = LvFLAGS(sv) & 2; + const bool negoff = LvFLAGS(sv) & LVf_NEG_OFF; + const bool negrem = LvFLAGS(sv) & LVf_NEG_LEN; PERL_ARGS_ASSERT_MAGIC_GETSUBSTR; PERL_UNUSED_ARG(mg); @@ -2229,8 +2229,8 @@ Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg) SV * const lsv = LvTARG(sv); STRLEN lvoff = LvTARGOFF(sv); STRLEN lvlen = LvTARGLEN(sv); - const bool negoff = LvFLAGS(sv) & 1; - const bool neglen = LvFLAGS(sv) & 2; + const bool negoff = LvFLAGS(sv) & LVf_NEG_OFF; + const bool neglen = LvFLAGS(sv) & LVf_NEG_LEN; PERL_ARGS_ASSERT_MAGIC_SETSUBSTR; PERL_UNUSED_ARG(mg); @@ -2311,7 +2311,7 @@ Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg) PERL_UNUSED_ARG(mg); /* non-zero errflags implies deferred out-of-range condition */ - assert(!(errflags & ~(1|4))); + assert(!(errflags & ~(LVf_NEG_OFF|LVf_OUT_OF_RANGE))); sv_setuv(sv, errflags ? 0 : do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv))); return 0; diff --git a/pp.c b/pp.c index 0c31062c3aed..6df21011affd 100644 --- a/pp.c +++ b/pp.c @@ -3377,11 +3377,11 @@ PP(pp_substr) LvTARGOFF(ret) = pos1_is_uv || pos1_iv >= 0 ? (STRLEN)(UV)pos1_iv - : (LvFLAGS(ret) |= 1, (STRLEN)(UV)-pos1_iv); + : (LvFLAGS(ret) |= LVf_NEG_OFF, (STRLEN)(UV)-pos1_iv); LvTARGLEN(ret) = len_is_uv || len_iv > 0 ? (STRLEN)(UV)len_iv - : (LvFLAGS(ret) |= 2, (STRLEN)(UV)-len_iv); + : (LvFLAGS(ret) |= LVf_NEG_LEN, (STRLEN)(UV)-len_iv); PUSHs(ret); /* avoid SvSETMAGIC here */ RETURN; @@ -3488,12 +3488,12 @@ PP(pp_vec) /* avoid a large UV being wrapped to a negative value */ if (SvIOK_UV(offsetsv) && SvUVX(offsetsv) > (UV)IV_MAX) - errflags = 4; /* out of range */ + errflags = LVf_OUT_OF_RANGE; else if (iv < 0) - errflags = (1|4); /* negative offset, out of range */ + errflags = (LVf_NEG_OFF|LVf_OUT_OF_RANGE); #if PTRSIZE < IVSIZE else if (iv > Size_t_MAX) - errflags = 4; /* out of range */ + errflags = LVf_OUT_OF_RANGE; #endif else offset = (STRLEN)iv; diff --git a/sv.h b/sv.h index 51e9b0ba6649..71c494b3675d 100644 --- a/sv.h +++ b/sv.h @@ -1402,6 +1402,10 @@ object type. Exposed to perl code via Internals::SvREADONLY(). #define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen #define LvFLAGS(sv) ((XPVLV*) SvANY(sv))->xlv_flags +#define LVf_NEG_OFF 0x1 +#define LVf_NEG_LEN 0x2 +#define LVf_OUT_OF_RANGE 0x4 + #define IoIFP(sv) (sv)->sv_u.svu_fp #define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp #define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp