Skip to content

Commit

Permalink
Define and use symbolic constants for LvFLAGS
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmari committed Jun 2, 2017
1 parent 3deca55 commit b063b0a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions doop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
10 changes: 5 additions & 5 deletions mg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions pp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions sv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b063b0a

Please sign in to comment.