new API for 'lua_resume' + cleaning the uses of the 'extra' field in

'CallInfo'
This commit is contained in:
Roberto Ierusalimschy
2017-11-02 09:28:56 -02:00
parent b9e76be8a6
commit ba36180fd7
7 changed files with 31 additions and 58 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: ldebug.c,v 2.133 2017/10/31 17:14:02 roberto Exp roberto $
** $Id: ldebug.c,v 2.134 2017/11/01 18:20:48 roberto Exp roberto $
** Debug Interface
** See Copyright Notice in lua.h
*/
@@ -106,22 +106,6 @@ static int currentline (CallInfo *ci) {
}
/*
** If function yielded, its 'func' can be in the 'extra' field. The
** next function restores 'func' to its correct value for debugging
** purposes. (It exchanges 'func' and 'extra'; so, when called again,
** after debugging, it also "re-restores" ** 'func' to its altered value.
*/
static void swapextra (lua_State *L) {
if (L->status == LUA_YIELD) {
CallInfo *ci = L->ci; /* get function that yielded */
StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
L->func = ci->func = restorestack(L, ci->extra);
ci->extra = savestack(L, temp);
}
}
/*
** This function can be called asynchronously (e.g. during a signal).
** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
@@ -209,7 +193,6 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
const char *name;
lua_lock(L);
swapextra(L);
if (ar == NULL) { /* information about non-active function? */
if (!isLfunction(s2v(L->top - 1))) /* not a Lua function? */
name = NULL;
@@ -224,7 +207,6 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
api_incr_top(L);
}
}
swapextra(L);
lua_unlock(L);
return name;
}
@@ -234,13 +216,11 @@ LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
StkId pos = NULL; /* to avoid warnings */
const char *name;
lua_lock(L);
swapextra(L);
name = findlocal(L, ar->i_ci, n, &pos);
if (name) {
setobjs2s(L, pos, L->top - 1);
L->top--; /* pop value */
}
swapextra(L);
lua_unlock(L);
return name;
}
@@ -361,7 +341,6 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
CallInfo *ci;
TValue *func;
lua_lock(L);
swapextra(L);
if (*what == '>') {
ci = NULL;
func = s2v(L->top - 1);
@@ -380,7 +359,6 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
setobj2s(L, L->top, func);
api_incr_top(L);
}
swapextra(L); /* correct before option 'L', which can raise a mem. error */
if (strchr(what, 'L'))
collectvalidlines(L, cl);
lua_unlock(L);
@@ -790,7 +768,6 @@ void luaG_traceexec (lua_State *L) {
L->hookcount = 1; /* undo decrement to zero */
ci->u.l.savedpc--; /* undo increment (resume will increment it again) */
ci->callstatus |= CIST_HOOKYIELD; /* mark that it yielded */
L->func = ci->func = L->top - 1; /* protect stack below results */
luaD_throw(L, LUA_YIELD);
}
}