From: Dave Mitchell Date: Sun, 1 Apr 2007 01:27:57 +0000 (+0000) Subject: Make parser_free() be called slightly later, X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e3abe207f764929a97eafa503a3780d5b7636ed2;p=p5sagit%2Fp5-mst-13.2.git Make parser_free() be called slightly later, i.e. at the point where lexer vars are being restored in a LEAVE, rather than at the end of yyparse() p4raw-id: //depot/perl@30822 --- diff --git a/perly.c b/perly.c index c8ee62f..95779a0 100644 --- a/perly.c +++ b/perly.c @@ -306,20 +306,6 @@ S_clear_yystack(pTHX_ const yy_parser *parser) } } -/* delete a parser object */ - -#ifndef PERL_IN_MADLY_C -void -Perl_parser_free(pTHX_ const yy_parser *parser) -{ - S_clear_yystack(aTHX_ parser); - Safefree(parser->stack); - Safefree(parser->lex_brackstack); - Safefree(parser->lex_casestack); - PL_parser = parser->old_parser; - Safefree(parser); -} -#endif /*----------. | yyparse. | @@ -362,8 +348,8 @@ Perl_yyparse (pTHX) parser = PL_parser; ps = parser->ps; - ENTER; /* force parser free before we return */ - SAVEPARSER(parser); + ENTER; /* force parser stack cleanup before we return */ + SAVEDESTRUCTOR_X(S_clear_yystack, parser); /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | @@ -691,7 +677,7 @@ Perl_yyparse (pTHX) goto yyreturn; yyreturn: - LEAVE; /* force parser free before we return */ + LEAVE; /* force parser stack cleanup before we return */ return yyresult; } diff --git a/toke.c b/toke.c index a9e3d88..d11cdcc 100644 --- a/toke.c +++ b/toke.c @@ -615,8 +615,7 @@ S_cr_textfilter(pTHX_ int idx, SV *sv, int maxlen) /* * Perl_lex_start - * Initialize variables. Uses the Perl save_stack to save its state (for - * recursive calls to the parser). + * Create a parser object and initialise its parser and lexer fields */ void @@ -641,6 +640,9 @@ Perl_lex_start(pTHX_ SV *line) parser->yyerrstatus = 0; parser->yychar = YYEMPTY; /* Cause a token to be read. */ + /* on scope exit, free this parser and restore any outer one */ + SAVEPARSER(parser); + /* initialise lexer state */ SAVEI32(PL_lex_state); @@ -713,6 +715,20 @@ Perl_lex_start(pTHX_ SV *line) PL_rsfp = 0; } + +/* delete a parser object */ + +void +Perl_parser_free(pTHX_ const yy_parser *parser) +{ + Safefree(parser->stack); + Safefree(parser->lex_brackstack); + Safefree(parser->lex_casestack); + PL_parser = parser->old_parser; + Safefree(parser); +} + + /* * Perl_lex_end * Finalizer for lexing operations. Must be called when the parser is