Front page | perl.perl5.porters |
Postings from August 2012
[perl #43425] local $[
Thread Next
From:
Father Chrysostomos via RT
Date:
August 6, 2012 13:54
Subject:
[perl #43425] local $[
Message ID:
rt-3.6.HEAD-11172-1344286487-1053.43425-14-0@perl.org
On Mon Jul 16 07:14:54 2007, davem wrote:
> On Fri, Jul 13, 2007 at 08:00:58AM +0200, Rafael Garcia-Suarez wrote:
> > On 13/07/07, Dave Mitchell <davem@iabyn.com> wrote:
> > >Prior to #22306, the savestack was popped at the end of each block
> or sub
> > >during compilation.
> > >To fix assorted nastiness associated with yyparse() error recovery
> (where
> > >it pops states off the stack until it reaches a statement boundary)
> -
> > >mainly that PL_comppad gets out of sync - I changed things in
> #22306 to pop
> > >the save stack at every statement boundary instead (roughly
> speaking).
> > >
> > >This, as has been seen, has the side effect of wiping out the
> compile-time
> > >effect of 'local $[' too soon - at the statement boundary rather
> than the
> > >block boundary. I think Father Chrysostomos's fix is a bit hacky;
> i.e.
> > >skipping popping the stack at a statement boundary if it has a
> > >SAVEt_COP_ARYBASE on it.
> > >
> > >I think a better fix would be: back out my #22306, thus fixing the
> local
> > >$[ issue, then put in a better fix for error recovery. Since
> perly.c is
> > >now freely editable rather than being auto-generated, this becomes
> > >trivial. I just add the current PL_savestack_ix as extra field to
> each
> > >pushed state, and the code that pops states during error recovery
> also
> > >does an appropriate LEAVE_SCOPE() at the same time.
> > >
> > >Would you prefer me to leave this till after 5.10?
> >
> > No, your analysis sounds good, go ahead.
>
> Change 31615 by davem@davem-pigeon on 2007/07/16 13:15:37
>
> [perl #43425] local $[: fix scoping during parser error
> handling.
>
> Change 22306# inadvertently made 'local $[' statement-scoped
> rather than block-scoped; so revert that change and add a
> different fix. The problem was to ensure that the savestack
> got
> popped correctly while popping errored tokens. We how record
> the
> current value of PL_savestack_ix with each pushed parser
> state.
>
> Note that due to later improvements I made to error handling - mainly
> recording the current value of PL_comppad with each pushed parser
> state, I
> couldn't reproduce the original faults after backing out change
> #22306.
> These faults were due to the failure to do a LEAVE_SCOPE(), meaning
> that
> PL_comppad wasn't getting correctly restored. But even if PL_comppad
> is
> now automatically handled, its still good to ensure that the savestack
> gets correctly popped during error recovery.
Five years later, I notice that under the new slab allocator this causes
the CV owning an op to be freed when that op is on the PL_nextval stack.
This happens in these cases:
format =
@
"${ use
strict }"
.
format =
@
use; format
strict
.
format =
@
;use
strict
.
In each of these cases it is the line containing ‘strict’ that is being
interpreted as a format picture line and being fed through force_next by
S_scan_formline.
Then the error condition kicks in after the force, causing a LEAVE_SCOPE
which frees the sub owning the const op for the format picture. Then a
token with a freed op is fed to the parser.
The first example above is plainly a bug; lex_formbrack is not being
localised at the same time as lex_brackets (when "..." is entered), so
the lexer thinks it’s not inside brackets inside the format. Localising
it will fix that case.
In the second and third examples, I think it’s a bug that code can ‘leak
out’ of the formline and start a new statement due to the semicolon. I
could fix that by wrapping the argument line of the format in do{...}
automatically.
But are there any other cases in which a forced token can be on the
PL_nextval stack when an error occurs that frees PL_compcv?
Should we remove the savestack handling, which you say is not strictly
necessary?
--
Father Chrysostomos
Thread Next
-
[perl #43425] local $[
by Father Chrysostomos via RT