[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdev-ruby/gsoc] parser: Ruby lexer: increase the buffer size for heredoc strings and expressions in
From:       Alexander Dymo <adymo () kdevelop ! org>
Date:       2012-07-03 13:12:51
Message-ID: 20120703131251.53897A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 240f8ffd4c7a7ff4415dcb2d86e9d56624160b7c by Alexander Dymo.
Committed on 03/07/2012 at 15:11.
Pushed by dymo into branch 'gsoc'.

Ruby lexer: increase the buffer size for heredoc strings and expressions interpolated into strings.
That buffer is currently quite large (will hold approx 2k of unicode strings).

The real fix would be buffers that get increased in size dynamically (realloc)
similarly to how original ruby parser does.

M  +9    -5    parser/parser.y

http://commits.kde.org/kdev-ruby/240f8ffd4c7a7ff4415dcb2d86e9d56624160b7c

diff --git a/parser/parser.y b/parser/parser.y
index bb6a5c0..c846c37 100644
--- a/parser/parser.y
+++ b/parser/parser.y
@@ -34,8 +34,12 @@
 #include "parser.h"
 
 #define STACK_SIZE 128
-#define BSIZE STACK_SIZE
-
+/* buffer size for heredocs and code blocks inside strings
+   let's say it has place for about 2k lines of utf8-encoded
+   code for now */
+#define STRING_BSIZE 320000
+/* buffer size for other tokens that are not strings */
+#define TOK_BSIZE 128
 
 /* Flags used by the lexer */
 struct flags_t {
@@ -1697,7 +1701,7 @@ static int push_string_var(struct parser_t * p, int * curs, char ** ch, int oax)
   int diff = *curs - p->cursor - oax + 2;
   struct pos_t tp = { p->line, p->line, p->column + diff, -1, 0 };
   int possible_error = *curs + 1;
-  char buffer[BSIZE];
+  char buffer[STRING_BSIZE];
   char * ptr = buffer;
   int step = 0; /* How many bytes the actual utf8 character has */
   int ax = 0; /* Used to properly update the column when utf8 chars appear */
@@ -1731,7 +1735,7 @@ static int push_string_var(struct parser_t * p, int * curs, char ** ch, int oax)
 
 static int parse_heredoc(struct parser_t * p, char * c, int * curs)
 {
-  char buffer[BSIZE], aux[BSIZE];
+  char buffer[STRING_BSIZE], aux[STRING_BSIZE];
   unsigned char quote_seen = 0, term = ' ';
   unsigned char dash_seen = 0;
   int i, l = 0, spaces = 0;
@@ -2162,7 +2166,7 @@ static int parse_re_options(struct parser_t *p, char *c, int curs)
 static int parser_yylex(struct parser_t * parser)
 {
   int t = token_invalid;
-  char buffer[BSIZE];
+  char buffer[TOK_BSIZE];
   char * c;
   int curs, len;
   unsigned char space_seen = 0;

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic