Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"0" fails as right-hand argument to .. #6047

Closed
p5pRT opened this issue Oct 30, 2002 · 7 comments
Closed

"0" fails as right-hand argument to .. #6047

p5pRT opened this issue Oct 30, 2002 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 30, 2002

Migrated from rt.perl.org#18165 (status was 'resolved')

Searchable as RT18165$

@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2002

From @mjdominus

Created by @mjdominus

  perl -e 'print "-4" .. "0"'

This prints nothing.

The problem persists in 5.7.3.

Perl Info

Flags:
    category=core
    severity=medium

Site configuration information for perl v5.6.1:

Configured by root at Sat Dec 29 11:54:59 EST 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.2-2, archname=i586-linux
    uname='linux plover.com 2.4.2-2 #1 sun apr 8 19:37:14 edt 2001 i586 unknown '
    config_args='-des'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing'
    ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-81)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.2.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.1:
    /usr/local/lib/perl5/5.6.1/i586-linux
    /usr/local/lib/perl5/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.1/i586-linux
    /usr/local/lib/perl5/site_perl/5.6.1
    /usr/local/lib/perl5/site_perl/5.6.0/i586-linux
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl
    .


Environment for perl v5.6.1:
    HOME=/home/mjd
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/lib:/usr/lib:/usr/X11R6/lib
    LOGDIR (unset)
    PATH=/home/mjd/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:/sbin:/usr/sbin:/usr/local/bin/X11R6:/usr/local/bin/mh:/data/mysql/bin:/usr/local/bin/pbm:/usr/local/bin/ezmlm:/home/mjd/TPI/bin:/usr/local/teTeX/bin:/usr/local/mysql/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2002

From ams@wiw.org

At 2002-10-30 17​:27​:53 -0000, perlbug@​perl.org wrote​:

perl -e 'print "-4" .. "0"'

This is a very old bug, introduced by​:

| Change 4730 by gsar@​auger on 1999/12/28 19​:55​:56
|
| range operator does magical string increment iff both operands
| are non-numbers, from Tom Phoenix <rootbeer@​redcat.com>; fixed
| the "foreach (RANGE)" case as well

(Ha ha, Andreas. :-)

The appended patch fixes it.

-- ams

Change 18073 by ams@​lustre on 2002/10/30 19​:47​:12

  Subject​: [perl #18165] "0" fails as right-hand argument to ..
  From​: Mark-Jason Dominus (via RT) <perlbug@​perl.org>
  Date​: 30 Oct 2002 17​:27​:53 -0000
  Message-Id​: <rt-18165-40816.6.86096008382222@​bugs6.perl.org>
 
  (Fixed by making an exception for .."0" in pp_flop.)

Affected files ...

...... //depot/perl/pp_ctl.c#325 edit
...... //depot/perl/t/op/range.t#9 edit

Differences ...

==== //depot/perl/pp_ctl.c#325 (text) ====
Index​: perl/pp_ctl.c

Inline Patch
--- perl/pp_ctl.c#324~18048~	Tue Oct 22 22:34:26 2002
+++ perl/pp_ctl.c	Thu Oct 31 01:17:12 2002
@@ -943,10 +943,15 @@
 	if (SvGMAGICAL(right))
 	    mg_get(right);
 
+	/* This code tries to decide if "$left .. $right" should use the
+	   magical string increment, or if the range is numeric (we make
+	   an exception for .."0" [#18165]). AMS 20021031. */
+
 	if (SvNIOKp(left) || !SvPOKp(left) ||
 	    SvNIOKp(right) || !SvPOKp(right) ||
 	    (looks_like_number(left) && *SvPVX(left) != '0' &&
-	     looks_like_number(right) && *SvPVX(right) != '0'))
+	     looks_like_number(right) && (*SvPVX(right) != '0' ||
+					  SvCUR(right) == 1)))
 	{
 	    if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
 		DIE(aTHX_ "Range iterator outside integer range");

==== //depot/perl/t/op/range.t#9 (xtext) ==== Index​: perl/t/op/range\.t
Inline Patch
--- perl/t/op/range.t#8~4730~	Wed Dec 29 01:25:56 1999
+++ perl/t/op/range.t	Thu Oct 31 01:17:12 2002
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..15\n";
+print "1..16\n";
 
 print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
 
@@ -73,3 +73,7 @@
     print "not ";
 }
 print "ok 15\n";
