aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/ldo.c b/ldo.c
index 2349aaed..f2d12f04 100644
--- a/ldo.c
+++ b/ldo.c
@@ -88,7 +88,7 @@ struct lua_longjmp {
88}; 88};
89 89
90 90
91static void seterrorobj (lua_State *L, int errcode, StkId oldtop) { 91void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop) {
92 switch (errcode) { 92 switch (errcode) {
93 case LUA_ERRMEM: { /* memory error? */ 93 case LUA_ERRMEM: { /* memory error? */
94 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ 94 setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */
@@ -121,7 +121,7 @@ l_noret luaD_throw (lua_State *L, int errcode) {
121 } 121 }
122 else { /* no handler at all; abort */ 122 else { /* no handler at all; abort */
123 if (g->panic) { /* panic function? */ 123 if (g->panic) { /* panic function? */
124 seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */ 124 luaD_seterrorobj(L, errcode, L->top); /* assume EXTRA_STACK */
125 if (L->ci->top < L->top) 125 if (L->ci->top < L->top)
126 L->ci->top = L->top; /* pushing msg. can break this invariant */ 126 L->ci->top = L->top; /* pushing msg. can break this invariant */
127 lua_unlock(L); 127 lua_unlock(L);
@@ -584,8 +584,8 @@ static int recover (lua_State *L, int status) {
584 if (ci == NULL) return 0; /* no recovery point */ 584 if (ci == NULL) return 0; /* no recovery point */
585 /* "finish" luaD_pcall */ 585 /* "finish" luaD_pcall */
586 oldtop = restorestack(L, ci->u2.funcidx); 586 oldtop = restorestack(L, ci->u2.funcidx);
587 luaF_close(L, oldtop); 587 luaF_close(L, oldtop, status);
588 seterrorobj(L, status, oldtop); 588 luaD_seterrorobj(L, status, oldtop);
589 L->ci = ci; 589 L->ci = ci;
590 L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */ 590 L->allowhook = getoah(ci->callstatus); /* restore original 'allowhook' */
591 L->nny = 0; /* should be zero to be yieldable */ 591 L->nny = 0; /* should be zero to be yieldable */
@@ -678,7 +678,7 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
678 } 678 }
679 if (unlikely(errorstatus(status))) { /* unrecoverable error? */ 679 if (unlikely(errorstatus(status))) { /* unrecoverable error? */
680 L->status = cast_byte(status); /* mark thread as 'dead' */ 680 L->status = cast_byte(status); /* mark thread as 'dead' */
681 seterrorobj(L, status, L->top); /* push error message */ 681 luaD_seterrorobj(L, status, L->top); /* push error message */
682 L->ci->top = L->top; 682 L->ci->top = L->top;
683 } 683 }
684 else lua_assert(status == L->status); /* normal end or yield */ 684 else lua_assert(status == L->status); /* normal end or yield */
@@ -726,6 +726,11 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, lua_KContext ctx,
726} 726}
727 727
728 728
729/*
730** Call the C function 'func' in protected mode, restoring basic
731** thread information ('allowhook', 'nny', etc.) and in particular
732** its stack level in case of errors.
733*/
729int luaD_pcall (lua_State *L, Pfunc func, void *u, 734int luaD_pcall (lua_State *L, Pfunc func, void *u,
730 ptrdiff_t old_top, ptrdiff_t ef) { 735 ptrdiff_t old_top, ptrdiff_t ef) {
731 int status; 736 int status;
@@ -737,11 +742,12 @@ int luaD_pcall (lua_State *L, Pfunc func, void *u,
737 status = luaD_rawrunprotected(L, func, u); 742 status = luaD_rawrunprotected(L, func, u);
738 if (unlikely(status != LUA_OK)) { /* an error occurred? */ 743 if (unlikely(status != LUA_OK)) { /* an error occurred? */
739 StkId oldtop = restorestack(L, old_top); 744 StkId oldtop = restorestack(L, old_top);
740 luaF_close(L, oldtop); /* close possible pending closures */
741 seterrorobj(L, status, oldtop);
742 L->ci = old_ci; 745 L->ci = old_ci;
743 L->allowhook = old_allowhooks; 746 L->allowhook = old_allowhooks;
744 L->nny = old_nny; 747 L->nny = old_nny;
748 status = luaF_close(L, oldtop, status);
749 oldtop = restorestack(L, old_top); /* previous call may change stack */
750 luaD_seterrorobj(L, status, oldtop);
745 luaD_shrinkstack(L); 751 luaD_shrinkstack(L);
746 } 752 }
747 L->errfunc = old_errfunc; 753 L->errfunc = old_errfunc;