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

List Constructor Operator - Undefined Values #8079

Closed
p5pRT opened this issue Aug 19, 2005 · 8 comments
Closed

List Constructor Operator - Undefined Values #8079

p5pRT opened this issue Aug 19, 2005 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Aug 19, 2005

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

Searchable as RT36959$

@p5pRT
Copy link
Author

p5pRT commented Aug 19, 2005

From cunger@cas.org

This is a bug report for perl from cunger@​cas.org,
generated with the help of perlbug 1.35 running under perl v5.8.4.


The Perl snippet below produces different results under Perl 5.8.4,
than Perl 5.6.1 (and earlier versions).

Perl 5.6.1 (this is what I would have expected if an undefined value
is supplied as first parameter) output​:

Loop 1​: 0
Loop 1​: 1

Loop 2​: 0
Loop 2​: 1

Perl 5.8.4 (also same output with Perl 5.8.7)​:

Loop 1​:

Loop 2​: 0
Loop 2​: 1

OK, I consider this an application error if you use an undefined
value with the list constructor operator (..), but shouldn't the
behavior be the same between Perl 5 versions?

Code​:

#!/usr/local/perl5/bin/perl

my @​array = (1, 2); # this means $#array is set to 1

for $i ($value1..$#array) { # note that $value1 is undefined
  print "Loop 1​: $i\n";
}

print "\n";

for $i ($value2..$#array) { # note $value2 is also undefined
  print "Loop 2​: $i\n";
}



Flags​:
  category=core
  severity=low


Site configuration information for perl v5.8.4​:

Configured by cwu21 at Thu Apr 22 16​:01​:31 EDT 2004.

Summary of my perl5 (revision 5 version 8 subversion 4) configuration​:
  Platform​:
  osname=solaris, osvers=2.8, archname=sun4-solaris
  uname='sunos cwu21awu 5.8 generic_108528-29 sun4u sparc sunw,sun-blade-100 '
  config_args=''
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='/opt/SUNWspro/bin/cc', ccflags =' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O',
  cppflags=''
  ccversion='Sun WorkShop 6 update 2 C 5.3 Patch 111679-08 2002/05/09', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='/opt/SUNWspro/bin/cc', ldflags =' -L/usr/lib -L/usr/ccs/lib -L/opt/SUNWspro/WS6U2/lib -L/usr/local/lib '
  libpth=/usr/lib /usr/ccs/lib /opt/SUNWspro/WS6U2/lib /usr/local/lib
  libs=-lsocket -lnsl -ldl -lm -lc
  perllibs=-lsocket -lnsl -ldl -lm -lc
  libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version=''
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
  cccdlflags='-KPIC', lddlflags='-G -L/usr/lib -L/usr/ccs/lib -L/opt/SUNWspro/WS6U2/lib -L/usr/local/lib'

Locally applied patches​:
 


@​INC for perl v5.8.4​:
  /usr/local/perl5/lib/5.8.4/sun4-solaris
  /usr/local/perl5/lib/5.8.4
  /usr/local/perl5/lib/site_perl/5.8.4/sun4-solaris
  /usr/local/perl5/lib/site_perl/5.8.4
  /usr/local/perl5/lib/site_perl
  .


Environment for perl v5.8.4​:
  HOME=/home/cwu21
  LANG=C
  LANGUAGE (unset)
  LC_ALL=C
  LC_CTYPE=C
  LD_LIBRARY_PATH=/usr/dt/lib​:/usr/dt/lib/sdtimage​:/usr/openwin/lib​:/usr/lib​:/cas/lib/sun4
  LOGDIR (unset)
  PATH=/usr//bin​:/home/cwu21/bin/sun4​:/home/cwu21/bin​:/usr/local/bin​:/usr/dt/bin​:/usr/openwin/bin​:/bin​:/opt/SUNWsmtv/bin​:/cas/bin/sun4​:/cas/abin/sun4​:/cas/X11/sun4/bin​:/usr/ccs/bin​:/lprod/bin​:/usr/sbin​:/usr/ucb​:/cas/tools/bin/sun4​:/cas/X11/sun4/tools/bin​:/opt/staroffice7/program​:/home/cwu21/bin​:/vol/ossccs/bin​:/projects/gnu/bin/sun4​:/usr/java/jdk1.1.4/bin​:/usr/oracle/bin​:/usr/local/sbin​:/usr/lib/SoftPC​:/usr/perl5/bin​:/usr/atria/bin​:/vol/pgp/sun5/bin​:/opt/SUNWcluster/bin​:/projects/muse3/public/bin/sol​::​:/usr/dt/bin​:/usr/openwin/bin
  PERL_BADLANG (unset)
  SHELL=/bin/ksh

