mirror of
https://github.com/lua/lua.git
synced 2026-06-08 08:03:49 +00:00
Bug: 'lua_load' does not preserve the stack
'lua_load' does not preserve the stack through the calls to the reader function, as it should. Immediately after the first call (to detect whether chunk is binary) it adds stuff, and it also adds a new table when starting the compilation of each new function.
This commit is contained in:
13
lundump.c
13
lundump.c
@@ -392,7 +392,8 @@ static void checkHeader (LoadState *S) {
|
||||
/*
|
||||
** Load precompiled chunk.
|
||||
*/
|
||||
LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) {
|
||||
LClosure *luaU_undump (lua_State *L, ZIO *Z, Table *anchor, const char *name,
|
||||
int fixed) {
|
||||
LoadState S;
|
||||
LClosure *cl;
|
||||
if (*name == '@' || *name == '=')
|
||||
@@ -405,20 +406,16 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) {
|
||||
S.fixed = cast_byte(fixed);
|
||||
S.offset = 1; /* fist byte was already read */
|
||||
checkHeader(&S);
|
||||
cl = luaF_newLclosure(L, loadByte(&S));
|
||||
setclLvalue2s(L, L->top.p, cl);
|
||||
luaD_inctop(L);
|
||||
S.h = luaH_new(L); /* create list of saved strings */
|
||||
S.h = anchor;
|
||||
S.nstr = 0;
|
||||
sethvalue2s(L, L->top.p, S.h); /* anchor it */
|
||||
luaD_inctop(L);
|
||||
cl = luaF_newLclosure(L, loadByte(&S));
|
||||
luaD_anchorobj(L, anchor, obj2gco(cl));
|
||||
cl->p = luaF_newproto(L);
|
||||
luaC_objbarrier(L, cl, cl->p);
|
||||
loadFunction(&S, cl->p);
|
||||
if (cl->nupvalues != cl->p->sizeupvalues)
|
||||
error(&S, "corrupted chunk");
|
||||
luai_verifycode(L, cl->p);
|
||||
L->top.p--; /* pop table */
|
||||
return cl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user