From 29ede6aa13144ff7b69c57a87be1ee93f57ae896 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 22 Nov 1999 11:12:07 -0200 Subject: first implementation of multiple states (reentrant code). --- lref.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'lref.c') diff --git a/lref.c b/lref.c index 5c22b63b..caaae400 100644 --- a/lref.c +++ b/lref.c @@ -1,17 +1,19 @@ /* -** $Id: lref.c,v 1.1 1999/10/04 17:50:24 roberto Exp roberto $ +** $Id: lref.c,v 1.2 1999/11/10 15:37:50 roberto Exp roberto $ ** REF mechanism ** See Copyright Notice in lua.h */ +#define LUA_REENTRANT + #include "lmem.h" #include "lref.h" #include "lstate.h" #include "lua.h" -int luaR_ref (const TObject *o, int lock) { +int luaR_ref (lua_State *L, const TObject *o, int lock) { int ref; if (ttype(o) == LUA_T_NIL) ref = LUA_REFNIL; @@ -21,7 +23,7 @@ int luaR_ref (const TObject *o, int lock) { L->refFree = L->refArray[ref].st; } else { /* no more free places */ - luaM_growvector(L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT); + luaM_growvector(L, L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT); ref = L->refSize++; } L->refArray[ref].o = *o; @@ -31,17 +33,17 @@ int luaR_ref (const TObject *o, int lock) { } -void lua_unref (int ref) { +void lua_unref (lua_State *L, int ref) { if (ref >= 0) { if (ref >= L->refSize || L->refArray[ref].st >= 0) - lua_error("API error - invalid parameter for function `lua_unref'"); + lua_error(L, "API error - invalid parameter for function `lua_unref'"); L->refArray[ref].st = L->refFree; L->refFree = ref; } } -const TObject *luaR_getref (int ref) { +const TObject *luaR_getref (lua_State *L, int ref) { if (ref == LUA_REFNIL) return &luaO_nilobject; else if (0 <= ref && ref < L->refSize && @@ -66,7 +68,7 @@ static int ismarked (const TObject *o) { #ifdef DEBUG case LUA_T_LINE: case LUA_T_CLMARK: case LUA_T_CMARK: case LUA_T_PMARK: - LUA_INTERNALERROR("invalid type"); + LUA_INTERNALERROR(L, "invalid type"); #endif default: /* number or cproto */ return 1; @@ -75,21 +77,21 @@ static int ismarked (const TObject *o) { /* for internal debugging only; check if a link of free refs is valid */ -#define VALIDLINK(st,n) (NONEXT <= (st) && (st) < (n)) +#define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n)) -void luaR_invalidaterefs (void) { +void luaR_invalidaterefs (lua_State *L) { int n = L->refSize; int i; for (i=0; irefArray[i]; if (r->st == HOLD && !ismarked(&r->o)) r->st = COLLECTED; - LUA_ASSERT((r->st == LOCK && ismarked(&r->o)) || + LUA_ASSERT(L, (r->st == LOCK && ismarked(&r->o)) || r->st == COLLECTED || r->st == NONEXT || - (r->st < n && VALIDLINK(L->refArray[r->st].st, n)), + (r->st < n && VALIDLINK(L, L->refArray[r->st].st, n)), "inconsistent ref table"); } - LUA_ASSERT(VALIDLINK(L->refFree, n), "inconsistent ref table"); + LUA_ASSERT(L, VALIDLINK(L, L->refFree, n), "inconsistent ref table"); } -- cgit v1.2.3-55-g6feb