diff options
Diffstat (limited to '')
-rw-r--r-- | llex.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -44,7 +44,7 @@ | |||
44 | /* ORDER RESERVED */ | 44 | /* ORDER RESERVED */ |
45 | static const char *const luaX_tokens [] = { | 45 | static const char *const luaX_tokens [] = { |
46 | "and", "break", "do", "else", "elseif", | 46 | "and", "break", "do", "else", "elseif", |
47 | "end", "false", "for", "function", "goto", "if", | 47 | "end", "false", "for", "function", "global", "goto", "if", |
48 | "in", "local", "nil", "not", "or", "repeat", | 48 | "in", "local", "nil", "not", "or", "repeat", |
49 | "return", "then", "true", "until", "while", | 49 | "return", "then", "true", "until", "while", |
50 | "//", "..", "...", "==", ">=", "<=", "~=", | 50 | "//", "..", "...", "==", ">=", "<=", "~=", |
@@ -62,10 +62,10 @@ static l_noret lexerror (LexState *ls, const char *msg, int token); | |||
62 | static void save (LexState *ls, int c) { | 62 | static void save (LexState *ls, int c) { |
63 | Mbuffer *b = ls->buff; | 63 | Mbuffer *b = ls->buff; |
64 | if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) { | 64 | if (luaZ_bufflen(b) + 1 > luaZ_sizebuffer(b)) { |
65 | size_t newsize; | 65 | size_t newsize = luaZ_sizebuffer(b); /* get old size */; |
66 | if (luaZ_sizebuffer(b) >= MAX_SIZE/2) | 66 | if (newsize >= (MAX_SIZE/3 * 2)) /* larger than MAX_SIZE/1.5 ? */ |
67 | lexerror(ls, "lexical element too long", 0); | 67 | lexerror(ls, "lexical element too long", 0); |
68 | newsize = luaZ_sizebuffer(b) * 2; | 68 | newsize += (newsize >> 1); /* new size is 1.5 times the old one */ |
69 | luaZ_resizebuffer(ls->L, b, newsize); | 69 | luaZ_resizebuffer(ls->L, b, newsize); |
70 | } | 70 | } |
71 | b->buffer[luaZ_bufflen(b)++] = cast_char(c); | 71 | b->buffer[luaZ_bufflen(b)++] = cast_char(c); |
@@ -184,7 +184,15 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source, | |||
184 | ls->linenumber = 1; | 184 | ls->linenumber = 1; |
185 | ls->lastline = 1; | 185 | ls->lastline = 1; |
186 | ls->source = source; | 186 | ls->source = source; |
187 | ls->envn = luaS_newliteral(L, LUA_ENV); /* get env name */ | 187 | /* all three strings here ("_ENV", "break", "global") were fixed, |
188 | so they cannot be collected */ | ||
189 | ls->envn = luaS_newliteral(L, LUA_ENV); /* get env string */ | ||
190 | ls->brkn = luaS_newliteral(L, "break"); /* get "break" string */ | ||
191 | #if defined(LUA_COMPAT_GLOBAL) | ||
192 | /* compatibility mode: "global" is not a reserved word */ | ||
193 | ls->glbn = luaS_newliteral(L, "global"); /* get "global" string */ | ||
194 | ls->glbn->extra = 0; /* mark it as not reserved */ | ||
195 | #endif | ||
188 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ | 196 | luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ |
189 | } | 197 | } |
190 | 198 | ||
@@ -354,12 +362,12 @@ static int readhexaesc (LexState *ls) { | |||
354 | ** for error reporting in case of errors; 'i' counts the number of | 362 | ** for error reporting in case of errors; 'i' counts the number of |
355 | ** saved characters, so that they can be removed if case of success. | 363 | ** saved characters, so that they can be removed if case of success. |
356 | */ | 364 | */ |
357 | static unsigned long readutf8esc (LexState *ls) { | 365 | static l_uint32 readutf8esc (LexState *ls) { |
358 | unsigned long r; | 366 | l_uint32 r; |
359 | int i = 4; /* number of chars to be removed: start with #"\u{X" */ | 367 | int i = 4; /* number of chars to be removed: start with #"\u{X" */ |
360 | save_and_next(ls); /* skip 'u' */ | 368 | save_and_next(ls); /* skip 'u' */ |
361 | esccheck(ls, ls->current == '{', "missing '{'"); | 369 | esccheck(ls, ls->current == '{', "missing '{'"); |
362 | r = cast_ulong(gethexa(ls)); /* must have at least one digit */ | 370 | r = cast_uint(gethexa(ls)); /* must have at least one digit */ |
363 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { | 371 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { |
364 | i++; | 372 | i++; |
365 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); | 373 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); |