Skip Menu |
Report information
Id: 123286
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: paul [at] pjcj.net
s.romanski [at] datos.pl
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: medium
Type: core
Perl Version: 5.20.1
Fixed In: 5.22.0



Date: Sun, 23 Nov 2014 23:17:01 +0100
To: <perlbug [...] perl.org>
From: "Stanislaw Romanski" <s.romanski [...] datos.pl>
Subject: bug in core perl - tested in v.5.10, 5.16, 5.18 - Strange behaviour of $_ in 'for' nested in 'map'
Download (untitled) / with headers
text/plain 28.8k

Message body is not shown because it is too large.

Download (untitled) / with headers
text/html 34.3k

Message body is not shown because it is too large.

Subject: $_ incorrect within for loop inside map
Date: Mon, 24 Nov 2014 00:21:36 +0100 (CET)
From: paul [...] pjcj.net
To: perlbug [...] perl.org
CC: paul [...] pjcj.net
Download (untitled) / with headers
text/plain 4.4k
This is a bug report for perl from paul@pjcj.net, generated with the help of perlbug 1.40 running under perl 5.20.1. ----------------------------------------------------------------- Here's a lovely bug found by Stanislaw Romanski and reported on LinkedIn. $ perl -e 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)' aaa333012dddeee It worked in 5.6.* and is broken in 5.8.0. Specifically, it broke in 36c66720: commit 36c66720946952b050ad9db88444230a58b3c69d Author: Robin Houston <robin@cpan.org> Date: Wed Mar 14 00:43:45 2001 +0000 Re: [ID 20010309.004] my-variables lose values while goto'ing within a for(;;)-loop Message-ID: <20010314004345.A15892@puffinry.freeserve.co.uk> p4raw-id: //depot/perl@9139 The commit was identified with: $ ../perl-bisect/Porting/bisect.pl --end=perl-5.8.0 -- ./perl -e 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; exit 0+!(jonn("", @a) eq "aaabbbcccdddeee")' For completeness, the original message is at https://www.linkedin.com/groupItem?view=&gid=106254&type=member&item=5942368474230718468D but you probably have to be logged in to LinkedIn and be a member of the Perl group to see that. [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=medium --- Site configuration information for perl 5.20.1: Configured by pjcj at Sun Oct 19 17:08:42 CEST 2014. Summary of my perl5 (revision 5 version 20 subversion 1) configuration: Platform: osname=linux, osvers=3.13.0-37-generic, archname=x86_64-linux uname='linux posub64 3.13.0-37-generic #64-ubuntu smp mon sep 22 21:28:38 utc 2014 x86_64 x86_64 x86_64 gnulinux ' config_args='-de -Dprefix=/home/pjcj/perl5/perlbrew/perls/perl-5.20.1 -Aeval:scriptdir=/home/pjcj/perl5/perlbrew/perls/perl-5.20.1/bin' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.8.2', 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 =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.19' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector' --- @INC for perl 5.20.1: /home/pjcj/perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1/x86_64-linux /home/pjcj/perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1 /home/pjcj/perl5/perlbrew/perls/perl-5.20.1/lib/5.20.1/x86_64-linux /home/pjcj/perl5/perlbrew/perls/perl-5.20.1/lib/5.20.1 . --- Environment for perl 5.20.1: HOME=/home/pjcj LANG=en_GB.UTF-8 LANGUAGE=en_GB:en LC_COLLATE=en_GB.UTF-8 LC_CTYPE=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/pjcj/perl5/perlbrew/bin:/home/pjcj/perl5/perlbrew/perls/perl-5.20.1/bin:/home/pjcj/bin:/home/pjcj/g/local_base/utils:/home/pjcj/g/base/utils:/home/pjcj/g/sw/bin:/home/pjcj/g/sw/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/pjcj/.local/bin PERLBREW=command perlbrew PERLBREW_BASHRC_VERSION=0.71 PERLBREW_HOME=/home/pjcj/.perlbrew PERLBREW_MANPATH=/home/pjcj/perl5/perlbrew/perls/perl-5.20.1/man PERLBREW_PATH=/home/pjcj/perl5/perlbrew/bin:/home/pjcj/perl5/perlbrew/perls/perl-5.20.1/bin PERLBREW_PERL=perl-5.20.1 PERLBREW_ROOT=/home/pjcj/perl5/perlbrew PERLBREW_VERSION=0.71 PERL_BADLANG (unset) SHELL=/bin/zsh
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 570b
On Sun Nov 23 15:22:09 2014, paul@pjcj.net wrote: Show quoted text
> > This is a bug report for perl from paul@pjcj.net, > generated with the help of perlbug 1.40 running under perl 5.20.1. > > > ----------------------------------------------------------------- > > Here's a lovely bug found by Stanislaw Romanski and reported on > LinkedIn. > > $ perl -e 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; > print join("", @a)' > aaa333012dddeee > > It worked in 5.6.* and is broken in 5.8.0.
The really weird thing is that ${\$_} just works. -- Father Chrysostomos
Date: Mon, 24 Nov 2014 10:21:00 +0000
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
From: Paul Johnson <paul [...] pjcj.net>
To: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 200b
This should be merged with 123285, which is Stanislaw's own report which was probably in moderation when I made this report. Sorry about that. -- Paul Johnson - paul@pjcj.net http://www.pjcj.net
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
From: David Nicol <davidnicol [...] gmail.com>
CC: Perl 5 Porters <perl5-porters [...] perl.org>
Date: Mon, 24 Nov 2014 12:46:02 -0600

