first implementation of multiple states (reentrant code).
This commit is contained in:
26
lref.c
26
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; i<n; i++) {
|
||||
struct ref *r = &L->refArray[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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user