Make parser_free() be called slightly later,
[p5sagit/p5-mst-13.2.git] / toke.c
diff --git a/toke.c b/toke.c
index 96b33cb..d11cdcc 100644 (file)
--- 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);
@@ -655,6 +657,7 @@ Perl_lex_start(pTHX_ SV *line)
        }
     }
     SAVEI32(PL_curforce);
+    PL_curforce = -1;
 #else
     if (PL_lex_state == LEX_KNOWNEXT) {
        I32 toke = PL_nexttoke;
@@ -712,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
@@ -12222,7 +12239,7 @@ Perl_scan_num(pTHX_ const char *start, YYSTYPE* lvalp)
     case 'v':
 vstring:
                sv = newSV(5); /* preallocate storage space */
-               s = scan_vstring(s,sv);
+               s = scan_vstring(s, PL_bufend, sv);
        break;
     }
 
@@ -12704,28 +12721,29 @@ vstring, as well as updating the passed in sv.
 Function must be called like
 
        sv = newSV(5);
-       s = scan_vstring(s,sv);
+       s = scan_vstring(s,e,sv);
 
+where s and e are the start and end of the string.
 The sv should already be large enough to store the vstring
 passed in, for performance reasons.
 
 */
 
 char *
-Perl_scan_vstring(pTHX_ const char *s, SV *sv)
+Perl_scan_vstring(pTHX_ const char *s, const char *e, SV *sv)
 {
     dVAR;
     const char *pos = s;
     const char *start = s;
     if (*pos == 'v') pos++;  /* get past 'v' */
-    while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
+    while (pos < e && (isDIGIT(*pos) || *pos == '_'))
        pos++;
     if ( *pos != '.') {
        /* this may not be a v-string if followed by => */
        const char *next = pos;
-       while (next < PL_bufend && isSPACE(*next))
+       while (next < e && isSPACE(*next))
            ++next;
-       if ((PL_bufend - next) >= 2 && *next == '=' && next[1] == '>' ) {
+       if ((e - next) >= 2 && *next == '=' && next[1] == '>' ) {
            /* return string not v-string */
            sv_setpvn(sv,(char *)s,pos-s);
            return (char *)pos;
@@ -12765,13 +12783,13 @@ Perl_scan_vstring(pTHX_ const char *s, SV *sv)
            sv_catpvn(sv, (const char*)tmpbuf, tmpend - tmpbuf);
            if (!UNI_IS_INVARIANT(NATIVE_TO_UNI(rev)))
                 SvUTF8_on(sv);
-           if (pos + 1 < PL_bufend && *pos == '.' && isDIGIT(pos[1]))
+           if (pos + 1 < e && *pos == '.' && isDIGIT(pos[1]))
                 s = ++pos;
            else {
                 s = pos;
                 break;
            }
-           while (pos < PL_bufend && (isDIGIT(*pos) || *pos == '_'))
+           while (pos < e && (isDIGIT(*pos) || *pos == '_'))
                 pos++;
        }
        SvPOK_on(sv);