Perlsyn's section on C-style "for" loops does not mention aliasing $_ at all, and when the topic
is simply mentioned prior to the loop, in 5.8.8, the bug disappears. This sure is screwy, how the behavior is right the first time, wrong the second, wrong in a different way the third, then back to right.

$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaa333012dddeee
$ perl -le 'map { $_; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaabbbcccdddeee



On Mon, Nov 24, 2014 at 4:21 AM, Paul Johnson <paul@pjcj.net> wrote:
Show quoted text

This should be merged with 123285, which is Stanislaw's own report which
was probably in moderation when I made this report.  Sorry about that.

--
Paul Johnson - paul@pjcj.net
http://www.pjcj.net




--
Sometimes I imply things, or include important information in pictures. Without a request for clarification, I will assume I was clear, which can cause later problems when I wasn't. So please ask me to clarify anything that seems ambiguous. Doing so is not rude. Thank you.

Date: Mon, 24 Nov 2014 20:01:20 +0100
To: perl5-porters [...] perl.org
From: ilmari [...] ilmari.org (Dagfinn Ilmari Mannsåker)
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
Download (untitled) / with headers
text/plain 1.3k
David Nicol <davidnicol@gmail.com> writes: Show quoted text
> Perlsyn's section on C-style "for" loops does not mention aliasing $_ > at all, and when the topic is simply mentioned prior to the loop, in > 5.8.8, the bug disappears.
It doesn't even have to be the topic. Any variable (global or lexical) will do. Show quoted text
> This sure is screwy, how the behavior is right the first time, wrong > the second, wrong in a different way the third, then back to right. > > $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; > print join("", @a)' > aaa333012dddeee > $ perl -le 'map { $_; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; > print join("", @a)' > aaabbbcccdddeee
perl -le 'map { $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print @a' aaabbbcccdddeee perl -le 'map { my $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print @a' aaabbbcccdddeee perl -le 'map { our $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print @a' aaabbbcccdddeee Show quoted text
> On Mon, Nov 24, 2014 at 4:21 AM, Paul Johnson <paul@pjcj.net> wrote: >
>> >> This should be merged with 123285, which is Stanislaw's own report which >> was probably in moderation when I made this report. Sorry about that. >> >> -- >> Paul Johnson - paul@pjcj.net >> http://www.pjcj.net >>
-- "A disappointingly low fraction of the human race is, at any given time, on fire." - Stig Sandbeck Mathisen
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.3k
On Mon Nov 24 11:01:51 2014, ilmari wrote: Show quoted text
> David Nicol <davidnicol@gmail.com> writes: >
> > Perlsyn's section on C-style "for" loops does not mention aliasing $_ > > at all, and when the topic is simply mentioned prior to the loop, in > > 5.8.8, the bug disappears.
> > It doesn't even have to be the topic. Any variable (global or lexical) > will do. >
> > This sure is screwy, how the behavior is right the first time, wrong > > the second, wrong in a different way the third, then back to right. > > > > $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } > > a..e; > > print join("", @a)' > > aaa333012dddeee > > $ perl -le 'map { $_; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } > > a..e; > > print join("", @a)' > > aaabbbcccdddeee
> > perl -le 'map { $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } > a..e; print @a' > aaabbbcccdddeee > perl -le 'map { my $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ } > } a..e; print @a' > aaabbbcccdddeee > perl -le 'map { our $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ > } } a..e; print @a' > aaabbbcccdddeee
This smells like a stack bug. I suspect the key is that the for loop must be the only thing inside the map block and there must be only one statement inside the for loop. New statements generally reset the stack, but things may get screwy at the beginning of a scope. -- Father Chrysostomos
Date: Mon, 24 Nov 2014 15:04:24 -0500
CC: Perl 5 Porters <perl5-porters [...] perl.org>
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
To: David Nicol <davidnicol [...] gmail.com>
From: Eric Brine <ikegami [...] adaelis.com>
Download (untitled) / with headers
text/plain 697b
On Mon, Nov 24, 2014 at 1:46 PM, David Nicol <davidnicol@gmail.com> wrote:
Show quoted text

