diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-16 17:52:00 -0300 |
commit | c787dccd9b5c3e55547a2c4bb598c0276de65034 (patch) | |
tree | c4cdf2f7319fee48e048472a2044119f541e8da2 /lgc.c | |
parent | b44e35b773bcaa9891d80a117392911ab5f656e5 (diff) | |
download | lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.gz lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.tar.bz2 lua-c787dccd9b5c3e55547a2c4bb598c0276de65034.zip |
"const" !!!
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 52 |
1 files changed, 18 insertions, 34 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 1.23 1999/03/04 21:17:26 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 1.24 1999/08/11 17:00:59 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -29,7 +29,7 @@ static int markobject (TObject *o); | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | 31 | ||
32 | int luaC_ref (TObject *o, int lock) { | 32 | int luaC_ref (const TObject *o, int lock) { |
33 | int ref; | 33 | int ref; |
34 | if (ttype(o) == LUA_T_NIL) | 34 | if (ttype(o) == LUA_T_NIL) |
35 | ref = LUA_REFNIL; | 35 | ref = LUA_REFNIL; |
@@ -48,15 +48,13 @@ int luaC_ref (TObject *o, int lock) { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | 50 | ||
51 | void lua_unref (int ref) | 51 | void lua_unref (int ref) { |
52 | { | ||
53 | if (ref >= 0 && ref < L->refSize) | 52 | if (ref >= 0 && ref < L->refSize) |
54 | L->refArray[ref].status = FREE; | 53 | L->refArray[ref].status = FREE; |
55 | } | 54 | } |
56 | 55 | ||
57 | 56 | ||
58 | TObject* luaC_getref (int ref) | 57 | const TObject *luaC_getref (int ref) { |
59 | { | ||
60 | if (ref == LUA_REFNIL) | 58 | if (ref == LUA_REFNIL) |
61 | return &luaO_nilobject; | 59 | return &luaO_nilobject; |
62 | if (ref >= 0 && ref < L->refSize && | 60 | if (ref >= 0 && ref < L->refSize && |
@@ -67,8 +65,7 @@ TObject* luaC_getref (int ref) | |||
67 | } | 65 | } |
68 | 66 | ||
69 | 67 | ||
70 | static void travlock (void) | 68 | static void travlock (void) { |
71 | { | ||
72 | int i; | 69 | int i; |
73 | for (i=0; i<L->refSize; i++) | 70 | for (i=0; i<L->refSize; i++) |
74 | if (L->refArray[i].status == LOCK) | 71 | if (L->refArray[i].status == LOCK) |
@@ -76,8 +73,7 @@ static void travlock (void) | |||
76 | } | 73 | } |
77 | 74 | ||
78 | 75 | ||
79 | static int ismarked (TObject *o) | 76 | static int ismarked (const TObject *o) { |
80 | { | ||
81 | /* valid only for locked objects */ | 77 | /* valid only for locked objects */ |
82 | switch (o->ttype) { | 78 | switch (o->ttype) { |
83 | case LUA_T_STRING: case LUA_T_USERDATA: | 79 | case LUA_T_STRING: case LUA_T_USERDATA: |
@@ -99,8 +95,7 @@ static int ismarked (TObject *o) | |||
99 | } | 95 | } |
100 | 96 | ||
101 | 97 | ||
102 | static void invalidaterefs (void) | 98 | static void invalidaterefs (void) { |
103 | { | ||
104 | int i; | 99 | int i; |
105 | for (i=0; i<L->refSize; i++) | 100 | for (i=0; i<L->refSize; i++) |
106 | if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o)) | 101 | if (L->refArray[i].status == HOLD && !ismarked(&L->refArray[i].o)) |
@@ -109,8 +104,7 @@ static void invalidaterefs (void) | |||
109 | 104 | ||
110 | 105 | ||
111 | 106 | ||
112 | void luaC_hashcallIM (Hash *l) | 107 | void luaC_hashcallIM (Hash *l) { |
113 | { | ||
114 | TObject t; | 108 | TObject t; |
115 | ttype(&t) = LUA_T_ARRAY; | 109 | ttype(&t) = LUA_T_ARRAY; |
116 | for (; l; l=(Hash *)l->head.next) { | 110 | for (; l; l=(Hash *)l->head.next) { |
@@ -120,8 +114,7 @@ void luaC_hashcallIM (Hash *l) | |||
120 | } | 114 | } |
121 | 115 | ||
122 | 116 | ||
123 | void luaC_strcallIM (TaggedString *l) | 117 | void luaC_strcallIM (TaggedString *l) { |
124 | { | ||
125 | TObject o; | 118 | TObject o; |
126 | ttype(&o) = LUA_T_USERDATA; | 119 | ttype(&o) = LUA_T_USERDATA; |
127 | for (; l; l=(TaggedString *)l->head.next) | 120 | for (; l; l=(TaggedString *)l->head.next) |
@@ -133,8 +126,7 @@ void luaC_strcallIM (TaggedString *l) | |||
133 | 126 | ||
134 | 127 | ||
135 | 128 | ||
136 | static GCnode *listcollect (GCnode *l) | 129 | static GCnode *listcollect (GCnode *l) { |
137 | { | ||
138 | GCnode *frees = NULL; | 130 | GCnode *frees = NULL; |
139 | while (l) { | 131 | while (l) { |
140 | GCnode *next = l->next; | 132 | GCnode *next = l->next; |
@@ -151,8 +143,7 @@ static GCnode *listcollect (GCnode *l) | |||
151 | } | 143 | } |
152 | 144 | ||
153 | 145 | ||
154 | static void strmark (TaggedString *s) | 146 | static void strmark (TaggedString *s) { |
155 | { | ||
156 | if (!s->head.marked) | 147 | if (!s->head.marked) |
157 | s->head.marked = 1; | 148 | s->head.marked = 1; |
158 | } | 149 | } |
@@ -169,8 +160,7 @@ static void protomark (TProtoFunc *f) { | |||
169 | } | 160 | } |
170 | 161 | ||
171 | 162 | ||
172 | static void closuremark (Closure *f) | 163 | static void closuremark (Closure *f) { |
173 | { | ||
174 | if (!f->head.marked) { | 164 | if (!f->head.marked) { |
175 | int i; | 165 | int i; |
176 | f->head.marked = 1; | 166 | f->head.marked = 1; |
@@ -180,8 +170,7 @@ static void closuremark (Closure *f) | |||
180 | } | 170 | } |
181 | 171 | ||
182 | 172 | ||
183 | static void hashmark (Hash *h) | 173 | static void hashmark (Hash *h) { |
184 | { | ||
185 | if (!h->head.marked) { | 174 | if (!h->head.marked) { |
186 | int i; | 175 | int i; |
187 | h->head.marked = 1; | 176 | h->head.marked = 1; |
@@ -196,8 +185,7 @@ static void hashmark (Hash *h) | |||
196 | } | 185 | } |
197 | 186 | ||
198 | 187 | ||
199 | static void globalmark (void) | 188 | static void globalmark (void) { |
200 | { | ||
201 | TaggedString *g; | 189 | TaggedString *g; |
202 | for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){ | 190 | for (g=(TaggedString *)L->rootglobal.next; g; g=(TaggedString *)g->head.next){ |
203 | LUA_ASSERT(g->constindex >= 0, "userdata in global list"); | 191 | LUA_ASSERT(g->constindex >= 0, "userdata in global list"); |
@@ -209,8 +197,7 @@ static void globalmark (void) | |||
209 | } | 197 | } |
210 | 198 | ||
211 | 199 | ||
212 | static int markobject (TObject *o) | 200 | static int markobject (TObject *o) { |
213 | { | ||
214 | switch (ttype(o)) { | 201 | switch (ttype(o)) { |
215 | case LUA_T_USERDATA: case LUA_T_STRING: | 202 | case LUA_T_USERDATA: case LUA_T_STRING: |
216 | strmark(tsvalue(o)); | 203 | strmark(tsvalue(o)); |
@@ -231,8 +218,7 @@ static int markobject (TObject *o) | |||
231 | 218 | ||
232 | 219 | ||
233 | 220 | ||
234 | static void markall (void) | 221 | static void markall (void) { |
235 | { | ||
236 | luaD_travstack(markobject); /* mark stack objects */ | 222 | luaD_travstack(markobject); /* mark stack objects */ |
237 | globalmark(); /* mark global variable values and names */ | 223 | globalmark(); /* mark global variable values and names */ |
238 | travlock(); /* mark locked objects */ | 224 | travlock(); /* mark locked objects */ |
@@ -240,8 +226,7 @@ static void markall (void) | |||
240 | } | 226 | } |
241 | 227 | ||
242 | 228 | ||
243 | long lua_collectgarbage (long limit) | 229 | long lua_collectgarbage (long limit) { |
244 | { | ||
245 | unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */ | 230 | unsigned long recovered = L->nblocks; /* to subtract nblocks after gc */ |
246 | Hash *freetable; | 231 | Hash *freetable; |
247 | TaggedString *freestr; | 232 | TaggedString *freestr; |
@@ -267,8 +252,7 @@ long lua_collectgarbage (long limit) | |||
267 | } | 252 | } |
268 | 253 | ||
269 | 254 | ||
270 | void luaC_checkGC (void) | 255 | void luaC_checkGC (void) { |
271 | { | ||
272 | if (L->nblocks >= L->GCthreshold) | 256 | if (L->nblocks >= L->GCthreshold) |
273 | lua_collectgarbage(0); | 257 | lua_collectgarbage(0); |
274 | } | 258 | } |