diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-01-23 09:31:38 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2003-01-23 09:31:38 -0200 |
commit | e44e579dc19ec0060f5e84c7a692b5c1cff2eec3 (patch) | |
tree | aae4ceddfd208640dee81368c94903384d29e034 | |
parent | a153cafd8df6c3b6dfd13d3d99d7a39d912dc983 (diff) | |
download | lua-e44e579dc19ec0060f5e84c7a692b5c1cff2eec3.tar.gz lua-e44e579dc19ec0060f5e84c7a692b5c1cff2eec3.tar.bz2 lua-e44e579dc19ec0060f5e84c7a692b5c1cff2eec3.zip |
bug: luaD_protectedparser must protect its garbage collection too
-rw-r--r-- | bugs | 6 | ||||
-rw-r--r-- | ldo.c | 29 |
2 files changed, 20 insertions, 15 deletions
@@ -313,3 +313,9 @@ Fri Dec 20 09:53:19 UTC 2002 | |||
313 | >> `resume' was checking the wrong value for stack overflow | 313 | >> `resume' was checking the wrong value for stack overflow |
314 | (by Maik Zimmermann; since 5.0b) | 314 | (by Maik Zimmermann; since 5.0b) |
315 | 315 | ||
316 | ** ldo.c | ||
317 | Thu Jan 23 11:29:06 UTC 2003 | ||
318 | >> error during garbage collection in luaD_protectedparser is not being | ||
319 | >> protected | ||
320 | (by Benoit Germain; since 5.0a) | ||
321 | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.210 2002/12/04 17:28:27 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.211 2002/12/04 17:38:31 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 | */ |
@@ -415,35 +415,34 @@ struct SParser { /* data to `f_parser' */ | |||
415 | }; | 415 | }; |
416 | 416 | ||
417 | static void f_parser (lua_State *L, void *ud) { | 417 | static void f_parser (lua_State *L, void *ud) { |
418 | lu_mem old_blocks; | ||
419 | Proto *tf; | ||
420 | Closure *cl; | ||
418 | struct SParser *p = cast(struct SParser *, ud); | 421 | struct SParser *p = cast(struct SParser *, ud); |
419 | Proto *tf = p->bin ? luaU_undump(L, p->z, &p->buff) : | 422 | /* before parsing, give a (good) chance to GC */ |
420 | luaY_parser(L, p->z, &p->buff); | 423 | if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold) |
421 | Closure *cl = luaF_newLclosure(L, 0, gt(L)); | 424 | luaC_collectgarbage(L); |
425 | old_blocks = G(L)->nblocks; | ||
426 | tf = p->bin ? luaU_undump(L, p->z, &p->buff) : luaY_parser(L, p->z, &p->buff); | ||
427 | cl = luaF_newLclosure(L, 0, gt(L)); | ||
422 | cl->l.p = tf; | 428 | cl->l.p = tf; |
423 | setclvalue(L->top, cl); | 429 | setclvalue(L->top, cl); |
424 | incr_top(L); | 430 | incr_top(L); |
431 | /* add new memory to threshold (as it probably will stay) */ | ||
432 | lua_assert(G(L)->nblocks >= old_blocks); | ||
433 | G(L)->GCthreshold += (G(L)->nblocks - old_blocks); | ||
425 | } | 434 | } |
426 | 435 | ||
427 | 436 | ||
428 | int luaD_protectedparser (lua_State *L, ZIO *z, int bin) { | 437 | int luaD_protectedparser (lua_State *L, ZIO *z, int bin) { |
429 | struct SParser p; | 438 | struct SParser p; |
430 | lu_mem old_blocks; | ||
431 | int status; | 439 | int status; |
432 | ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */ | 440 | ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */ |
433 | p.z = z; p.bin = bin; | 441 | p.z = z; p.bin = bin; |
434 | luaZ_initbuffer(L, &p.buff); | 442 | luaZ_initbuffer(L, &p.buff); |
435 | /* before parsing, give a (good) chance to GC */ | ||
436 | if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold) | ||
437 | luaC_collectgarbage(L); | ||
438 | old_blocks = G(L)->nblocks; | ||
439 | status = luaD_rawrunprotected(L, f_parser, &p); | 443 | status = luaD_rawrunprotected(L, f_parser, &p); |
440 | luaZ_freebuffer(L, &p.buff); | 444 | luaZ_freebuffer(L, &p.buff); |
441 | if (status == 0) { | 445 | if (status != 0) { /* error */ |
442 | /* add new memory to threshold (as it probably will stay) */ | ||
443 | lua_assert(G(L)->nblocks >= old_blocks); | ||
444 | G(L)->GCthreshold += (G(L)->nblocks - old_blocks); | ||
445 | } | ||
446 | else { /* error */ | ||
447 | StkId oldtop = restorestack(L, oldtopr); | 446 | StkId oldtop = restorestack(L, oldtopr); |
448 | seterrorobj(L, status, oldtop); | 447 | seterrorobj(L, status, oldtop); |
449 | } | 448 | } |