aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-01 18:31:25 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-12-01 18:31:25 -0200
commit3393fd7f257397199c6ecd143f956a19ee4a0cf7 (patch)
tree3a0114c3f5954b07074bb51d9fa5616bc49b101d
parent00c122cc291cfb24e01a5c00f2c3503a6dfa073e (diff)
downloadlua-3393fd7f257397199c6ecd143f956a19ee4a0cf7.tar.gz
lua-3393fd7f257397199c6ecd143f956a19ee4a0cf7.tar.bz2
lua-3393fd7f257397199c6ecd143f956a19ee4a0cf7.zip
first version of "lua_close"
-rw-r--r--lgc.c10
-rw-r--r--lgc.h4
-rw-r--r--lstate.c28
-rw-r--r--lstring.c40
-rw-r--r--lstring.h5
-rw-r--r--lua.c6
-rw-r--r--lua.h3
7 files changed, 84 insertions, 12 deletions
diff --git a/lgc.c b/lgc.c
index fd7a6bcb..203e9d93 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.8 1997/11/19 17:29:23 roberto Exp roberto $ 2** $Id: lgc.c,v 1.9 1997/11/27 15:59:25 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*/
@@ -108,7 +108,7 @@ static void invalidaterefs (void)
108 108
109 109
110 110
111static void hashcallIM (Hash *l) 111void luaC_hashcallIM (Hash *l)
112{ 112{
113 TObject t; 113 TObject t;
114 ttype(&t) = LUA_T_ARRAY; 114 ttype(&t) = LUA_T_ARRAY;
@@ -119,7 +119,7 @@ static void hashcallIM (Hash *l)
119} 119}
120 120
121 121
122static void strcallIM (TaggedString *l) 122void luaC_strcallIM (TaggedString *l)
123{ 123{
124 TObject o; 124 TObject o;
125 ttype(&o) = LUA_T_USERDATA; 125 ttype(&o) = LUA_T_USERDATA;
@@ -259,8 +259,8 @@ long lua_collectgarbage (long limit)
259 freefunc = (TProtoFunc *)listcollect(&(L->rootproto)); 259 freefunc = (TProtoFunc *)listcollect(&(L->rootproto));
260 freeclos = (Closure *)listcollect(&(L->rootcl)); 260 freeclos = (Closure *)listcollect(&(L->rootcl));
261 L->GCthreshold *= 4; /* to avoid GC during GC */ 261 L->GCthreshold *= 4; /* to avoid GC during GC */
262 hashcallIM(freetable); /* GC tag methods for tables */ 262 luaC_hashcallIM(freetable); /* GC tag methods for tables */
263 strcallIM(freestr); /* GC tag methods for userdata */ 263 luaC_strcallIM(freestr); /* GC tag methods for userdata */
264 luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */ 264 luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
265 luaH_free(freetable); 265 luaH_free(freetable);
266 luaS_free(freestr); 266 luaS_free(freestr);
diff --git a/lgc.h b/lgc.h
index a7a9a77a..60a0b1ec 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 1.2 1997/10/23 16:26:37 roberto Exp roberto $ 2** $Id: lgc.h,v 1.3 1997/11/19 17:29:23 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*/
@@ -14,6 +14,8 @@
14void luaC_checkGC (void); 14void luaC_checkGC (void);
15TObject* luaC_getref (int ref); 15TObject* luaC_getref (int ref);
16int luaC_ref (TObject *o, int lock); 16int luaC_ref (TObject *o, int lock);
17void luaC_hashcallIM (Hash *l);
18void luaC_strcallIM (TaggedString *l);
17 19
18 20
19#endif 21#endif
diff --git a/lstate.c b/lstate.c
index 69100ba3..9fd27212 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.1 1997/11/19 17:31:19 roberto Exp roberto $ 2** $Id: lstate.c,v 1.2 1997/11/27 15:59:25 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -7,6 +7,8 @@
7 7
8#include "lbuiltin.h" 8#include "lbuiltin.h"
9#include "ldo.h" 9#include "ldo.h"
10#include "lfunc.h"
11#include "lgc.h"
10#include "llex.h" 12#include "llex.h"
11#include "lmem.h" 13#include "lmem.h"
12#include "lstate.h" 14#include "lstate.h"
@@ -48,3 +50,27 @@ void lua_open (void)
48 luaB_predefine(); 50 luaB_predefine();
49} 51}
50 52
53
54void lua_close (void)
55{
56 TaggedString *alludata = luaS_collectudata();
57 L->GCthreshold = MAX_INT; /* to avoid GC during GC */
58 luaC_hashcallIM((Hash *)L->roottable.next); /* GC t.methods for tables */
59 luaC_strcallIM(alludata); /* GC tag methods for userdata */
60 luaD_gcIM(&luaO_nilobject); /* GC tag method for nil (signal end of GC) */
61 luaH_free((Hash *)L->roottable.next);
62 luaF_freeproto((TProtoFunc *)L->rootproto.next);
63 luaF_freeclosure((Closure *)L->rootcl.next);
64 luaS_free(alludata);
65 luaS_freeall();
66 luaM_free(L->stack.stack);
67 luaM_free(L->IMtable);
68 luaM_free(L->refArray);
69 luaM_free(L->Mbuffer);
70 luaM_free(L);
71 L = NULL;
72#if DEBUG
73 printf("total de blocos: %ld\n", numblocks);
74 printf("total de memoria: %ld\n", totalmem);
75#endif
76}
diff --git a/lstring.c b/lstring.c
index b4e435df..6f3ba519 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 1.5 1997/11/19 17:29:23 roberto Exp roberto $ 2** $Id: lstring.c,v 1.6 1997/11/21 19:00:46 roberto Exp roberto $
3** String table (keep all strings handled by Lua) 3** String table (keep all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -195,6 +195,44 @@ TaggedString *luaS_collector (void)
195} 195}
196 196
197 197
198TaggedString *luaS_collectudata (void)
199{
200 TaggedString *frees = NULL;
201 int i;
202 L->rootglobal.next = NULL; /* empty list of globals */
203 for (i=0; i<NUM_HASHS; i++) {
204 stringtable *tb = &L->string_root[i];
205 int j;
206 for (j=0; j<tb->size; j++) {
207 TaggedString *t = tb->hash[j];
208 if (t == NULL || t == &EMPTY || t->constindex != -1)
209 continue; /* get only user datas */
210 t->head.next = (GCnode *)frees;
211 frees = t;
212 tb->hash[j] = &EMPTY;
213 }
214 }
215 return frees;
216}
217
218
219void luaS_freeall (void)
220{
221 int i;
222 for (i=0; i<NUM_HASHS; i++) {
223 stringtable *tb = &L->string_root[i];
224 int j;
225 for (j=0; j<tb->size; j++) {
226 TaggedString *t = tb->hash[j];
227 if (t == &EMPTY) continue;
228 luaM_free(t);
229 }
230 luaM_free(tb->hash);
231 }
232 luaM_free(L->string_root);
233}
234
235
198void luaS_rawsetglobal (TaggedString *ts, TObject *newval) 236void luaS_rawsetglobal (TaggedString *ts, TObject *newval)
199{ 237{
200 ts->u.globalval = *newval; 238 ts->u.globalval = *newval;
diff --git a/lstring.h b/lstring.h
index b2c421e2..5f8d01f4 100644
--- a/lstring.h
+++ b/lstring.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.h,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $ 2** $Id: lstring.h,v 1.5 1997/11/26 18:53:45 roberto Exp roberto $
3** String table (keep all strings handled by Lua) 3** String table (keep all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -20,5 +20,8 @@ TaggedString *luaS_newfixedstring (char *str);
20void luaS_rawsetglobal (TaggedString *ts, TObject *newval); 20void luaS_rawsetglobal (TaggedString *ts, TObject *newval);
21char *luaS_travsymbol (int (*fn)(TObject *)); 21char *luaS_travsymbol (int (*fn)(TObject *));
22int luaS_globaldefined (char *name); 22int luaS_globaldefined (char *name);
23TaggedString *luaS_collectudata (void);
24void luaS_freeall (void);
25
23 26
24#endif 27#endif
diff --git a/lua.c b/lua.c
index 2484d3bc..2ebfc951 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.4 1997/11/19 17:29:23 roberto Exp roberto $ 2** $Id: lua.c,v 1.5 1997/11/21 19:00:46 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -82,7 +82,9 @@ int main (int argc, char *argv[])
82 } 82 }
83 } 83 }
84 } 84 }
85/* lua_close(); */ 85#if DEBUG
86 lua_close();
87#endif
86 return 0; 88 return 0;
87} 89}
88 90
diff --git a/lua.h b/lua.h
index 7d05b2e9..3cc871dc 100644
--- a/lua.h
+++ b/lua.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.h,v 1.6 1997/11/27 15:59:25 roberto Exp roberto $ 2** $Id: lua.h,v 1.7 1997/11/27 18:25:14 roberto Exp roberto $
3** Lua - An Extensible Extension Language 3** Lua - An Extensible Extension Language
4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 4** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
5** e-mail: lua@tecgraf.puc-rio.br 5** e-mail: lua@tecgraf.puc-rio.br
@@ -55,6 +55,7 @@ typedef unsigned int lua_Object;
55 55
56 56
57void lua_open (void); 57void lua_open (void);
58void lua_close (void);
58 59
59lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ 60lua_Object lua_settagmethod (int tag, char *event); /* In: new method */
60lua_Object lua_gettagmethod (int tag, char *event); 61lua_Object lua_gettagmethod (int tag, char *event);