@p5pRT
Copy link
Author

p5pRT commented Aug 20, 2005

From @ysth

On Fri, Aug 19, 2005 at 01​:35​:49PM -0700, Chris Unger wrote​:

Perl 5.8.4 (also same output with Perl 5.8.7)​:

Loop 1​:

Loop 2​: 0
Loop 2​: 1

Code​:

#!/usr/local/perl5/bin/perl

my @​array = (1, 2); # this means $#array is set to 1

for $i ($value1..$#array) { # note that $value1 is undefined
print "Loop 1​: $i\n";
}

print "\n";

for $i ($value2..$#array) { # note $value2 is also undefined
print "Loop 2​: $i\n";
}

Sounds like a missing mg_get somewhere.

@p5pRT
Copy link
Author

p5pRT commented Aug 20, 2005

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Aug 20, 2005

From rick@bort.ca

On Fri, Aug 19, 2005 at 05​:30​:41PM -0700, Yitzchak Scott-Thoennes wrote​:

On Fri, Aug 19, 2005 at 01​:35​:49PM -0700, Chris Unger wrote​:

my @​array = (1, 2); # this means $#array is set to 1

for $i ($value1..$#array) { # note that $value1 is undefined
print "Loop 1​: $i\n";
}

print "\n";

for $i ($value2..$#array) { # note $value2 is also undefined
print "Loop 2​: $i\n";
}

Sounds like a missing mg_get somewhere.

Looks like it might be all over the place. From sv.h​:

  /* Let us hope that bitmaps for UV and IV are the same */
  #define SvIV(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv))
  #define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv))
  #define SvNV(sv) (SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv))

  #define SvIV_nomg(sv) (SvIOK(sv) ? SvIVX(sv) : sv_2iv_flags(sv, 0))
  #define SvUV_nomg(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv_flags(sv, 0))

Aren't those first three going to return the old un-mg_getted value
quite often? Should they just be

  #define SvIV(sv) sv_2iv(sv)
  #define SvUV(sv) sv_2uv(sv)
  #define SvNV(sv) sv_2nv(sv)

or is it the responsibility of setters to do SvNIOK_off?

--
Rick Delaney
rick@​bort.ca

@p5pRT
Copy link
Author

p5pRT commented Aug 21, 2005

From @ysth

On Sat, Aug 20, 2005 at 12​:43​:03AM -0400, Rick Delaney wrote​:

On Fri, Aug 19, 2005 at 05​:30​:41PM -0700, Yitzchak Scott-Thoennes wrote​:

On Fri, Aug 19, 2005 at 01​:35​:49PM -0700, Chris Unger wrote​:

my @​array = (1, 2); # this means $#array is set to 1

for $i ($value1..$#array) { # note that $value1 is undefined
print "Loop 1​: $i\n";
}

print "\n";

for $i ($value2..$#array) { # note $value2 is also undefined
print "Loop 2​: $i\n";
}

Sounds like a missing mg_get somewhere.

Looks like it might be all over the place. From sv.h​:

/\* Let us hope that bitmaps for UV and IV are the same \*/
\#define SvIV\(sv\) \(SvIOK\(sv\) ? SvIVX\(sv\) : sv\_2iv\(sv\)\)
\#define SvUV\(sv\) \(SvIOK\(sv\) ? SvUVX\(sv\) : sv\_2uv\(sv\)\)
\#define SvNV\(sv\) \(SvNOK\(sv\) ? SvNVX\(sv\) : sv\_2nv\(sv\)\)

\#define SvIV\_nomg\(sv\) \(SvIOK\(sv\) ? SvIVX\(sv\) : sv\_2iv\_flags\(sv\, 0\)\)
\#define SvUV\_nomg\(sv\) \(SvIOK\(sv\) ? SvUVX\(sv\) : sv\_2uv\_flags\(sv\, 0\)\)

Aren't those first three going to return the old un-mg_getted value
quite often? Should they just be

\#define SvIV\(sv\) sv\_2iv\(sv\)
\#define SvUV\(sv\) sv\_2uv\(sv\)
\#define SvNV\(sv\) sv\_2nv\(sv\)

or is it the responsibility of setters to do SvNIOK_off?

