if (RANGE_IS_NUMERIC(left,right)) {
register IV i, j;
IV max;
- if ((SvOK(left) && SvNV(left) < IV_MIN) ||
- (SvOK(right) && SvNV(right) > IV_MAX))
+ if ((SvOK(left) && SvNV_nomg(left) < IV_MIN) ||
+ (SvOK(right) && SvNV_nomg(right) > IV_MAX))
DIE(aTHX_ "Range iterator outside integer range");
- i = SvIV(left);
- max = SvIV(right);
+ i = SvIV_nomg(left);
+ max = SvIV_nomg(right);
if (max >= i) {
j = max - i + 1;
EXTEND_MORTAL(j);
}
else {
STRLEN len;
- const char * const tmps = SvPV_const(right, len);
+ const char * const tmps = SvPV_nomg_const(right, len);
- SV *sv = sv_mortalcopy(left);
+ SV *sv = sv_newmortal();
+ sv_setsv_nomg(sv, left);
SvPV_force_nolen(sv);
while (!SvNIOKp(sv) && SvCUR(sv) <= len) {
XPUSHs(sv);
assumptions */
assert(CxTYPE(cx) == CXt_LOOP_LAZYIV);
#ifdef NV_PRESERVES_UV
- if ((SvOK(sv) && ((SvNV(sv) < (NV)IV_MIN) ||
- (SvNV(sv) > (NV)IV_MAX)))
+ if ((SvOK(sv) && ((SvNV_nomg(sv) < (NV)IV_MIN) ||
+ (SvNV_nomg(sv) > (NV)IV_MAX)))
||
- (SvOK(right) && ((SvNV(right) > (NV)IV_MAX) ||
- (SvNV(right) < (NV)IV_MIN))))
+ (SvOK(right) && ((SvNV_nomg(right) > (NV)IV_MAX) ||
+ (SvNV_nomg(right) < (NV)IV_MIN))))
#else
- if ((SvOK(sv) && ((SvNV(sv) <= (NV)IV_MIN)
+ if ((SvOK(sv) && ((SvNV_nomg(sv) <= (NV)IV_MIN)
||
- ((SvNV(sv) > 0) &&
- ((SvUV(sv) > (UV)IV_MAX) ||
- (SvNV(sv) > (NV)UV_MAX)))))
+ ((SvNV_nomg(sv) > 0) &&
+ ((SvUV_nomg(sv) > (UV)IV_MAX) ||
+ (SvNV_nomg(sv) > (NV)UV_MAX)))))
||
- (SvOK(right) && ((SvNV(right) <= (NV)IV_MIN)
+ (SvOK(right) && ((SvNV_nomg(right) <= (NV)IV_MIN)
||
- ((SvNV(right) > 0) &&
- ((SvUV(right) > (UV)IV_MAX) ||
- (SvNV(right) > (NV)UV_MAX))))))
+ ((SvNV_nomg(right) > 0) &&
+ ((SvUV_nomg(right) > (UV)IV_MAX) ||
+ (SvNV_nomg(right) > (NV)UV_MAX))
+ ))))
#endif
DIE(aTHX_ "Range iterator outside integer range");
- cx->blk_loop.state_u.lazyiv.cur = SvIV(sv);
- cx->blk_loop.state_u.lazyiv.end = SvIV(right);
+ cx->blk_loop.state_u.lazyiv.cur = SvIV_nomg(sv);
+ cx->blk_loop.state_u.lazyiv.end = SvIV_nomg(right);
#ifdef DEBUGGING
/* for correct -Dstv display */
cx->blk_oldsp = sp - PL_stack_base;
Test if the content of an SV looks like a number (or is a number).
C<Inf> and C<Infinity> are treated as numbers (so will not issue a
-non-numeric warning), even if your atof() doesn't grok them.
+non-numeric warning), even if your atof() doesn't grok them. Get-magic is
+ignored.
=cut
*/
PERL_ARGS_ASSERT_LOOKS_LIKE_NUMBER;
- if (SvPOK(sv)) {
- sbegin = SvPVX_const(sv);
- len = SvCUR(sv);
+ if (SvPOK(sv) || SvPOKp(sv)) {
+ sbegin = SvPV_nomg_const(sv, len);
}
- else if (SvPOKp(sv))
- sbegin = SvPV_const(sv, len);
else
return SvFLAGS(sv) & (SVf_NOK|SVp_NOK|SVf_IOK|SVp_IOK);
return grok_number(sbegin, len, NULL);
@foo = 4 .. $x;
is(scalar @foo, 3);
is("@foo", "4 5 6");
-{
- local $TODO = "test for double magic with range operator";
- is(fetches($x), 1);
-}
+is(fetches($x), 1);
is(stores($x), 0);
@foo = $x .. 8;
is(scalar @foo, 3);
is("@foo", "6 7 8");
-{
- local $TODO = "test for double magic with range operator";
- is(fetches($x), 1);
-}
+is(fetches($x), 1);
is(stores($x), 0);
@foo = $x .. $x + 1;
is(scalar @foo, 2);
is("@foo", "6 7");
-{
- local $TODO = "test for double magic with range operator";
- is(fetches($x), 2);
-}
+is(fetches($x), 2);
is(stores($x), 0);
@foo = ();
}
is(scalar @foo, 3);
is("@foo", "4 5 6");
-{
- local $TODO = "test for double magic with range operator";
- is(fetches($x), 1);
-}
+is(fetches($x), 1);
is(stores($x), 0);
@foo = ();
}
is(scalar @foo, 3);
is("@foo", "6 5 4");
-{
- local $TODO = "test for double magic with range operator";
- is(fetches($x), 1);
-}
+is(fetches($x), 1);
is(stores($x), 0);
is( ( join ' ', map { join '', map ++$_, ($x=1)..4 } 1..2 ), '2345 2345',
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
- plan (tests => 283);
+ plan (tests => 287);
}
use strict;
$dummy = $var x 1 ; check_count 'x';
@dummy = ($var) x 1 ; check_count 'x';
$dummy = $var . 1 ; check_count '.';
+@dummy = $var .. 1 ; check_count '$tied..1';
+@dummy = 1 .. $var; check_count '1..$tied';
+tie my $v42 => 'main', "z";
+@dummy = $v42 .. "a"; check_count '$tied.."a"';
+@dummy = "a" .. $v42; check_count '"a"..$tied';
# Pre/post in/decrement
$var ++ ; check_count 'post ++';