+
+# [#18165] Should allow "-4".."0", broken by #4730. (AMS 20021031)
+print "not " unless 5 == (() = "-4".."0");
+print "ok 16\n";

@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2002

From @eserte

Abhijit Menon-Sen <ams@​wiw.org> writes​:

At 2002-10-30 17​:27​:53 -0000, perlbug@​perl.org wrote​:

perl -e 'print "-4" .. "0"'

This is a very old bug, introduced by​:

| Change 4730 by gsar@​auger on 1999/12/28 19​:55​:56
|
| range operator does magical string increment iff both operands
| are non-numbers, from Tom Phoenix <rootbeer@​redcat.com>; fixed
| the "foreach (RANGE)" case as well

(Ha ha, Andreas. :-)

The appended patch fixes it.

Please see also [perl #18114] and the patch there, which also handles
the "-4\n" .. "0\n" case.

Regards,
  Slaven

-- ams

Change 18073 by ams@​lustre on 2002/10/30 19​:47​:12

Subject&#8203;: \[perl \#18165\] "0" fails as right\-hand argument to \.\.
From&#8203;: Mark\-Jason Dominus \(via RT\) \<perlbug@&#8203;perl\.org>
Date&#8203;: 30 Oct 2002 17&#8203;:27&#8203;:53 \-0000
Message\-Id&#8203;: \<rt\-18165\-40816\.6\.86096008382222@&#8203;bugs6\.perl\.org>

\(Fixed by making an exception for \.\."0" in pp\_flop\.\)

Affected files ...

... //depot/perl/pp_ctl.c#325 edit
... //depot/perl/t/op/range.t#9 edit

Differences ...

==== //depot/perl/pp_ctl.c#325 (text) ====
Index​: perl/pp_ctl.c
--- perl/pp_ctl.c#32418048 Tue Oct 22 22​:34​:26 2002
+++ perl/pp_ctl.c Thu Oct 31 01​:17​:12 2002
@​@​ -943,10 +943,15 @​@​
if (SvGMAGICAL(right))
mg_get(right);

+ /* This code tries to decide if "$left .. $right" should use the
+ magical string increment, or if the range is numeric (we make
+ an exception for .."0" [#18165]). AMS 20021031. */
+
if (SvNIOKp(left) || !SvPOKp(left) ||
SvNIOKp(right) || !SvPOKp(right) ||
(looks_like_number(left) && *SvPVX(left) != '0' &&
- looks_like_number(right) && *SvPVX(right) != '0'))
+ looks_like_number(right) && (*SvPVX(right) != '0' ||
+ SvCUR(right) == 1)))
{
if (SvNV(left) < IV_MIN || SvNV(right) > IV_MAX)
DIE(aTHX_ "Range iterator outside integer range");

==== //depot/perl/t/op/range.t#9 (xtext) ====
Index​: perl/t/op/range.t
--- perl/t/op/range.t#84730 Wed Dec 29 01​:25​:56 1999
+++ perl/t/op/range.t Thu Oct 31 01​:17​:12 2002
@​@​ -1,6 +1,6 @​@​
#!./perl

-print "1..15\n";
+print "1..16\n";

print join('​:',1..5) eq '1​:2​:3​:4​:5' ? "ok 1\n" : "not ok 1\n";

@​@​ -73,3 +73,7 @​@​
print "not ";
}
print "ok 15\n";
+
+# [#18165] Should allow "-4".."0", broken by #4730. (AMS 20021031)
+print "not " unless 5 == (() = "-4".."0");
+print "ok 16\n";

