summaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-08-27 18:01:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2003-08-27 18:01:44 -0300
commit8332d5c8a5059b85da1adaa3f0197d0f57afae81 (patch)
tree8a2f59ff0803da3afbc7e8a409911c920d624e94 /ldo.c
parent885961be1d8e3f703b54d1d19e6c63617cd2ed24 (diff)
downloadlua-github-8332d5c8a5059b85da1adaa3f0197d0f57afae81.tar.gz
parser fully reentrant(!)
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/ldo.c b/ldo.c
index 2b5dfdbf..bf244c91 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 1.222 2003/08/25 19:51:54 roberto Exp roberto $
+** $Id: ldo.c,v 1.223 2003/08/26 12:04:13 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -429,18 +429,17 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
struct SParser { /* data to `f_parser' */
ZIO *z;
Mbuffer buff; /* buffer to be used by the scanner */
- int bin;
const char *name;
};
static void f_parser (lua_State *L, void *ud) {
- struct SParser *p;
Proto *tf;
Closure *cl;
+ struct SParser *p = cast(struct SParser *, ud);
+ int c = luaZ_lookahead(p->z);
luaC_checkGC(L);
- p = cast(struct SParser *, ud);
- tf = p->bin ? luaU_undump(L, p->z, &p->buff, p->name) :
- luaY_parser(L, p->z, &p->buff, p->name);
+ tf = (c == LUA_SIGNATURE[0]) ? luaU_undump(L, p->z, &p->buff, p->name) :
+ luaY_parser(L, p->z, &p->buff, p->name);
cl = luaF_newLclosure(L, 0, gt(L));
cl->l.p = tf;
setclvalue(L->top, cl);
@@ -448,18 +447,13 @@ static void f_parser (lua_State *L, void *ud) {
}
-int luaD_protectedparser (lua_State *L, ZIO *z, int bin, const char *name) {
+int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) {
struct SParser p;
int status;
- ptrdiff_t oldtopr = savestack(L, L->top); /* save current top */
- p.z = z; p.bin = bin; p.name = name;
+ p.z = z; p.name = name;
luaZ_initbuffer(L, &p.buff);
- status = luaD_rawrunprotected(L, f_parser, &p);
+ status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc);
luaZ_freebuffer(L, &p.buff);
- if (status != 0) { /* error? */
- StkId oldtop = restorestack(L, oldtopr);
- seterrorobj(L, status, oldtop);
- }
return status;
}