Perlsyn's section on C-style "for" loops does not mention aliasing $_ at all, and when the topic
is simply mentioned prior to the loop, in 5.8.8, the bug disappears.

Placing a statement before the for also makes the weirdness disappear.

$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaa333012dddeee

# Statement before
$ perl -le 'map { ""; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaabbbcccdddeee

# $_ outside of for
$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } $_ } a..e; print join("", @a)'
aaabbbcccdddeee

CC: Perl 5 Porters <perl5-porters [...] perl.org>
Date: Mon, 24 Nov 2014 15:06:25 -0500
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
To: David Nicol <davidnicol [...] gmail.com>
From: Eric Brine <ikegami [...] adaelis.com>
Download (untitled) / with headers
text/plain 1.2k
On Mon, Nov 24, 2014 at 3:04 PM, Eric Brine <ikegami@adaelis.com> wrote:
Show quoted text
On Mon, Nov 24, 2014 at 1:46 PM, David Nicol <davidnicol@gmail.com> wrote:

Perlsyn's section on C-style "for" loops does not mention aliasing $_ at all, and when the topic
is simply mentioned prior to the loop, in 5.8.8, the bug disappears.

Placing a statement before the for also makes the weirdness disappear.

$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaa333012dddeee

# Statement before
$ perl -le 'map { ""; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaabbbcccdddeee

# $_ outside of for
$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } $_ } a..e; print join("", @a)'
aaabbbcccdddeee


Correction, any other statement, before or after, makes the problem go away.

$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaa333012dddeee

# Statement before
$ perl -le 'map { ""; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print join("", @a)'
aaabbbcccdddeee

# Statement after
$ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } "" } a..e; print join("", @a)'
aaabbbcccdddeee


RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 2.7k
On Mon Nov 24 12:06:46 2014, ikegami@adaelis.com wrote: Show quoted text
> On Mon, Nov 24, 2014 at 3:04 PM, Eric Brine <ikegami@adaelis.com> wrote: >
> > On Mon, Nov 24, 2014 at 1:46 PM, David Nicol <davidnicol@gmail.com> wrote: > >
> >> > >> Perlsyn's section on C-style "for" loops does not mention aliasing $_ at > >> all, and when the topic > >> is simply mentioned prior to the loop, in 5.8.8, the bug disappears. > >>
> > > > Placing a statement before the for also makes the weirdness disappear. > > > > $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; > > print join("", @a)' > > aaa333012dddeee > > > > # Statement before > > $ perl -le 'map { ""; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } > > a..e; print join("", @a)' > > aaabbbcccdddeee > > > > # $_ outside of for > > $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } $_ } a..e; > > print join("", @a)' > > aaabbbcccdddeee > > > >
> Correction, any other statement, before or after, makes the problem go away. > > $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; > print join("", @a)' > aaa333012dddeee > > # Statement before > $ perl -le 'map { ""; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; > print join("", @a)' > aaabbbcccdddeee > > # Statement after > $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } "" } a..e; > print join("", @a)' > aaabbbcccdddeee
The extra statements seem to be correcting the stack bug. It seems that the for-loop is using the wrong stack offset and stomping on the arguments to map. The ‘333’ in the output is the constant 3 in $i<3. The ‘012’ is $i. If I add the following code to pp.c:pp_study: Perl_warn(aTHX_ "stack %d", PL_stack_sp-PL_stack_base); Perl_warn(aTHX_ "markstack %d", PL_markstack_ptr-PL_markstack); Perl_warn(aTHX_ "arg is %"SVf", defsv is %"SVf, sv, DEFSV); Then I see a stack offset of 6 with multiple statements: $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; () } a..e; print join(" ", @a)' stack 6 at -e line 1. markstack 4 at -e line 1. arg is a, defsv is a at -e line 1. ... Take away that empty list: $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; } a..e; print join(" ", @a)' stack 1 at -e line 1. markstack 4 at -e line 1. arg is a, defsv is a at -e line 1. stack 1 at -e line 1. markstack 4 at -e line 1. arg is a, defsv is a at -e line 1. stack 1 at -e line 1. markstack 4 at -e line 1. arg is a, defsv is a at -e line 1. stack 1 at -e line 1. markstack 4 at -e line 1. arg is 3, defsv is 3 at -e line 1. stack 1 at -e line 1. markstack 4 at -e line 1. arg is 3, defsv is 3 at -e line 1. stack 1 at -e line 1. markstack 4 at -e line 1. arg is 3, defsv is 3 at -e line 1. The stack offset of 1 is now pointing to one of map’s arguments. -- Father Chrysostomos
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.6k
On Tue Nov 25 16:54:17 2014, sprout wrote: Show quoted text
> The extra statements seem to be correcting the stack bug. It seems > that the for-loop is using the wrong stack offset and stomping on the > arguments to map. > > The ‘333’ in the output is the constant 3 in $i<3. The ‘012’ is $i. > > If I add the following code to pp.c:pp_study: > > Perl_warn(aTHX_ "stack %d", PL_stack_sp-PL_stack_base); > Perl_warn(aTHX_ "markstack %d", PL_markstack_ptr-PL_markstack); > Perl_warn(aTHX_ "arg is %"SVf", defsv is %"SVf, sv, DEFSV); > > Then I see a stack offset of 6 with multiple statements: > > $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; > () } a..e; print join(" ", @a)' > stack 6 at -e line 1. > markstack 4 at -e line 1. > arg is a, defsv is a at -e line 1. > ... > > Take away that empty list: > > $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; } > a..e; print join(" ", @a)' > stack 1 at -e line 1. > markstack 4 at -e line 1. > arg is a, defsv is a at -e line 1. > stack 1 at -e line 1. > markstack 4 at -e line 1. > arg is a, defsv is a at -e line 1. > stack 1 at -e line 1. > markstack 4 at -e line 1. > arg is a, defsv is a at -e line 1. > stack 1 at -e line 1. > markstack 4 at -e line 1. > arg is 3, defsv is 3 at -e line 1. > stack 1 at -e line 1. > markstack 4 at -e line 1. > arg is 3, defsv is 3 at -e line 1. > stack 1 at -e line 1. > markstack 4 at -e line 1. > arg is 3, defsv is 3 at -e line 1. > > The stack offset of 1 is now pointing to one of map’s arguments.
Found the bug. I’ll put the details in the commit message. Here is another instance of it: $ perl5.20.1 -le 'print 1..3, do{for(0;0;){}}, 4..6;' 0456 -- Father Chrysostomos
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.7k
On Tue Nov 25 17:08:29 2014, sprout wrote: Show quoted text
> On Tue Nov 25 16:54:17 2014, sprout wrote:
> > The extra statements seem to be correcting the stack bug. It seems > > that the for-loop is using the wrong stack offset and stomping on the > > arguments to map. > > > > The ‘333’ in the output is the constant 3 in $i<3. The ‘012’ is $i. > > > > If I add the following code to pp.c:pp_study: > > > > Perl_warn(aTHX_ "stack %d", PL_stack_sp-PL_stack_base); > > Perl_warn(aTHX_ "markstack %d", PL_markstack_ptr-PL_markstack); > > Perl_warn(aTHX_ "arg is %"SVf", defsv is %"SVf, sv, DEFSV); > > > > Then I see a stack offset of 6 with multiple statements: > > > > $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; > > () } a..e; print join(" ", @a)' > > stack 6 at -e line 1. > > markstack 4 at -e line 1. > > arg is a, defsv is a at -e line 1. > > ... > > > > Take away that empty list: > > > > $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; > > } > > a..e; print join(" ", @a)' > > stack 1 at -e line 1. > > markstack 4 at -e line 1. > > arg is a, defsv is a at -e line 1. > > stack 1 at -e line 1. > > markstack 4 at -e line 1. > > arg is a, defsv is a at -e line 1. > > stack 1 at -e line 1. > > markstack 4 at -e line 1. > > arg is a, defsv is a at -e line 1. > > stack 1 at -e line 1. > > markstack 4 at -e line 1. > > arg is 3, defsv is 3 at -e line 1. > > stack 1 at -e line 1. > > markstack 4 at -e line 1. > > arg is 3, defsv is 3 at -e line 1. > > stack 1 at -e line 1. > > markstack 4 at -e line 1. > > arg is 3, defsv is 3 at -e line 1. > > > > The stack offset of 1 is now pointing to one of map’s arguments.
> > Found the bug. I’ll put the details in the commit message.
See <http://perl5.git.perl.org/perl.git/commitdiff/0f602692a>. -- Father Chrysostomos
CC: perl5-porters [...] perl.org
Date: Wed, 26 Nov 2014 09:39:26 +0000
From: Paul Johnson <paul [...] pjcj.net>
To: Father Chrysostomos via RT <perlbug-followup [...] perl.org>
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
Download (untitled) / with headers
text/plain 324b
On Tue, Nov 25, 2014 at 08:12:10PM -0800, Father Chrysostomos via RT wrote: Show quoted text
> On Tue Nov 25 17:08:29 2014, sprout wrote:
> > > > Found the bug. I’ll put the details in the commit message.
> > See <http://perl5.git.perl.org/perl.git/commitdiff/0f602692a>.
Thanks! -- Paul Johnson - paul@pjcj.net http://www.pjcj.net
Subject: Re: [perl #123286] $_ incorrect within for loop inside map
Date: Wed, 26 Nov 2014 11:44:21 +0100
From: "Stanislaw Romanski" <s.romanski [...] datos.pl>
To: <perlbug-followup [...] perl.org>, <paul [...] pjcj.net>
Download (untitled) / with headers
text/plain 2.4k
Hello Father Chrysostomos, Thanks for fixing a bug and for a clear explanation of the case you gave in the commit. I am proud I could point out a bug lasting about 12 years in the interpreter of my favourite language ;-)) We had had a long discussion about this case in Linkedin' group 'Perl'. Thank you again and Good Luck ! Dr. Stanislaw Romanski Show quoted text
----- Original Message ----- From: "Father Chrysostomos via RT" <perlbug-followup@perl.org> To: <paul@pjcj.net>; <s.romanski@datos.pl> Sent: Wednesday, November 26, 2014 5:12 AM Subject: [perl #123286] $_ incorrect within for loop inside map
> On Tue Nov 25 17:08:29 2014, sprout wrote:
>> On Tue Nov 25 16:54:17 2014, sprout wrote:
>> > The extra statements seem to be correcting the stack bug. It seems >> > that the for-loop is using the wrong stack offset and stomping on the >> > arguments to map. >> > >> > The ‘333’ in the output is the constant 3 in $i<3. The ‘012’ is $i. >> > >> > If I add the following code to pp.c:pp_study: >> > >> > Perl_warn(aTHX_ "stack %d", PL_stack_sp-PL_stack_base); >> > Perl_warn(aTHX_ "markstack %d", PL_markstack_ptr-PL_markstack); >> > Perl_warn(aTHX_ "arg is %"SVf", defsv is %"SVf, sv, DEFSV); >> > >> > Then I see a stack offset of 6 with multiple statements: >> > >> > $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; >> > () } a..e; print join(" ", @a)' >> > stack 6 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is a, defsv is a at -e line 1. >> > ... >> > >> > Take away that empty list: >> > >> > $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; >> > } >> > a..e; print join(" ", @a)' >> > stack 1 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is a, defsv is a at -e line 1. >> > stack 1 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is a, defsv is a at -e line 1. >> > stack 1 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is a, defsv is a at -e line 1. >> > stack 1 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is 3, defsv is 3 at -e line 1. >> > stack 1 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is 3, defsv is 3 at -e line 1. >> > stack 1 at -e line 1. >> > markstack 4 at -e line 1. >> > arg is 3, defsv is 3 at -e line 1. >> > >> > The stack offset of 1 is now pointing to one of map’s arguments.
>> >> Found the bug. I’ll put the details in the commit message.
> > See <http://perl5.git.perl.org/perl.git/commitdiff/0f602692a>. > > -- > > Father Chrysostomos >
Subject: Your ticket against Perl 5 has been resolved
Download (untitled) / with headers
text/plain 263b
Thanks for submitting this ticket The issue should be resolved with the release today of Perl v5.22, available at http://www.perl.org/get.html If you find that the problem persists, feel free to reopen this ticket -- Karl Williamson for the Perl 5 porters team


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org