diff options
Diffstat (limited to 'lref.c')
-rw-r--r-- | lref.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -1,17 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lref.c,v 1.1 1999/10/04 17:50:24 roberto Exp roberto $ | 2 | ** $Id: lref.c,v 1.2 1999/11/10 15:37:50 roberto Exp roberto $ |
3 | ** REF mechanism | 3 | ** REF mechanism |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
6 | 6 | ||
7 | 7 | ||
8 | #define LUA_REENTRANT | ||
9 | |||
8 | #include "lmem.h" | 10 | #include "lmem.h" |
9 | #include "lref.h" | 11 | #include "lref.h" |
10 | #include "lstate.h" | 12 | #include "lstate.h" |
11 | #include "lua.h" | 13 | #include "lua.h" |
12 | 14 | ||
13 | 15 | ||
14 | int luaR_ref (const TObject *o, int lock) { | 16 | int luaR_ref (lua_State *L, const TObject *o, int lock) { |
15 | int ref; | 17 | int ref; |
16 | if (ttype(o) == LUA_T_NIL) | 18 | if (ttype(o) == LUA_T_NIL) |
17 | ref = LUA_REFNIL; | 19 | ref = LUA_REFNIL; |
@@ -21,7 +23,7 @@ int luaR_ref (const TObject *o, int lock) { | |||
21 | L->refFree = L->refArray[ref].st; | 23 | L->refFree = L->refArray[ref].st; |
22 | } | 24 | } |
23 | else { /* no more free places */ | 25 | else { /* no more free places */ |
24 | luaM_growvector(L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT); | 26 | luaM_growvector(L, L->refArray, L->refSize, 1, struct ref, refEM, MAX_INT); |
25 | ref = L->refSize++; | 27 | ref = L->refSize++; |
26 | } | 28 | } |
27 | L->refArray[ref].o = *o; | 29 | L->refArray[ref].o = *o; |
@@ -31,17 +33,17 @@ int luaR_ref (const TObject *o, int lock) { | |||
31 | } | 33 | } |
32 | 34 | ||
33 | 35 | ||
34 | void lua_unref (int ref) { | 36 | void lua_unref (lua_State *L, int ref) { |
35 | if (ref >= 0) { | 37 | if (ref >= 0) { |
36 | if (ref >= L->refSize || L->refArray[ref].st >= 0) | 38 | if (ref >= L->refSize || L->refArray[ref].st >= 0) |
37 | lua_error("API error - invalid parameter for function `lua_unref'"); | 39 | lua_error(L, "API error - invalid parameter for function `lua_unref'"); |
38 | L->refArray[ref].st = L->refFree; | 40 | L->refArray[ref].st = L->refFree; |
39 | L->refFree = ref; | 41 | L->refFree = ref; |
40 | } | 42 | } |
41 | } | 43 | } |
42 | 44 | ||
43 | 45 | ||
44 | const TObject *luaR_getref (int ref) { | 46 | const TObject *luaR_getref (lua_State *L, int ref) { |
45 | if (ref == LUA_REFNIL) | 47 | if (ref == LUA_REFNIL) |
46 | return &luaO_nilobject; | 48 | return &luaO_nilobject; |
47 | else if (0 <= ref && ref < L->refSize && | 49 | else if (0 <= ref && ref < L->refSize && |
@@ -66,7 +68,7 @@ static int ismarked (const TObject *o) { | |||
66 | #ifdef DEBUG | 68 | #ifdef DEBUG |
67 | case LUA_T_LINE: case LUA_T_CLMARK: | 69 | case LUA_T_LINE: case LUA_T_CLMARK: |
68 | case LUA_T_CMARK: case LUA_T_PMARK: | 70 | case LUA_T_CMARK: case LUA_T_PMARK: |
69 | LUA_INTERNALERROR("invalid type"); | 71 | LUA_INTERNALERROR(L, "invalid type"); |
70 | #endif | 72 | #endif |
71 | default: /* number or cproto */ | 73 | default: /* number or cproto */ |
72 | return 1; | 74 | return 1; |
@@ -75,21 +77,21 @@ static int ismarked (const TObject *o) { | |||
75 | 77 | ||
76 | 78 | ||
77 | /* for internal debugging only; check if a link of free refs is valid */ | 79 | /* for internal debugging only; check if a link of free refs is valid */ |
78 | #define VALIDLINK(st,n) (NONEXT <= (st) && (st) < (n)) | 80 | #define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n)) |
79 | 81 | ||
80 | void luaR_invalidaterefs (void) { | 82 | void luaR_invalidaterefs (lua_State *L) { |
81 | int n = L->refSize; | 83 | int n = L->refSize; |
82 | int i; | 84 | int i; |
83 | for (i=0; i<n; i++) { | 85 | for (i=0; i<n; i++) { |
84 | struct ref *r = &L->refArray[i]; | 86 | struct ref *r = &L->refArray[i]; |
85 | if (r->st == HOLD && !ismarked(&r->o)) | 87 | if (r->st == HOLD && !ismarked(&r->o)) |
86 | r->st = COLLECTED; | 88 | r->st = COLLECTED; |
87 | LUA_ASSERT((r->st == LOCK && ismarked(&r->o)) || | 89 | LUA_ASSERT(L, (r->st == LOCK && ismarked(&r->o)) || |
88 | r->st == COLLECTED || | 90 | r->st == COLLECTED || |
89 | r->st == NONEXT || | 91 | r->st == NONEXT || |
90 | (r->st < n && VALIDLINK(L->refArray[r->st].st, n)), | 92 | (r->st < n && VALIDLINK(L, L->refArray[r->st].st, n)), |
91 | "inconsistent ref table"); | 93 | "inconsistent ref table"); |
92 | } | 94 | } |
93 | LUA_ASSERT(VALIDLINK(L->refFree, n), "inconsistent ref table"); | 95 | LUA_ASSERT(L, VALIDLINK(L, L->refFree, n), "inconsistent ref table"); |
94 | } | 96 | } |
95 | 97 | ||