Skip to content

Commit b063b0a

Browse files
committed
Define and use symbolic constants for LvFLAGS
1 parent 3deca55 commit b063b0a

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

doop.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,8 @@ Perl_do_vecset(pTHX_ SV *sv)
927927
/* some out-of-range errors have been deferred if/until the LV is
928928
* actually written to: f(vec($s,-1,8)) is not always fatal */
929929
if (errflags) {
930-
assert(!(errflags & ~(1|4)));
931-
if (errflags & 1)
930+
assert(!(errflags & ~(LVf_NEG_OFF|LVf_OUT_OF_RANGE)));
931+
if (errflags & LVf_NEG_OFF)
932932
Perl_croak_nocontext("Negative offset to vec in lvalue context");
933933
Perl_croak_nocontext("Out of memory!");
934934
}

mg.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2197,8 +2197,8 @@ Perl_magic_getsubstr(pTHX_ SV *sv, MAGIC *mg)
21972197
const char * const tmps = SvPV_const(lsv,len);
21982198
STRLEN offs = LvTARGOFF(sv);
21992199
STRLEN rem = LvTARGLEN(sv);
2200-
const bool negoff = LvFLAGS(sv) & 1;
2201-
const bool negrem = LvFLAGS(sv) & 2;
2200+
const bool negoff = LvFLAGS(sv) & LVf_NEG_OFF;
2201+
const bool negrem = LvFLAGS(sv) & LVf_NEG_LEN;
22022202

22032203
PERL_ARGS_ASSERT_MAGIC_GETSUBSTR;
22042204
PERL_UNUSED_ARG(mg);
@@ -2229,8 +2229,8 @@ Perl_magic_setsubstr(pTHX_ SV *sv, MAGIC *mg)
22292229
SV * const lsv = LvTARG(sv);
22302230
STRLEN lvoff = LvTARGOFF(sv);
22312231
STRLEN lvlen = LvTARGLEN(sv);
2232-
const bool negoff = LvFLAGS(sv) & 1;
2233-
const bool neglen = LvFLAGS(sv) & 2;
2232+
const bool negoff = LvFLAGS(sv) & LVf_NEG_OFF;
2233+
const bool neglen = LvFLAGS(sv) & LVf_NEG_LEN;
22342234

22352235
PERL_ARGS_ASSERT_MAGIC_SETSUBSTR;
22362236
PERL_UNUSED_ARG(mg);
@@ -2311,7 +2311,7 @@ Perl_magic_getvec(pTHX_ SV *sv, MAGIC *mg)
23112311
PERL_UNUSED_ARG(mg);
23122312

23132313
/* non-zero errflags implies deferred out-of-range condition */
2314-
assert(!(errflags & ~(1|4)));
2314+
assert(!(errflags & ~(LVf_NEG_OFF|LVf_OUT_OF_RANGE)));
23152315
sv_setuv(sv, errflags ? 0 : do_vecget(lsv, LvTARGOFF(sv), LvTARGLEN(sv)));
23162316

23172317
return 0;

pp.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -3377,11 +3377,11 @@ PP(pp_substr)
33773377
LvTARGOFF(ret) =
33783378
pos1_is_uv || pos1_iv >= 0
33793379
? (STRLEN)(UV)pos1_iv
3380-
: (LvFLAGS(ret) |= 1, (STRLEN)(UV)-pos1_iv);
3380+
: (LvFLAGS(ret) |= LVf_NEG_OFF, (STRLEN)(UV)-pos1_iv);
33813381
LvTARGLEN(ret) =
33823382
len_is_uv || len_iv > 0
33833383
? (STRLEN)(UV)len_iv
3384-
: (LvFLAGS(ret) |= 2, (STRLEN)(UV)-len_iv);
3384+
: (LvFLAGS(ret) |= LVf_NEG_LEN, (STRLEN)(UV)-len_iv);
33853385

33863386
PUSHs(ret); /* avoid SvSETMAGIC here */
33873387
RETURN;
@@ -3488,12 +3488,12 @@ PP(pp_vec)
34883488

34893489
/* avoid a large UV being wrapped to a negative value */
34903490
if (SvIOK_UV(offsetsv) && SvUVX(offsetsv) > (UV)IV_MAX)
3491-
errflags = 4; /* out of range */
3491+
errflags = LVf_OUT_OF_RANGE;
34923492
else if (iv < 0)
3493-
errflags = (1|4); /* negative offset, out of range */
3493+
errflags = (LVf_NEG_OFF|LVf_OUT_OF_RANGE);
34943494
#if PTRSIZE < IVSIZE
34953495
else if (iv > Size_t_MAX)
3496-
errflags = 4; /* out of range */
3496+
errflags = LVf_OUT_OF_RANGE;
34973497
#endif
34983498
else
34993499
offset = (STRLEN)iv;

sv.h

+4
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,10 @@ object type. Exposed to perl code via Internals::SvREADONLY().
14021402
#define LvTARGLEN(sv) ((XPVLV*) SvANY(sv))->xlv_targlen
14031403
#define LvFLAGS(sv) ((XPVLV*) SvANY(sv))->xlv_flags
14041404

1405+
#define LVf_NEG_OFF 0x1
1406+
#define LVf_NEG_LEN 0x2
1407+
#define LVf_OUT_OF_RANGE 0x4
1408+
14051409
#define IoIFP(sv) (sv)->sv_u.svu_fp
14061410
#define IoOFP(sv) ((XPVIO*) SvANY(sv))->xio_ofp
14071411
#define IoDIRP(sv) ((XPVIO*) SvANY(sv))->xio_dirp

0 commit comments

Comments
 (0)