commit 3e41afcec550e8c5c3c4372f72efa48cbf7031a3
parent 3acf5ec5a18c83ed0ce7e41c9b5789bddd2b3e60
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 27 Nov 2009 13:37:35 -0200
extra api checks for number of returns of C functions and for lua_yield
Diffstat:
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 2.99 2009/11/09 18:55:17 roberto Exp roberto $
+** $Id: lapi.c,v 2.100 2009/11/09 19:10:48 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -35,9 +35,6 @@ const char lua_ident[] =
-#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
- "not enough elements in the stack")
-
#define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject, \
"invalid index")
diff --git a/lapi.h b/lapi.h
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.h,v 2.5 2009/04/03 15:58:03 roberto Exp roberto $
+** $Id: lapi.h,v 2.6 2009/08/31 14:26:28 roberto Exp roberto $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/
@@ -17,5 +17,8 @@
#define adjustresults(L,nres) \
{ if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; }
+#define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \
+ "not enough elements in the stack")
+
#endif
diff --git a/ldo.c b/ldo.c
@@ -1,5 +1,5 @@
/*
-** $Id: ldo.c,v 2.72 2009/11/17 16:46:44 roberto Exp roberto $
+** $Id: ldo.c,v 2.73 2009/11/25 15:27:51 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -311,6 +311,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
lua_unlock(L);
n = (*curr_func(L)->c.f)(L); /* do the actual call */
lua_lock(L);
+ api_checknelems(L, n);
luaD_poscall(L, L->top - n);
return 1;
}
@@ -382,6 +383,7 @@ static void finishCcall (lua_State *L) {
lua_unlock(L);
n = (*ci->u.c.k)(L);
lua_lock(L);
+ api_checknelems(L, n);
/* finish 'luaD_precall' */
luaD_poscall(L, L->top - n);
}
@@ -424,6 +426,7 @@ static void resume (lua_State *L, void *ud) {
lua_unlock(L);
n = (*ci->u.c.k)(L); /* call continuation */
lua_lock(L);
+ api_checknelems(L, n);
firstArg = L->top - n;
}
G(L)->nCcalls--; /* finish 'luaD_call' */
@@ -511,6 +514,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) {
CallInfo *ci = L->ci;
luai_userstateyield(L, nresults);
lua_lock(L);
+ api_checknelems(L, nresults);
if (L->nny > 0)
luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
L->status = LUA_YIELD;