develooper Front page | perl.perl5.porters | Postings from October 2005

Re: [PATCH] Re: [perl #37350] $#{@$aref} in debugger gives: Bizarre copy of ARRAY in leave

Thread Previous | Thread Next
From:
Yitzchak Scott-Thoennes
Date:
October 12, 2005 15:34
Subject:
Re: [PATCH] Re: [perl #37350] $#{@$aref} in debugger gives: Bizarre copy of ARRAY in leave
Message ID:
20051012223345.GA3920@efn.org
On Wed, Oct 12, 2005 at 12:42:14PM +0100, Dave Mitchell wrote:
> On Wed, Oct 12, 2005 at 02:18:12AM -0700, Yitzchak Scott-Thoennes wrote:
> > I think the problem is that that the first executed (of two) rv2av is
> > getting the OPf_REF flag set, when IMO it shouldn't.  $#{@x} *is*
> > valid syntax; it should return $# of the array symbolically referred
> > to by @x, like this:
> > 
> > $ perl -we'*1 = [qw/foo bar baz/]; @x=0; print $#{0+@x}'
> > 2
> > 
> > only without the 0+ being there.  (If @x is lexical, then it's padav
> > that has the troublesome OPf_REF.)
> 
> It's because Perl_ref() recursively sets the OPf_REF flag in the following
> in perly.y:
> 
> 	|	arylen 	%prec '('                    /* $#x, $#{ something } */
> 			{ $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
> 
> That particuar problem can be fixed by replacing the call to ref() above
> with a direct $1->op_flags |= OPf_REF, but that doesn't solve the more
> general problem with things like push @{@a}, ...., which also gets the
> recursive Perl_ref() treatment. Possibly it can be fixed in Perl_ref()?

I think it needs to be recursive, even there, because IMO this should
continue to autovivify:

$ perl -we'$#{$x}=3; print $x'
ARRAY(0x460f10)

The solution I'm thinking of would require another parameter to Perl_ref
to say whether it should set OPf_REF for PADAV, PADHV, RV2AV, and RV2HV.
All external calls would set it to true, and recursive calls would
propagate it, except for OP_SCOPE and OP_LEAVE, which would set it false.

Does that sound like the right effect?  Can you think of anything that
would break?  Can you think of a way to do it without adding a parameter?

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