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
Refcounting bug with reused implicit lexicals as nested loop iterators #9440
Comments
From fish-perlbug@uc.orgThis is a bug report for perl from fish-perlbug@uc.org, Re-using the same implicitly lexical iterator variable in nested loops Terrible, terrible coding style, I know, but still, a bug. Self-contained example: --start-- my @list1 = ( qw{ foo } ); for $i ( @list1 ) { --cut-- Result: This happens consistently on perl 5.10 but not on 5.8.* nor does it appear to It is specific to the nesting of the foreach-style loops with implicit lexical The entry of the first loop aliases $i to the first SV of the first list. This However, on exit of the inner list, the refcount of the first item of the first --start-- use Devel::Peek; my @list1 = ( qw{ foo } ); for $i ( @list1 ) { print Dump \@list1; --cut-- SV = RV(0x1233938) at 0x1233928 Comparing that with bleadperl: SV = IV(0x1423928) at 0x1423928 Dumping \$i after the exit of the inner loop, the refcount of the SV is 2, If the $i is a package global in the declaration, this issue does not manifest. Not sure if this is a known issue - it doesn't seem to happen in bleadperl, but The effect of this seems to vary a fair bit. In the case I was seeing this in Not cygwin specific, seen on linux as well. Flags: This perlbug was built using Perl 5.10.0 - Tue Mar 18 00:26:31 EDT 2008 Site configuration information for perl 5.10.0: Configured by rurban at Mon Jun 30 16:03:19 GMT 2008. Summary of my perl5 (revision 5 version 10 subversion 0 patch 34065) configuration: Locally applied patches: @INC for perl 5.10.0: Environment for perl 5.10.0: |
From p5p@perl.wizbit.beCiteren "fish-perlbug@uc.org (via RT)" <perlbug-followup@perl.org>:
Thanks for the bug report and the small test. Binary search to see which Change broke it: ----Program---- my ----Output of .../pdnRSb4/perl-5.9.2@26026/bin/perl---- ----EOF ($?='0')---- ----EOF ($?='0')---- http://public.activestate.com/cgi-bin/perlbrowse/p/26027 Subject: [perl #24254] Attempt to free unreferenced scalar http://rt.perl.org/rt3/Public/Bug/Display.html?id=24254 Binary search to see which Change fixed it: ----Program---- my ----Output of ...p0B4D4a/perl-5.10.0@33077/bin/perl---- ----EOF ($?='0')---- ----EOF ($?='0')---- perl-p-5.10.0\@33079/miniperl test_57564.pl perl-p-5.10.0\@33078/miniperl test_57564.pl So it got fixed with Change 33078 or Change 33079, or Change 33080. http://public.activestate.com/cgi-bin/perlbrowse/p/33078 POPLOOP is actually doing all the work of Perl_save_padsv() already! http://public.activestate.com/cgi-bin/perlbrowse/p/33079 Change 33072 missed embed.h. I wasn't aware that it was affected by http://public.activestate.com/cgi-bin/perlbrowse/p/33080 Investigation reveals that the work of restoring the iterator to the All this means that itersave is now redundant. So remove it. None of the Changes (the one that broke it and the one that fixed it) Kind regards, Bram |
The RT System itself - Status changed from 'new' to 'open' |
From p5p@perl.wizbit.beCiteren Bram <p5p@perl.wizbit.be>:
Patch with tests attached. Will the Changes 33078, 33079, and 33080 be intergrated into 5.10.x? If not then the last test needs to be marked todo/skip in 5.10.x. Kind regards, Bram |
From p5p@perl.wizbit.beInline Patch--- old/t/op/ref.t 2008-08-05 18:48:45.000000000 +0200
+++ new/t/op/ref.t 2008-08-05 19:48:08.000000000 +0200
@@ -8,7 +8,7 @@
require 'test.pl';
use strict qw(refs subs);
-plan(182);
+plan(189);
# Test glob operations.
@@ -584,6 +584,18 @@
ok (!eval { $pvbm->() }, 'PVBM is not a CODE ref');
ok (!eval { $rpvbm->foo }, 'PVBM is not an object');
+# bug 24254
+is( runperl(stderr => 1, prog => 'map eval qq(exit),1 for 1'), "");
+is( runperl(stderr => 1, prog => 'eval { for (1) { map { die } 2 } };'), "");
+is( runperl(stderr => 1, prog => 'for (125) { map { exit } (213)}'), "");
+is( runperl(stderr => 1, prog => 'map die,4 for 3'), "Died at -e line 1.\n");
+is( runperl(stderr => 1, prog => 'grep die,4 for 3'), "Died at -e line 1.\n");
+is( runperl(stderr => 1, prog => 'for $a (3) {@b=sort {die} 4,5}'), "Died at -e line 1.\n");
+
+# bug 57564
+is( runperl(stderr => 1, prog => 'my $i;for $i (1) { for $i (2) { } }'), "");
+
+
# Bit of a hack to make test.pl happy. There are 3 more tests after it leaves.
$test = curr_test();
curr_test($test + 3); |
From @TuxOn Tue, 05 Aug 2008 19:58:00 +0200, Bram <p5p@perl.wizbit.be> wrote:
Thanks, applied in change #34171 -- |
p5p@spam.wizbit.be - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#57564 (status was 'resolved')
Searchable as RT57564$
The text was updated successfully, but these errors were encountered: