summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-01-23 09:31:38 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-01-23 09:31:38 -0200
commite44e579dc19ec0060f5e84c7a692b5c1cff2eec3 (patch)
treeaae4ceddfd208640dee81368c94903384d29e034 /ldo.c
parenta153cafd8df6c3b6dfd13d3d99d7a39d912dc983 (diff)
downloadlua-github-e44e579dc19ec0060f5e84c7a692b5c1cff2eec3.tar.gz
bug: luaD_protectedparser must protect its garbage collection too
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/ldo.c b/ldo.c
index 5ce25b5f..00b42ccc 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.210 2002/12/04 17:28:27 roberto Exp roberto $
+** $Id: ldo.c,v 1.211 2002/12/04 17:38:31 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -415,35 +415,34 @@ struct SParser { /* data to `f_parser' */
};
static void f_parser (lua_State *L, void *ud) {
+ lu_mem old_blocks;
+ Proto *tf;
+ Closure *cl;
struct SParser *p = cast(struct SParser *, ud);
- Proto *tf = p->bin ? luaU_undump(L, p->z, &p->buff) :
- luaY_parser(L, p->z, &p->buff);
- Closure *cl = luaF_newLclosure(L, 0, gt(L));
+ /* before parsing, give a (good) chance to GC */
+ if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold)
+ luaC_collectgarbage(L);
+ old_blocks = G(L)->nblocks;
+ tf = p->bin ? luaU_undump(L, p->z, &p->buff) : luaY_parser(L, p->z, &p->buff);
+ cl = luaF_newLclosure(L, 0, gt(L));
cl->l.p = tf;
setclvalue(L->top, cl);
incr_top(L);
+ /* add new memory to threshold (as it probably will stay) */
+ lua_assert(G(L)->nblocks >= old_blocks);
+ G(L)->GCthreshold += (G(L)->nblocks - old_blocks);
}
int luaD_protectedparser (lua_State *L, ZIO *z, int bin) {
struct SParser p;
- lu_mem old_blocks;
int status;
ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */
p.z = z; p.bin = bin;
luaZ_initbuffer(L, &p.buff);
- /* before parsing, give a (good) chance to GC */
- if (G(L)->nblocks + G(L)->nblocks/4 >= G(L)->GCthreshold)
- luaC_collectgarbage(L);
- old_blocks = G(L)->nblocks;
status = luaD_rawrunprotected(L, f_parser, &p);
luaZ_freebuffer(L, &p.buff);
- if (status == 0) {
- /* add new memory to threshold (as it probably will stay) */
- lua_assert(G(L)->nblocks >= old_blocks);
- G(L)->GCthreshold += (G(L)->nblocks - old_blocks);
- }
- else { /* error */
+ if (status != 0) { /* error */
StkId oldtop = restorestack(L, oldtopr);
seterrorobj(L, status, oldtop);
}