summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldo.c7
-rw-r--r--lgc.c10
-rw-r--r--llex.c129
-rw-r--r--llex.h5
-rw-r--r--llimits.h8
-rw-r--r--lobject.c11
-rw-r--r--lobject.h4
-rw-r--r--lparser.c5
-rw-r--r--lparser.h4
-rw-r--r--lstate.c7
-rw-r--r--lstate.h6
-rw-r--r--lundump.c4
-rw-r--r--lvm.c4
-rw-r--r--lzio.c15
-rw-r--r--lzio.h27
15 files changed, 136 insertions, 110 deletions
diff --git a/ldo.c b/ldo.c
index a0772421..27688d2d 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.193 2002/08/30 19:09:21 roberto Exp roberto $ 2** $Id: ldo.c,v 1.194 2002/09/02 20:00:41 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -420,12 +420,13 @@ int luaD_pcall (lua_State *L, int nargs, int nresults, ptrdiff_t errfunc) {
420*/ 420*/
421struct SParser { /* data to `f_parser' */ 421struct SParser { /* data to `f_parser' */
422 ZIO *z; 422 ZIO *z;
423 Mbuffer buff; /* buffer to be used by the scanner */
423 int bin; 424 int bin;
424}; 425};
425 426
426static void f_parser (lua_State *L, void *ud) { 427static void f_parser (lua_State *L, void *ud) {
427 struct SParser *p = cast(struct SParser *, ud); 428 struct SParser *p = cast(struct SParser *, ud);
428 Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); 429 Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z, &p->buff);
429 Closure *cl = luaF_newLclosure(L, 0, gt(L)); 430 Closure *cl = luaF_newLclosure(L, 0, gt(L));
430 cl->l.p = tf; 431 cl->l.p = tf;
431 setclvalue(L->top, cl); 432 setclvalue(L->top, cl);
@@ -439,11 +440,13 @@ int luaD_protectedparser (lua_State *L, ZIO *z, int bin) {
439 int status; 440 int status;
440 ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */ 441 ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */
441 p.z = z; p.bin = bin; 442 p.z = z; p.bin = bin;
443 luaZ_initbuffer(L, &p.buff);
442 /* before parsing, give a (good) chance to GC */ 444 /* before parsing, give a (good) chance to GC */
443 if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold) 445 if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold)
444 luaC_collectgarbage(L); 446 luaC_collectgarbage(L);
445 old_blocks = G(L)->nblocks; 447 old_blocks = G(L)->nblocks;
446 status = luaD_rawrunprotected(L, f_parser, &p); 448 status = luaD_rawrunprotected(L, f_parser, &p);
449 luaZ_freebuffer(L, &p.buff);
447 if (status == 0) { 450 if (status == 0) {
448 /* add new memory to threshold (as it probably will stay) */ 451 /* add new memory to threshold (as it probably will stay) */
449 lua_assert(G(L)->nblocks >= old_blocks); 452 lua_assert(G(L)->nblocks >= old_blocks);
diff --git a/lgc.c b/lgc.c
index afaba8c2..d23e7a02 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.150 2002/09/05 19:57:40 roberto Exp roberto $ 2** $Id: lgc.c,v 1.151 2002/09/19 19:54:22 roberto Exp roberto $
3** Garbage Collector 3** Garbage Collector
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -332,17 +332,15 @@ static void sweepstrings (lua_State *L, int all) {
332} 332}
333 333
334 334
335#define MINBUFFER 256
336static void checkSizes (lua_State *L) { 335static void checkSizes (lua_State *L) {
337 /* check size of string hash */ 336 /* check size of string hash */
338 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) && 337 if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
339 G(L)->strt.size > MINSTRTABSIZE*2) 338 G(L)->strt.size > MINSTRTABSIZE*2)
340 luaS_resize(L, G(L)->strt.size/2); /* table is too big */ 339 luaS_resize(L, G(L)->strt.size/2); /* table is too big */
341 /* check size of buffer */ 340 /* check size of buffer */
342 if (G(L)->Mbuffsize > MINBUFFER*2) { /* is buffer too big? */ 341 if (luaZ_sizebuffer(&G(L)->buff) > LUA_MINBUFFER*2) { /* buffer too big? */
343 size_t newsize = G(L)->Mbuffsize/2; /* still larger than MINBUFFER */ 342 size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
344 luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, newsize, char); 343 luaZ_resizebuffer(L, &G(L)->buff, newsize);
345 G(L)->Mbuffsize = newsize;
346 } 344 }
347} 345}
348 346
diff --git a/llex.c b/llex.c
index 83ac742d..b2560fbd 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 1.111 2002/09/05 19:45:42 roberto Exp roberto $ 2** $Id: llex.c,v 1.112 2002/09/19 13:03:53 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -100,7 +100,7 @@ static void luaX_lexerror (LexState *ls, const char *s, int token) {
100 if (token == TK_EOS) 100 if (token == TK_EOS)
101 luaX_error(ls, s, luaX_token2str(ls, token)); 101 luaX_error(ls, s, luaX_token2str(ls, token));
102 else 102 else
103 luaX_error(ls, s, cast(char *, G(ls->L)->Mbuffer)); 103 luaX_error(ls, s, luaZ_buffer(ls->buff));
104} 104}
105 105
106 106
@@ -138,146 +138,143 @@ void luaX_setinput (lua_State *L, LexState *LS, ZIO *z, TString *source) {
138 138
139/* use Mbuffer to store names, literal strings and numbers */ 139/* use Mbuffer to store names, literal strings and numbers */
140 140
141#define EXTRABUFF 128 141#define EXTRABUFF 32
142#define checkbuffer(L, len) \ 142#define checkbuffer(LS, len) \
143 if (((len)+10)*sizeof(char) > G(L)->Mbuffsize) \ 143 if (((len)+3)*sizeof(char) > luaZ_sizebuffer((LS)->buff)) \
144 luaO_openspace(L, (len)+EXTRABUFF) 144 luaZ_openspace((LS)->L, (LS)->buff, (len)+EXTRABUFF)
145 145
146#define save(L, c, l) (cast(char *, G(L)->Mbuffer)[l++] = cast(char, c)) 146#define save(LS, c, l) \
147#define save_and_next(L, LS, l) (save(L, LS->current, l), next(LS)) 147 (cast(char *, luaZ_buffer((LS)->buff))[l++] = cast(char, c))
148#define save_and_next(LS, l) (save(LS, LS->current, l), next(LS))
148 149
149 150
150static size_t readname (LexState *LS) { 151static size_t readname (LexState *LS) {
151 lua_State *L = LS->L;
152 size_t l = 0; 152 size_t l = 0;
153 checkbuffer(L, l); 153 checkbuffer(LS, l);
154 do { 154 do {
155 checkbuffer(L, l); 155 checkbuffer(LS, l);
156 save_and_next(L, LS, l); 156 save_and_next(LS, l);
157 } while (isalnum(LS->current) || LS->current == '_'); 157 } while (isalnum(LS->current) || LS->current == '_');
158 save(L, '\0', l); 158 save(LS, '\0', l);
159 return l-1; 159 return l-1;
160} 160}
161 161
162 162
163/* LUA_NUMBER */ 163/* LUA_NUMBER */
164static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) { 164static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) {
165 lua_State *L = LS->L;
166 size_t l = 0; 165 size_t l = 0;
167 checkbuffer(L, l); 166 checkbuffer(LS, l);
168 if (comma) save(L, '.', l); 167 if (comma) save(LS, '.', l);
169 while (isdigit(LS->current)) { 168 while (isdigit(LS->current)) {
170 checkbuffer(L, l); 169 checkbuffer(LS, l);
171 save_and_next(L, LS, l); 170 save_and_next(LS, l);
172 } 171 }
173 if (LS->current == '.') { 172 if (LS->current == '.') {
174 save_and_next(L, LS, l); 173 save_and_next(LS, l);
175 if (LS->current == '.') { 174 if (LS->current == '.') {
176 save_and_next(L, LS, l); 175 save_and_next(LS, l);
177 save(L, '\0', l); 176 save(LS, '\0', l);
178 luaX_lexerror(LS, 177 luaX_lexerror(LS,
179 "ambiguous syntax (decimal point x string concatenation)", 178 "ambiguous syntax (decimal point x string concatenation)",
180 TK_NUMBER); 179 TK_NUMBER);
181 } 180 }
182 } 181 }
183 while (isdigit(LS->current)) { 182 while (isdigit(LS->current)) {
184 checkbuffer(L, l); 183 checkbuffer(LS, l);
185 save_and_next(L, LS, l); 184 save_and_next(LS, l);
186 } 185 }
187 if (LS->current == 'e' || LS->current == 'E') { 186 if (LS->current == 'e' || LS->current == 'E') {
188 save_and_next(L, LS, l); /* read `E' */ 187 save_and_next(LS, l); /* read `E' */
189 if (LS->current == '+' || LS->current == '-') 188 if (LS->current == '+' || LS->current == '-')
190 save_and_next(L, LS, l); /* optional exponent sign */ 189 save_and_next(LS, l); /* optional exponent sign */
191 while (isdigit(LS->current)) { 190 while (isdigit(LS->current)) {
192 checkbuffer(L, l); 191 checkbuffer(LS, l);
193 save_and_next(L, LS, l); 192 save_and_next(LS, l);
194 } 193 }
195 } 194 }
196 save(L, '\0', l); 195 save(LS, '\0', l);
197 if (!luaO_str2d(cast(char *, G(L)->Mbuffer), &seminfo->r)) 196 if (!luaO_str2d(cast(char *, luaZ_buffer(LS->buff)), &seminfo->r))
198 luaX_lexerror(LS, "malformed number", TK_NUMBER); 197 luaX_lexerror(LS, "malformed number", TK_NUMBER);
199} 198}
200 199
201 200
202static void read_long_string (LexState *LS, SemInfo *seminfo) { 201static void read_long_string (LexState *LS, SemInfo *seminfo) {
203 lua_State *L = LS->L;
204 int cont = 0; 202 int cont = 0;
205 size_t l = 0; 203 size_t l = 0;
206 checkbuffer(L, l); 204 checkbuffer(LS, l);
207 save(L, '[', l); /* save first `[' */ 205 save(LS, '[', l); /* save first `[' */
208 save_and_next(L, LS, l); /* pass the second `[' */ 206 save_and_next(LS, l); /* pass the second `[' */
209 if (LS->current == '\n') /* string starts with a newline? */ 207 if (LS->current == '\n') /* string starts with a newline? */
210 inclinenumber(LS); /* skip it */ 208 inclinenumber(LS); /* skip it */
211 for (;;) { 209 for (;;) {
212 checkbuffer(L, l); 210 checkbuffer(LS, l);
213 switch (LS->current) { 211 switch (LS->current) {
214 case EOZ: 212 case EOZ:
215 save(L, '\0', l); 213 save(LS, '\0', l);
216 luaX_lexerror(LS, (seminfo) ? "unfinished long string" : 214 luaX_lexerror(LS, (seminfo) ? "unfinished long string" :
217 "unfinished long comment", TK_EOS); 215 "unfinished long comment", TK_EOS);
218 break; /* to avoid warnings */ 216 break; /* to avoid warnings */
219 case '[': 217 case '[':
220 save_and_next(L, LS, l); 218 save_and_next(LS, l);
221 if (LS->current == '[') { 219 if (LS->current == '[') {
222 cont++; 220 cont++;
223 save_and_next(L, LS, l); 221 save_and_next(LS, l);
224 } 222 }
225 continue; 223 continue;
226 case ']': 224 case ']':
227 save_and_next(L, LS, l); 225 save_and_next(LS, l);
228 if (LS->current == ']') { 226 if (LS->current == ']') {
229 if (cont == 0) goto endloop; 227 if (cont == 0) goto endloop;
230 cont--; 228 cont--;
231 save_and_next(L, LS, l); 229 save_and_next(LS, l);
232 } 230 }
233 continue; 231 continue;
234 case '\n': 232 case '\n':
235 save(L, '\n', l); 233 save(LS, '\n', l);
236 inclinenumber(LS); 234 inclinenumber(LS);
237 if (!seminfo) l = 0; /* reset buffer to avoid wasting space */ 235 if (!seminfo) l = 0; /* reset buffer to avoid wasting space */
238 continue; 236 continue;
239 default: 237 default:
240 save_and_next(L, LS, l); 238 save_and_next(LS, l);
241 } 239 }
242 } endloop: 240 } endloop:
243 save_and_next(L, LS, l); /* skip the second `]' */ 241 save_and_next(LS, l); /* skip the second `]' */
244 save(L, '\0', l); 242 save(LS, '\0', l);
245 if (seminfo) 243 if (seminfo)
246 seminfo->ts = luaS_newlstr(L, cast(char *, G(L)->Mbuffer)+2, l-5); 244 seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 2, l - 5);
247} 245}
248 246
249 247
250static void read_string (LexState *LS, int del, SemInfo *seminfo) { 248static void read_string (LexState *LS, int del, SemInfo *seminfo) {
251 lua_State *L = LS->L;
252 size_t l = 0; 249 size_t l = 0;
253 checkbuffer(L, l); 250 checkbuffer(LS, l);
254 save_and_next(L, LS, l); 251 save_and_next(LS, l);
255 while (LS->current != del) { 252 while (LS->current != del) {
256 checkbuffer(L, l); 253 checkbuffer(LS, l);
257 switch (LS->current) { 254 switch (LS->current) {
258 case EOZ: 255 case EOZ:
259 save(L, '\0', l); 256 save(LS, '\0', l);
260 luaX_lexerror(LS, "unfinished string", TK_EOS); 257 luaX_lexerror(LS, "unfinished string", TK_EOS);
261 break; /* to avoid warnings */ 258 break; /* to avoid warnings */
262 case '\n': 259 case '\n':
263 save(L, '\0', l); 260 save(LS, '\0', l);
264 luaX_lexerror(LS, "unfinished string", TK_STRING); 261 luaX_lexerror(LS, "unfinished string", TK_STRING);
265 break; /* to avoid warnings */ 262 break; /* to avoid warnings */
266 case '\\': 263 case '\\':
267 next(LS); /* do not save the `\' */ 264 next(LS); /* do not save the `\' */
268 switch (LS->current) { 265 switch (LS->current) {
269 case 'a': save(L, '\a', l); next(LS); break; 266 case 'a': save(LS, '\a', l); next(LS); break;
270 case 'b': save(L, '\b', l); next(LS); break; 267 case 'b': save(LS, '\b', l); next(LS); break;
271 case 'f': save(L, '\f', l); next(LS); break; 268 case 'f': save(LS, '\f', l); next(LS); break;
272 case 'n': save(L, '\n', l); next(LS); break; 269 case 'n': save(LS, '\n', l); next(LS); break;
273 case 'r': save(L, '\r', l); next(LS); break; 270 case 'r': save(LS, '\r', l); next(LS); break;
274 case 't': save(L, '\t', l); next(LS); break; 271 case 't': save(LS, '\t', l); next(LS); break;
275 case 'v': save(L, '\v', l); next(LS); break; 272 case 'v': save(LS, '\v', l); next(LS); break;
276 case '\n': save(L, '\n', l); inclinenumber(LS); break; 273 case '\n': save(LS, '\n', l); inclinenumber(LS); break;
277 case EOZ: break; /* will raise an error next loop */ 274 case EOZ: break; /* will raise an error next loop */
278 default: { 275 default: {
279 if (!isdigit(LS->current)) 276 if (!isdigit(LS->current))
280 save_and_next(L, LS, l); /* handles \\, \", \', and \? */ 277 save_and_next(LS, l); /* handles \\, \", \', and \? */
281 else { /* \xxx */ 278 else { /* \xxx */
282 int c = 0; 279 int c = 0;
283 int i = 0; 280 int i = 0;
@@ -286,21 +283,21 @@ static void read_string (LexState *LS, int del, SemInfo *seminfo) {
286 next(LS); 283 next(LS);
287 } while (++i<3 && isdigit(LS->current)); 284 } while (++i<3 && isdigit(LS->current));
288 if (c > UCHAR_MAX) { 285 if (c > UCHAR_MAX) {
289 save(L, '\0', l); 286 save(LS, '\0', l);
290 luaX_lexerror(LS, "escape sequence too large", TK_STRING); 287 luaX_lexerror(LS, "escape sequence too large", TK_STRING);
291 } 288 }
292 save(L, c, l); 289 save(LS, c, l);
293 } 290 }
294 } 291 }
295 } 292 }
296 break; 293 break;
297 default: 294 default:
298 save_and_next(L, LS, l); 295 save_and_next(LS, l);
299 } 296 }
300 } 297 }
301 save_and_next(L, LS, l); /* skip delimiter */ 298 save_and_next(LS, l); /* skip delimiter */
302 save(L, '\0', l); 299 save(LS, '\0', l);
303 seminfo->ts = luaS_newlstr(L, cast(char *, G(L)->Mbuffer)+1, l-3); 300 seminfo->ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff) + 1, l - 3);
304} 301}
305 302
306 303
@@ -388,7 +385,7 @@ int luaX_lex (LexState *LS, SemInfo *seminfo) {
388 else if (isalpha(LS->current) || LS->current == '_') { 385 else if (isalpha(LS->current) || LS->current == '_') {
389 /* identifier or reserved word */ 386 /* identifier or reserved word */
390 size_t l = readname(LS); 387 size_t l = readname(LS);
391 TString *ts = luaS_newlstr(LS->L, cast(char *, G(LS->L)->Mbuffer), l); 388 TString *ts = luaS_newlstr(LS->L, luaZ_buffer(LS->buff), l);
392 if (ts->tsv.reserved > 0) /* reserved word? */ 389 if (ts->tsv.reserved > 0) /* reserved word? */
393 return ts->tsv.reserved - 1 + FIRST_RESERVED; 390 return ts->tsv.reserved - 1 + FIRST_RESERVED;
394 seminfo->ts = ts; 391 seminfo->ts = ts;
diff --git a/llex.h b/llex.h
index 514d5bbc..d0e4216c 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.43 2002/05/07 17:36:56 roberto Exp roberto $ 2** $Id: llex.h,v 1.44 2002/09/03 11:57:38 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -56,7 +56,8 @@ typedef struct LexState {
56 Token lookahead; /* look ahead token */ 56 Token lookahead; /* look ahead token */
57 struct FuncState *fs; /* `FuncState' is private to the parser */ 57 struct FuncState *fs; /* `FuncState' is private to the parser */
58 struct lua_State *L; 58 struct lua_State *L;
59 struct zio *z; /* input stream */ 59 ZIO *z; /* input stream */
60 Mbuffer *buff; /* buffer for tokens */
60 TString *source; /* current source name */ 61 TString *source; /* current source name */
61} LexState; 62} LexState;
62 63
diff --git a/llimits.h b/llimits.h
index ca7dce5e..9acea06d 100644
--- a/llimits.h
+++ b/llimits.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llimits.h,v 1.44 2002/06/13 13:45:31 roberto Exp roberto $ 2** $Id: llimits.h,v 1.45 2002/07/08 20:22:08 roberto Exp roberto $
3** Limits, basic types, and some other `installation-dependent' definitions 3** Limits, basic types, and some other `installation-dependent' definitions
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -150,4 +150,10 @@ typedef unsigned long Instruction;
150#endif 150#endif
151 151
152 152
153/* minimum size for string buffer */
154#ifndef LUA_MINBUFFER
155#define LUA_MINBUFFER 32
156#endif
157
158
153#endif 159#endif
diff --git a/lobject.c b/lobject.c
index cdf49c92..bf6b4c00 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 1.88 2002/09/19 13:03:53 roberto Exp roberto $ 2** $Id: lobject.c,v 1.89 2002/10/04 14:31:03 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -73,15 +73,6 @@ int luaO_rawequalObj (const TObject *t1, const TObject *t2) {
73} 73}
74 74
75 75
76char *luaO_openspace (lua_State *L, size_t n) {
77 if (n > G(L)->Mbuffsize) {
78 luaM_reallocvector(L, G(L)->Mbuffer, G(L)->Mbuffsize, n, char);
79 G(L)->Mbuffsize = n;
80 }
81 return G(L)->Mbuffer;
82}
83
84
85int luaO_str2d (const char *s, lua_Number *result) { 76int luaO_str2d (const char *s, lua_Number *result) {
86 char *endptr; 77 char *endptr;
87 lua_Number res = lua_str2number(s, &endptr); 78 lua_Number res = lua_str2number(s, &endptr);
diff --git a/lobject.h b/lobject.h
index d9a5c242..c872ecc9 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 1.145 2002/09/02 19:54:49 roberto Exp roberto $ 2** $Id: lobject.h,v 1.146 2002/09/19 13:03:53 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -316,8 +316,6 @@ extern const TObject luaO_nilobject;
316int luaO_log2 (unsigned int x); 316int luaO_log2 (unsigned int x);
317 317
318 318
319char *luaO_openspace (lua_State *L, size_t n);
320
321int luaO_rawequalObj (const TObject *t1, const TObject *t2); 319int luaO_rawequalObj (const TObject *t1, const TObject *t2);
322int luaO_str2d (const char *s, lua_Number *result); 320int luaO_str2d (const char *s, lua_Number *result);
323 321
diff --git a/lparser.c b/lparser.c
index e5dc2054..1009f87b 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 1.193 2002/08/22 19:51:08 roberto Exp roberto $ 2** $Id: lparser.c,v 1.194 2002/08/30 19:09:21 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -351,9 +351,10 @@ static void close_func (LexState *ls) {
351} 351}
352 352
353 353
354Proto *luaY_parser (lua_State *L, ZIO *z) { 354Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff) {
355 struct LexState lexstate; 355 struct LexState lexstate;
356 struct FuncState funcstate; 356 struct FuncState funcstate;
357 lexstate.buff = buff;
357 luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z))); 358 luaX_setinput(L, &lexstate, z, luaS_new(L, zname(z)));
358 open_func(&lexstate, &funcstate); 359 open_func(&lexstate, &funcstate);
359 next(&lexstate); /* read first token */ 360 next(&lexstate); /* read first token */
diff --git a/lparser.h b/lparser.h
index 2b9c64d4..011c59fe 100644
--- a/lparser.h
+++ b/lparser.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.h,v 1.43 2002/05/10 19:22:11 roberto Exp roberto $ 2** $Id: lparser.h,v 1.44 2002/05/14 17:52:22 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -65,7 +65,7 @@ typedef struct FuncState {
65} FuncState; 65} FuncState;
66 66
67 67
68Proto *luaY_parser (lua_State *L, ZIO *z); 68Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff);
69 69
70 70
71#endif 71#endif
diff --git a/lstate.c b/lstate.c
index a2334cca..a8136d1a 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.104 2002/08/16 20:00:28 roberto Exp roberto $ 2** $Id: lstate.c,v 1.105 2002/08/30 19:09:21 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -61,8 +61,7 @@ static void f_luaopen (lua_State *L, void *ud) {
61 G(L)->strt.size = 0; 61 G(L)->strt.size = 0;
62 G(L)->strt.nuse = 0; 62 G(L)->strt.nuse = 0;
63 G(L)->strt.hash = NULL; 63 G(L)->strt.hash = NULL;
64 G(L)->Mbuffer = NULL; 64 luaZ_initbuffer(L, &G(L)->buff);
65 G(L)->Mbuffsize = 0;
66 G(L)->panic = &default_panic; 65 G(L)->panic = &default_panic;
67 G(L)->rootgc = NULL; 66 G(L)->rootgc = NULL;
68 G(L)->rootudata = NULL; 67 G(L)->rootudata = NULL;
@@ -160,7 +159,7 @@ static void close_state (lua_State *L) {
160 lua_assert(G(L)->rootgc == NULL); 159 lua_assert(G(L)->rootgc == NULL);
161 lua_assert(G(L)->rootudata == NULL); 160 lua_assert(G(L)->rootudata == NULL);
162 luaS_freeall(L); 161 luaS_freeall(L);
163 luaM_freearray(L, G(L)->Mbuffer, G(L)->Mbuffsize, char); 162 luaZ_freebuffer(L, &G(L)->buff);
164 luaM_freelem(NULL, L->l_G); 163 luaM_freelem(NULL, L->l_G);
165 } 164 }
166 luaE_closethread(NULL, L); 165 luaE_closethread(NULL, L);
diff --git a/lstate.h b/lstate.h
index 618685c1..94af29ad 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.95 2002/08/30 19:09:21 roberto Exp roberto $ 2** $Id: lstate.h,v 1.96 2002/09/19 13:03:53 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -11,6 +11,7 @@
11 11
12#include "lobject.h" 12#include "lobject.h"
13#include "ltm.h" 13#include "ltm.h"
14#include "lzio.h"
14 15
15 16
16/* 17/*
@@ -124,8 +125,7 @@ typedef struct global_State {
124 GCObject *rootgc; /* list of (almost) all collectable objects */ 125 GCObject *rootgc; /* list of (almost) all collectable objects */
125 GCObject *rootudata; /* (separated) list of all userdata */ 126 GCObject *rootudata; /* (separated) list of all userdata */
126 GCObject *tmudata; /* list of userdata to be GC */ 127 GCObject *tmudata; /* list of userdata to be GC */
127 char *Mbuffer; /* global buffer */ 128 Mbuffer buff; /* temporary buffer for string concatentation */
128 size_t Mbuffsize; /* size of Mbuffer */
129 lu_mem GCthreshold; 129 lu_mem GCthreshold;
130 lu_mem nblocks; /* number of `bytes' currently allocated */ 130 lu_mem nblocks; /* number of `bytes' currently allocated */
131 lua_CFunction panic; /* to be called in unprotected errors */ 131 lua_CFunction panic; /* to be called in unprotected errors */
diff --git a/lundump.c b/lundump.c
index 6f2fa287..a555f97a 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 1.52 2002/08/12 13:37:19 roberto Exp roberto $ 2** $Id: lundump.c,v 1.53 2002/09/19 13:03:53 roberto Exp roberto $
3** load pre-compiled Lua chunks 3** load pre-compiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -99,7 +99,7 @@ static TString* LoadString (LoadState* S)
99 return NULL; 99 return NULL;
100 else 100 else
101 { 101 {
102 char* s=luaO_openspace(S->L,size); 102 char* s=luaZ_openspace(S->L,&G(S->L)->buff,size);
103 ezread(S,s,size); 103 ezread(S,s,size);
104 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ 104 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
105 } 105 }
diff --git a/lvm.c b/lvm.c
index 0279dbe7..68e6a080 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 1.255 2002/09/19 13:03:53 roberto Exp roberto $ 2** $Id: lvm.c,v 1.256 2002/09/19 20:12:47 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -303,7 +303,7 @@ void luaV_concat (lua_State *L, int total, int last) {
303 n++; 303 n++;
304 } 304 }
305 if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow"); 305 if (tl > MAX_SIZET) luaG_runerror(L, "string size overflow");
306 buffer = luaO_openspace(L, tl); 306 buffer = luaZ_openspace(L, &G(L)->buff, tl);
307 tl = 0; 307 tl = 0;
308 for (i=n; i>0; i--) { /* concat all strings */ 308 for (i=n; i>0; i--) { /* concat all strings */
309 size_t l = tsvalue(top-i)->tsv.len; 309 size_t l = tsvalue(top-i)->tsv.len;
diff --git a/lzio.c b/lzio.c
index 7ae7abb5..b22c4242 100644
--- a/lzio.c
+++ b/lzio.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.c,v 1.20 2002/08/05 18:45:02 roberto Exp roberto $ 2** $Id: lzio.c,v 1.21 2002/08/06 17:26:45 roberto Exp roberto $
3** a generic input stream interface 3** a generic input stream interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -10,10 +10,10 @@
10#include "lua.h" 10#include "lua.h"
11 11
12#include "llimits.h" 12#include "llimits.h"
13#include "lmem.h"
13#include "lzio.h" 14#include "lzio.h"
14 15
15 16
16
17int luaZ_fill (ZIO *z) { 17int luaZ_fill (ZIO *z) {
18 size_t size; 18 size_t size;
19 const char *buff = z->reader(NULL, z->data, &size); 19 const char *buff = z->reader(NULL, z->data, &size);
@@ -66,3 +66,14 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) {
66 return 0; 66 return 0;
67} 67}
68 68
69/* ------------------------------------------------------------------------ */
70char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
71 if (n > buff->buffsize) {
72 if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
73 luaM_reallocvector(L, buff->buffer, buff->buffsize, n, char);
74 buff->buffsize = n;
75 }
76 return buff->buffer;
77}
78
79
diff --git a/lzio.h b/lzio.h
index e7807ec3..f2fbad90 100644
--- a/lzio.h
+++ b/lzio.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lzio.h,v 1.12 2002/06/06 12:40:22 roberto Exp roberto $ 2** $Id: lzio.h,v 1.13 2002/08/05 18:45:02 roberto Exp roberto $
3** Buffered streams 3** Buffered streams
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -13,7 +13,7 @@
13 13
14#define EOZ (-1) /* end of stream */ 14#define EOZ (-1) /* end of stream */
15 15
16typedef struct zio ZIO; 16typedef struct Zio ZIO;
17 17
18#define zgetc(z) (((z)->n--)>0 ? \ 18#define zgetc(z) (((z)->n--)>0 ? \
19 cast(int, cast(unsigned char, *(z)->p++)) : \ 19 cast(int, cast(unsigned char, *(z)->p++)) : \
@@ -26,9 +26,30 @@ size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
26int luaZ_lookahead (ZIO *z); 26int luaZ_lookahead (ZIO *z);
27 27
28 28
29
30typedef struct Mbuffer {
31 char *buffer;
32 size_t buffsize;
33} Mbuffer;
34
35
36char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
37
38#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
39
40#define luaZ_sizebuffer(buff) ((buff)->buffsize)
41#define luaZ_buffer(buff) ((buff)->buffer)
42
43#define luaZ_resizebuffer(L, buff, size) \
44 (luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
45 (buff)->buffsize = size)
46
47#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
48
49
29/* --------- Private Part ------------------ */ 50/* --------- Private Part ------------------ */
30 51
31struct zio { 52struct Zio {
32 size_t n; /* bytes still unread */ 53 size_t n; /* bytes still unread */
33 const char *p; /* current position in buffer */ 54 const char *p; /* current position in buffer */
34 lua_Chunkreader reader; 55 lua_Chunkreader reader;