macros LUA_ENTRY/LUA_EXIT to control exclusive access to Lua core

This commit is contained in:
Roberto Ierusalimschy
2001-01-24 13:45:33 -02:00
parent 6fda6a5302
commit 71ae4801d6
11 changed files with 420 additions and 149 deletions

32
ldo.c
View File

@@ -1,5 +1,5 @@
/*
** $Id: ldo.c,v 1.114 2001/01/18 15:59:09 roberto Exp roberto $
** $Id: ldo.c,v 1.115 2001/01/19 13:20:30 roberto Exp roberto $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/
@@ -56,7 +56,7 @@ void luaD_checkstack (lua_State *L, int n) {
else {
L->stack_last += EXTRA_STACK; /* to be used by error message */
lua_assert(L->stack_last == L->stack+L->stacksize-1);
lua_error(L, "stack overflow");
luaD_error(L, "stack overflow");
}
}
}
@@ -94,7 +94,9 @@ static void dohook (lua_State *L, lua_Debug *ar, lua_Hook hook) {
StkId old_top = L->Cbase = L->top;
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
L->allowhooks = 0; /* cannot call hooks inside a hook */
LUA_EXIT;
(*hook)(L, ar);
LUA_ENTRY;
lua_assert(L->allowhooks == 0);
L->allowhooks = 1;
L->top = old_top;
@@ -133,7 +135,9 @@ static StkId callCclosure (lua_State *L, const struct Closure *cl, StkId base) {
luaD_checkstack(L, nup+LUA_MINSTACK); /* ensure minimum stack size */
for (n=0; n<nup; n++) /* copy upvalues as extra arguments */
setobj(L->top++, &cl->upvalue[n]);
LUA_EXIT;
n = (*cl->f.c)(L); /* do the actual call */
LUA_ENTRY;
L->Cbase = old_Cbase; /* restore old C base */
return L->top - n; /* return index of first result */
}
@@ -212,13 +216,16 @@ static void f_call (lua_State *L, void *ud) {
LUA_API int lua_call (lua_State *L, int nargs, int nresults) {
StkId func = L->top - (nargs+1); /* function to be called */
StkId func;
struct CallS c;
int status;
LUA_ENTRY;
func = L->top - (nargs+1); /* function to be called */
c.func = func; c.nresults = nresults;
status = luaD_runprotected(L, f_call, &c);
if (status != 0) /* an error occurred? */
L->top = func; /* remove parameters from the stack */
LUA_EXIT;
return status;
}
@@ -242,6 +249,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
struct ParserS p;
mem_int old_blocks;
int status;
LUA_ENTRY;
p.z = z; p.bin = bin;
luaC_checkGC(L);
old_blocks = G(L)->nblocks;
@@ -253,6 +261,7 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
}
else if (status == LUA_ERRRUN) /* an error occurred: correct error code */
status = LUA_ERRSYNTAX;
LUA_EXIT;
return status;
}
@@ -275,9 +284,9 @@ static int parse_file (lua_State *L, const char *filename) {
lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename);
lua_concat(L, 2);
filename = lua_tostring(L, -1); /* filename = '@'..filename */
lua_pop(L, 1); /* OK: there is no GC during parser */
luaZ_Fopen(&z, f, filename);
status = protectedparser(L, &z, bin);
lua_remove(L, -2); /* remove filename */
if (f != stdin)
fclose(f);
return status;
@@ -285,7 +294,8 @@ static int parse_file (lua_State *L, const char *filename) {
LUA_API int lua_dofile (lua_State *L, const char *filename) {
int status = parse_file(L, filename);
int status;
status = parse_file(L, filename);
if (status == 0) /* parse OK? */
status = lua_call(L, 0, LUA_MULTRET); /* call main */
return status;
@@ -295,14 +305,17 @@ LUA_API int lua_dofile (lua_State *L, const char *filename) {
static int parse_buffer (lua_State *L, const char *buff, size_t size,
const char *name) {
ZIO z;
int status;
if (!name) name = "?";
luaZ_mopen(&z, buff, size, name);
return protectedparser(L, &z, buff[0]==ID_CHUNK);
status = protectedparser(L, &z, buff[0]==ID_CHUNK);
return status;
}
LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name) {
int status = parse_buffer(L, buff, size, name);
int status;
status = parse_buffer(L, buff, size, name);
if (status == 0) /* parse OK? */
status = lua_call(L, 0, LUA_MULTRET); /* call main */
return status;
@@ -333,7 +346,8 @@ static void message (lua_State *L, const char *s) {
if (ttype(em) == LUA_TFUNCTION) {
setobj(L->top, em);
incr_top;
lua_pushstring(L, s);
setsvalue(L->top, luaS_new(L, s));
incr_top;
luaD_call(L, L->top-2, 0);
}
}
@@ -342,7 +356,7 @@ static void message (lua_State *L, const char *s) {
/*
** Reports an error, and jumps up to the available recovery label
*/
LUA_API void lua_error (lua_State *L, const char *s) {
void luaD_error (lua_State *L, const char *s) {
if (s) message(L, s);
luaD_breakrun(L, LUA_ERRRUN);
}