--
Slaven Rezic - slaven.rezic@​berlin.de

  tknotes - A knotes clone, written in Perl/Tk.
  http​://ptktools.sourceforge.net/#tknotes

@p5pRT
Copy link
Author

p5pRT commented Oct 30, 2002

From ams@wiw.org

At 2002-10-31 00​:13​:51 +0100, slaven.rezic@​berlin.de wrote​:

Please see also [perl #18114] and the patch there, which also handles
the "-4\n" .. "0\n" case.

Thanks, I've applied that patch with Yves Orton's tests and my comments,
as #18074.

-- ams, clearly not reading p5p with both eyes.

@p5pRT
Copy link
Author

p5pRT commented Nov 29, 2002

From @eserte

Abhijit Menon-Sen <ams@​wiw.org> writes​:

At 2002-10-31 00​:13​:51 +0100, slaven.rezic@​berlin.de wrote​:

Please see also [perl #18114] and the patch there, which also handles
the "-4\n" .. "0\n" case.

Thanks, I've applied that patch with Yves Orton's tests and my comments,
as #18074.

Here's a similar patch for the

  for ("-4" .. "0") { ... }

case​:

Inline Patch
--- bleedperl/pp_ctl.c	Mon Nov 25 04:42:18 2002
+++ bleedperl3/pp_ctl.c	Fri Nov 29 23:50:32 2002
@@ -1690,11 +1690,11 @@ PP(pp_enteriter)
 	cx->blk_loop.iterary = (AV*)SvREFCNT_inc(POPs);
 	if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
 	    dPOPss;
+	    /* See comment in pp_flop() */
 	    if (SvNIOKp(sv) || !SvPOKp(sv) ||
 		SvNIOKp(cx->blk_loop.iterary) || !SvPOKp(cx->blk_loop.iterary) ||
 		(looks_like_number(sv) && *SvPVX(sv) != '0' &&
-		 looks_like_number((SV*)cx->blk_loop.iterary) &&
-		 *SvPVX(cx->blk_loop.iterary) != '0'))
+		 looks_like_number((SV*)cx->blk_loop.iterary)))
 	    {
 		 if (SvNV(sv) < IV_MIN ||
 		     SvNV((SV*)cx->blk_loop.iterary) >= IV_MAX)
--- bleedperl/t/cmd/for.t	Thu May 10 15:28:03 2001
+++ bleedperl3/t/cmd/for.t	Fri Nov 29 23:43:39 2002
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..11\n";
+print "1..12\n";
 
 for ($i = 0; $i <= 10; $i++) {
     $x[$i] = $i;
@@ -66,3 +66,8 @@ foreach $b (bar()) {
 }
 print $a == 7 ? "ok" : "not ok", " 11\n";
 
+$loop_count = 0;
+for ("-3" .. "0") {
+    $loop_count++;
+}
+print $loop_count == 4 ? "ok" : "not ok", " 12\n";

-- 

Slaven Rezic - slaven.rezic@​berlin.de

Tk-AppMaster​: a perl/Tk module launcher designed for handhelds
  http​://tk-appmaster.sf.net

@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2002

From @rgs

Slaven Rezic wrote​:

Abhijit Menon-Sen <ams@​wiw.org> writes​:

At 2002-10-31 00​:13​:51 +0100, slaven.rezic@​berlin.de wrote​:

Please see also [perl #18114] and the patch there, which also handles
the "-4\n" .. "0\n" case.

Thanks, I've applied that patch with Yves Orton's tests and my comments,
as #18074.

Here's a similar patch for the

for \("\-4" \.\. "0"\) \{ \.\.\. \}

case​:

--- bleedperl/pp_ctl.c Mon Nov 25 04​:42​:18 2002
+++ bleedperl3/pp_ctl.c Fri Nov 29 23​:50​:32 2002

Thanks, applied as #18264.

@p5pRT
Copy link
Author

p5pRT commented Dec 8, 2002

@rgs - Status changed from 'new' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant