-
Notifications
You must be signed in to change notification settings - Fork 574
$_ incorrect within for loop inside map #14269
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
Comments
From @stas53Cc: s.romanski@datos.pl This is a bug report for perl from s.romanski@datos.pl, #!perl -w use strict; Flags: Site configuration information for perl 5.16.3: Configured by gecko at Wed Mar 13 11:25:21 2013. Summary of my perl5 (revision 5 version 16 subversion 3) configuration: Locally applied patches: @INC for perl 5.16.3: Environment for perl 5.16.3: Complete configuration data for perl 5.16.3: Author='' |
From @pjcjCreated by @pjcjThis is a bug report for perl from paul@pjcj.net, ----------------------------------------------------------------- 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)' It worked in 5.6.* and is broken in 5.8.0. Specifically, it broke in 36c6672: commit 36c6672 Re: [ID 20010309.004] my-variables lose values while goto'ing within a for(;;)-loop 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 Perl Info
|
From @cpansproutOn Sun Nov 23 15:22:09 2014, paul@pjcj.net wrote:
The really weird thing is that ${\$_} just works. -- Father Chrysostomos |
The RT System itself - Status changed from 'new' to 'open' |
From @pjcjThis should be merged with 123285, which is Stanislaw's own report which -- |
From @davidnicolPerlsyn's section on C-style "for" loops does not mention aliasing $_ at $ perl -le 'map { for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; On Mon, Nov 24, 2014 at 4:21 AM, Paul Johnson <paul@pjcj.net> wrote:
-- |
From @ilmariDavid Nicol <davidnicol@gmail.com> writes:
It doesn't even have to be the topic. Any variable (global or lexical)
perl -le 'map { $foo; for (my $i = 0; $i < 3; $i++) { push @a, $_ } } a..e; print @a'
-- |
From @cpansproutOn Mon Nov 24 11:01:51 2014, ilmari wrote:
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 |
From @ikegamiOn Mon, Nov 24, 2014 at 1:46 PM, David Nicol <davidnicol@gmail.com> wrote:
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; # Statement before # $_ outside of for |
From @ikegamiOn Mon, Nov 24, 2014 at 3:04 PM, Eric Brine <ikegami@adaelis.com> wrote:
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; # Statement before # Statement after |
From @cpansproutOn Mon Nov 24 12:06:46 2014, ikegami@adaelis.com 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); 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)' Take away that empty list: $ ./miniperl -le 'map { for (my $i = 0; $i < 3; $i++) { study $_; }; } a..e; print join(" ", @a)' The stack offset of 1 is now pointing to one of map’s arguments. -- Father Chrysostomos |
From @cpansproutOn Tue Nov 25 16:54:17 2014, sprout wrote:
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;' -- Father Chrysostomos |
From @cpansproutOn Tue Nov 25 17:08:29 2014, sprout wrote:
See <http://perl5.git.perl.org/perl.git/commitdiff/0f602692a>. -- Father Chrysostomos |
@cpansprout - Status changed from 'open' to 'pending release' |
From @pjcjOn Tue, Nov 25, 2014 at 08:12:10PM -0800, Father Chrysostomos via RT wrote:
Thanks! -- |
From @stas53Hello Father Chrysostomos, Thanks for fixing a bug and for a clear explanation of the case I am proud I could point out a bug lasting about 12 years We had had a long discussion about this case Thank you again and Good Luck ! Dr. Stanislaw Romanski ----- Original Message -----
|
From @khwilliamsonThanks 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 -- |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#123286 (status was 'resolved')
Searchable as RT123286$
The text was updated successfully, but these errors were encountered: