develooper Front page | perl.perl5.porters | Postings from August 2008

[perl #38809][PATCH] loss of stack elements with a do block insidea return

Thread Next
From:
Vincent Pit
Date:
August 30, 2008 08:25
Subject:
[perl #38809][PATCH] loss of stack elements with a do block insidea return
Message ID:
48B9665E.7060402@profvince.com
This is the bug that makes

   sub foo { do { return do { 1; 2 } }; 3 }

returns undef. The 1 is here to prevent the return do block to be
optimized away, and the 3 to ensure that the first statement receives
void context. Concise says :

1  <;> nextstate(main 3 -e:1) v
2  <0> enter v
3  <;> nextstate(main 2 -e:1) v
4  <0> pushmark s
5  <0> enter
6  <;> nextstate(main 1 -e:1) v
7  <;> nextstate(main 1 -e:1) v
8  <$> const[IV 2] s
9  <@> leave KP
a  <@> return K
b  <@> leave vKP
c  <;> nextstate(main 3 -e:1) v
d  <$> const[IV 3] s
e  <1> leavesub[1 ref] K/REFC,1

The problem is that the enter after the pushmark has no context and
hence its associated leave won't drop its return value on the stack.

The patch attached is a way better solution compared to the previous one
I sent some months ago. In ck_return, it looks at the kids and force
list context on NULLs that have the OPf_SPECIAL flag set (which
corresponds to do { } blocks, op.h says). Maybe other kids could receive
the same treatment.

Vincent.

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