IIRC (don't have time to check the code now), magic only results in
the private flags being set (e.g. SvIOKp), so it all Just Works (TM).

@p5pRT
Copy link
Author

p5pRT commented Aug 21, 2005

From rick@bort.ca

On Sun, Aug 21, 2005 at 01​:00​:07AM -0700, Yitzchak Scott-Thoennes wrote​:

IIRC (don't have time to check the code now), magic only results in
the private flags being set (e.g. SvIOKp), so it all Just Works (TM).

Ah, thanks. I could have sworn that I saw IOK with Devel​::Peek in my
preliminary tests but I must have been seeing things since I can't
reproduce now. The problem is, as you stated, a missing mg_get. Patch
included.

--
Rick Delaney
rick@​bort.ca

Inline Patch
diff -rpuN perl-current/pp_ctl.c perl-current-dev/pp_ctl.c
--- perl-current/pp_ctl.c	2005-08-07 06:39:09.000000000 -0400
+++ perl-current-dev/pp_ctl.c	2005-08-21 14:52:48.145320881 -0400
@@ -1843,6 +1843,8 @@ PP(pp_enteriter)
 	if (SvTYPE(cx->blk_loop.iterary) != SVt_PVAV) {
 	    dPOPss;
 	    SV *right = (SV*)cx->blk_loop.iterary;
+	    SvGETMAGIC(sv);
+	    SvGETMAGIC(right);
 	    if (RANGE_IS_NUMERIC(sv,right)) {
 		if ((SvOK(sv) && SvNV(sv) < IV_MIN) ||
 		    (SvOK(right) && SvNV(right) >= IV_MAX))
diff -rpuN perl-current/t/op/range.t perl-current-dev/t/op/range.t
--- perl-current/t/op/range.t	2004-03-18 15:53:32.000000000 -0500
+++ perl-current-dev/t/op/range.t	2005-08-21 14:21:37.127953275 -0400
@@ -7,7 +7,7 @@ BEGIN {
 
 use Config;
 
-print "1..37\n";
+print "1..45\n";
 
 print join(':',1..5) eq '1:2:3:4:5' ? "ok 1\n" : "not ok 1\n";
 
@@ -140,3 +140,51 @@ print join(":", map "[$_]", @foo) eq '' 
 
 @foo=(); push @foo, $_ for undef..undef;
 print join(":", map "[$_]", @foo) eq '[]' ? "ok 37\n" : "not ok 37\n";
+
+# again with magic
+{
+    my @a = (1..3);
+    @foo=(); push @foo, $_ for undef..$#a;
+    print join(":", @foo) eq '0:1:2' ? "ok 38\n" : "not ok 38\n";
+}
+{
+    my @a = ();
+    @foo=(); push @foo, $_ for $#a..undef;
+    print join(":", @foo) eq '-1:0' ? "ok 39\n" : "not ok 39\n";
+}
+{
+    local $1;
+    "2" =~ /(.+)/;
+    @foo=(); push @foo, $_ for undef..$1;
+    print join(":", @foo) eq '0:1:2' ? "ok 40\n" : "not ok 40\n";
+}
+{
+    local $1;
+    "-2" =~ /(.+)/;
+    @foo=(); push @foo, $_ for $1..undef;
+    print join(":", @foo) eq '-2:-1:0' ? "ok 41\n" : "not ok 41\n";
+}
+{
+    local $1;
+    "B" =~ /(.+)/;
+    @foo=(); push @foo, $_ for undef..$1;
+    print join(":", map "[$_]", @foo) eq '[]' ? "ok 42\n" : "not ok 42\n";
+}
+{
+    local $1;
+    "B" =~ /(.+)/;
+    @foo=(); push @foo, $_ for ""..$1;
+    print join(":", map "[$_]", @foo) eq '[]' ? "ok 43\n" : "not ok 43\n";
+}
+{
+    local $1;
+    "B" =~ /(.+)/;
+    @foo=(); push @foo, $_ for $1..undef;
+    print join(":", map "[$_]", @foo) eq '' ? "ok 44\n" : "not ok 44\n";
+}
+{
+    local $1;
+    "B" =~ /(.+)/;
+    @foo=(); push @foo, $_ for $1.."";
+    print join(":", map "[$_]", @foo) eq '' ? "ok 45\n" : "not ok 45\n";
+}

@p5pRT
Copy link
Author

p5pRT commented Aug 22, 2005

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

@p5pRT p5pRT closed this as completed Aug 22, 2005
@p5pRT
Copy link
Author

p5pRT commented Aug 22, 2005

From @rgs

Rick Delaney wrote​:

On Sun, Aug 21, 2005 at 01​:00​:07AM -0700, Yitzchak Scott-Thoennes wrote​:

IIRC (don't have time to check the code now), magic only results in
the private flags being set (e.g. SvIOKp), so it all Just Works (TM).

Ah, thanks. I could have sworn that I saw IOK with Devel​::Peek in my
preliminary tests but I must have been seeing things since I can't
reproduce now. The problem is, as you stated, a missing mg_get. Patch
included.

Thanks, applied as change #25319.

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

No branches or pull requests

1 participant