diff options
Diffstat (limited to 'ldo.c')
-rw-r--r-- | ldo.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -15,6 +15,7 @@ | |||
15 | 15 | ||
16 | #include "ldebug.h" | 16 | #include "ldebug.h" |
17 | #include "ldo.h" | 17 | #include "ldo.h" |
18 | #include "lfunc.h" | ||
18 | #include "lgc.h" | 19 | #include "lgc.h" |
19 | #include "lmem.h" | 20 | #include "lmem.h" |
20 | #include "lobject.h" | 21 | #include "lobject.h" |
@@ -122,9 +123,9 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl) { | |||
122 | int n; | 123 | int n; |
123 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ | 124 | luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */ |
124 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ | 125 | for (n=0; n<nup; n++) /* copy upvalues as extra arguments */ |
125 | setobj(L->top++, &cl->upvalue[n]); | 126 | setobj(L->top++, &cl->u.c.upvalue[n]); |
126 | lua_unlock(L); | 127 | lua_unlock(L); |
127 | n = (*cl->f.c)(L); /* do the actual call */ | 128 | n = (*cl->u.c.f)(L); /* do the actual call */ |
128 | lua_lock(L); | 129 | lua_lock(L); |
129 | return L->top - n; /* return index of first result */ | 130 | return L->top - n; /* return index of first result */ |
130 | } | 131 | } |
@@ -209,7 +210,12 @@ struct SParser { /* data to `f_parser' */ | |||
209 | static void f_parser (lua_State *L, void *ud) { | 210 | static void f_parser (lua_State *L, void *ud) { |
210 | struct SParser *p = cast(struct SParser *, ud); | 211 | struct SParser *p = cast(struct SParser *, ud); |
211 | Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); | 212 | Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z); |
212 | luaV_Lclosure(L, tf, 0); | 213 | Closure *cl = luaF_newLclosure(L, 0); |
214 | cl->u.l.p = tf; | ||
215 | luaF_LConlist(L, cl); | ||
216 | setclvalue(L->top, cl); | ||
217 | incr_top; | ||
218 | |||
213 | } | 219 | } |
214 | 220 | ||
215 | 221 | ||
@@ -286,6 +292,9 @@ struct lua_longjmp { | |||
286 | jmp_buf b; | 292 | jmp_buf b; |
287 | struct lua_longjmp *previous; | 293 | struct lua_longjmp *previous; |
288 | volatile int status; /* error code */ | 294 | volatile int status; /* error code */ |
295 | CallInfo *ci; /* call info of active function that set protection */ | ||
296 | StkId top; /* top stack when protection was set */ | ||
297 | int allowhooks; /* `allowhook' state when protection was set */ | ||
289 | }; | 298 | }; |
290 | 299 | ||
291 | 300 | ||
@@ -325,19 +334,20 @@ void luaD_breakrun (lua_State *L, int errcode) { | |||
325 | 334 | ||
326 | 335 | ||
327 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud) { | 336 | int luaD_runprotected (lua_State *L, void (*f)(lua_State *, void *), void *ud) { |
328 | CallInfo *oldci = L->ci; | ||
329 | StkId oldtop = L->top; | ||
330 | struct lua_longjmp lj; | 337 | struct lua_longjmp lj; |
331 | int allowhooks = L->allowhooks; | 338 | lj.ci = L->ci; |
339 | lj.top = L->top; | ||
340 | lj.allowhooks = L->allowhooks; | ||
332 | lj.status = 0; | 341 | lj.status = 0; |
333 | lj.previous = L->errorJmp; /* chain new error handler */ | 342 | lj.previous = L->errorJmp; /* chain new error handler */ |
334 | L->errorJmp = &lj; | 343 | L->errorJmp = &lj; |
335 | if (setjmp(lj.b) == 0) | 344 | if (setjmp(lj.b) == 0) |
336 | (*f)(L, ud); | 345 | (*f)(L, ud); |
337 | else { /* an error occurred: restore the state */ | 346 | else { /* an error occurred: restore the state */ |
338 | L->allowhooks = allowhooks; | 347 | luaF_close(L, lj.top); /* close eventual pending closures */ |
339 | L->ci = oldci; | 348 | L->ci = lj.ci; |
340 | L->top = oldtop; | 349 | L->top = lj.top; |
350 | L->allowhooks = lj.allowhooks; | ||
341 | restore_stack_limit(L); | 351 | restore_stack_limit(L); |
342 | } | 352 | } |
343 | L->errorJmp = lj.previous; /* restore old error handler */ | 353 | L->errorJmp = lj.previous; /* restore old error handler */ |