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

Inconsistent scoping for while .. redo #9677

Closed
p5pRT opened this issue Mar 9, 2009 · 4 comments
Closed

Inconsistent scoping for while .. redo #9677

p5pRT opened this issue Mar 9, 2009 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 9, 2009

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

Searchable as RT63752$

@p5pRT
Copy link
Author

p5pRT commented Mar 9, 2009

From @kenneth-k

This is a bug report for perl from kennethk@​cpan.org,
generated with the help of perlbug 1.35 running under perl v5.8.8.

#!/usr/bin/perl
# This displays scoping inconsistencies between various
# versions of perl. Specifically, under several Linux
# builds of v5.8.8, $i becomes undefined after the redo and
# the script outputs '2'.
# Those are​: v5.8.8 built for i386-linux-thread-multi
# v5.8.8 built for i486-linux-gnu-thread-multi
# v5.8.8 built for x86_64-linux-gnu-thread-multi
# For other builds, $i maintains its value and the script
# outputs '210'.
# Those are​: v5.10.0 built for x86_64-linux-gnu-thread-multi
# v5.8.8 built for MSWin32-x86-multi-thread
# v5.8.9 built for MSWin32-x86-multi-thread
# There is a discussion at​:
# http​://www.perlmonks.org/?node_id=749322
use strict;
use warnings;

my $j = 2;
while ( my $i = $j ) {
  print $i if defined $i;
  last unless $i--;
  redo;
}


Flags​:
  category=core
  severity=medium


Site configuration information for perl v5.8.8​:

Configured by Debian Project at Wed Jan 14 22​:49​:45 UTC 2009.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration​:
  Platform​:
  osname=linux, osvers=2.6.24-16-server,
archname=x86_64-linux-gnu-thread-multi
  uname='linux yellow 2.6.24-16-server #1 smp thu apr 10 13​:15​:38
utc 2008 x86_64 gnulinux '
  config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN
-Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr
-Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8
-Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5
-Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local
-Dsitelib=/usr/local/share/perl/5.8.8
-Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1
-Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1
-Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl
-Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio
-Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
  hint=recommended, useposix=true, d_sigaction=define
  usethreads=define use5005threads=undef useithreads=define
usemultiplicity=define
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=define use64bitall=define uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN
-fno-strict-aliasing -pipe -I/usr/local/include'
  ccversion='', gccversion='4.2.3 (Ubuntu 4.2.3-2ubuntu7)', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -L/usr/local/lib'
  libpth=/usr/local/lib /lib /usr/lib
  libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
  perllibs=-ldl -lm -lpthread -lc -lcrypt
  libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
  gnulibc_version='2.7'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
  cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches​:


@​INC for perl v5.8.8​:
  /etc/perl
  /usr/local/lib/perl/5.8.8
  /usr/local/share/perl/5.8.8
  /usr/lib/perl5
  /usr/share/perl5
  /usr/lib/perl/5.8
  /usr/share/perl/5.8
  /usr/local/lib/site_perl
  .


Environment for perl v5.8.8​:
  HOME=/home/kennethk
  LANG=en_US.UTF-8
  LANGUAGE (unset)
  LD_LIBRARY_PATH=/opt/sun/sunstudio12/lib/amd64​:/opt/sun/sunstudio12/rtlibs/amd64​:/opt/intel/fce/10.1.015/lib​:/usr/local/lib
  LOGDIR (unset)
  PATH=/opt/sun/sunstudio12/bin​:/opt/intel/fce/10.1.015/bin​:/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/sbin​:/bin​:/usr/games​:/u01/app/oracle/product/11.1.0/client_1/bin
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2009

From p5p@spam.wizbit.be

On Mon Mar 09 14​:09​:46 2009, kennethk@​cpan.org wrote​:

This is a bug report for perl from kennethk@​cpan.org,
generated with the help of perlbug 1.35 running under perl v5.8.8.

#!/usr/bin/perl
# This displays scoping inconsistencies between various
# versions of perl. Specifically, under several Linux
# builds of v5.8.8, $i becomes undefined after the redo and
# the script outputs '2'.
# Those are​: v5.8.8 built for i386-linux-thread-multi
# v5.8.8 built for i486-linux-gnu-thread-multi
# v5.8.8 built for x86_64-linux-gnu-thread-multi
# For other builds, $i maintains its value and the script
# outputs '210'.
# Those are​: v5.10.0 built for x86_64-linux-gnu-thread-multi
# v5.8.8 built for MSWin32-x86-multi-thread
# v5.8.9 built for MSWin32-x86-multi-thread
# There is a discussion at​:
# http​://www.perlmonks.org/?node_id=749322
use strict;
use warnings;

my $j = 2;
while ( my $i = $j ) {
print $i if defined $i;
last unless $i--;
redo;
}
---

Hello,

Thank you for your bug report.

A binary search reveals​:

http​://public.activestate.com/cgi-bin/perlbrowse/p/24412
Change 24412 by davem@​davem-splatty on 2005/05/07 12​:57​:06

  while (my $x ...) { ...; redo } shouldn't undef $x.
  In the presence of 'my' in the conditional of a while(),
until(),
  or for(;;) loop, add an extra scope to the body so that redo
  doesn't undef the lexical

This is an intended change of behaviour (a bugfix) so I'm marking this
as resolved, notabug.

If you want code that behaves correctly on all versions of perl then
you should add an extra scope and declare my $i in it.

That is​:

#!/usr/bin/perl

use strict;
use warnings;

my $j = 2;
{
  my $i;
  while ( $i = $j ) {
  print $i if defined $i;
  last unless $i--;
  redo;
  }
}

(The only reason why your code is printing 210 on 'v5.8.8 built for
MSWin32-x86-multi-thread ' is because it not a stock perl. (read​:
patches were applied to it.))

Kind regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2009

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

@p5pRT
Copy link
Author

p5pRT commented Mar 11, 2009

p5p@spam.wizbit.be - Status changed from 'open' 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