develooper Front page | perl.perl5.porters | Postings from September 2013

Re: [perl #119797] lvalue sub shows "Bizarre copy of ARRAY in blockexit" in very specific case.

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
September 15, 2013 14:19
Subject:
Re: [perl #119797] lvalue sub shows "Bizarre copy of ARRAY in blockexit" in very specific case.
Message ID:
CAHAeAG4UjRyS5QG1ZnVfC4Lj8wmOZvORgnfYWZRtg+QzkaZSEw@mail.gmail.com
On Sun, Sep 15, 2013 at 3:21 PM, James E Keenan via RT <
perlbug-followup@perl.org> wrote:

> On Sun Sep 15 03:08:16 2013, glitchmr@myopera.com wrote:
>


> 1. I cannot reproduce the error you cite.  I cannot generate this error:
>  ""Bizarre copy of ARRAY in block exit".
>

  I can, with 5.14.2 and some rewriting of the code.

  I don't have a more recent version readily available, so it may well be
fixed now, but ... essentially it's the same as the OP reported, so here
goes:


2. Did you try running your program with 'use strict; use warnings;'?
> If so, you would have gotten messages that indicated problematic code.
>

  I did.  They went away once I declared @array and ... added some lvalue
(even read-only) to the if-branch ... perhaps 5.14.2 optimizes differently?


3. Did you try rewriting your program to name the subroutine something
> other than 'array'?  That only made for a more confusing bug report.
>
> Once I started to debug this with steps 2 and 3 above, I found that I
> could get an executable (though not very useful) program  by simply
> placing '()' after the subroutine call.
>
> ##########
> $ cat 119797-lvalue.pl
> my @this = (1..5);
>
> (that()) = ();
> print "@this\n";
>
> sub that :lvalue { if (@this) { } else { @this; } }
> ##########
> $ perl 119797-lvalue.pl
> 1 2 3 4 5
> ##########
>
> I don't think there is a bug here.
>

  Your rewrite gets two things wrong:

  First, to trigger the bug, the else-branch must be taken, so @this should
be empty or the conditional changed.

  Second, your need for the '()' stems from declaring &that after using it
... ;-)

  Additionally, I added a (read-only) lvalue to the if-branch, to avoid
perl 5.14.2 going down a different internal path ...

##########
use strict;
use warnings;

my @this;

sub that :lvalue { if (@this) { $& } else { @this; } }

(that) = ();
print "@this\n";
##########
perl /home/eirik/tmp/kladd.pl
Bizarre copy of ARRAY in block exit at /home/eirik/tmp/kladd.pl line 6.
##########


Eirik

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About