diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-01 18:31:25 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-12-01 18:31:25 -0200 |
| commit | 3393fd7f257397199c6ecd143f956a19ee4a0cf7 (patch) | |
| tree | 3a0114c3f5954b07074bb51d9fa5616bc49b101d | |
| parent | 00c122cc291cfb24e01a5c00f2c3503a6dfa073e (diff) | |
| download | lua-3393fd7f257397199c6ecd143f956a19ee4a0cf7.tar.gz lua-3393fd7f257397199c6ecd143f956a19ee4a0cf7.tar.bz2 lua-3393fd7f257397199c6ecd143f956a19ee4a0cf7.zip | |
first version of "lua_close"
| -rw-r--r-- | lgc.c | 10 | ||||
| -rw-r--r-- | lgc.h | 4 | ||||
| -rw-r--r-- | lstate.c | 28 | ||||
| -rw-r--r-- | lstring.c | 40 | ||||
| -rw-r--r-- | lstring.h | 5 | ||||
| -rw-r--r-- | lua.c | 6 | ||||
| -rw-r--r-- | lua.h | 3 |
7 files changed, 84 insertions, 12 deletions
| @@ -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 | ||
| 111 | static void hashcallIM (Hash *l) | 111 | void 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 | ||
| 122 | static void strcallIM (TaggedString *l) | 122 | void 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); |
| @@ -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 @@ | |||
| 14 | void luaC_checkGC (void); | 14 | void luaC_checkGC (void); |
| 15 | TObject* luaC_getref (int ref); | 15 | TObject* luaC_getref (int ref); |
| 16 | int luaC_ref (TObject *o, int lock); | 16 | int luaC_ref (TObject *o, int lock); |
| 17 | void luaC_hashcallIM (Hash *l); | ||
| 18 | void luaC_strcallIM (TaggedString *l); | ||
| 17 | 19 | ||
| 18 | 20 | ||
| 19 | #endif | 21 | #endif |
| @@ -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 | |||
| 54 | void 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 | } | ||
| @@ -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 | ||
| 198 | TaggedString *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 | |||
| 219 | void 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 | |||
| 198 | void luaS_rawsetglobal (TaggedString *ts, TObject *newval) | 236 | void luaS_rawsetglobal (TaggedString *ts, TObject *newval) |
| 199 | { | 237 | { |
| 200 | ts->u.globalval = *newval; | 238 | ts->u.globalval = *newval; |
| @@ -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); | |||
| 20 | void luaS_rawsetglobal (TaggedString *ts, TObject *newval); | 20 | void luaS_rawsetglobal (TaggedString *ts, TObject *newval); |
| 21 | char *luaS_travsymbol (int (*fn)(TObject *)); | 21 | char *luaS_travsymbol (int (*fn)(TObject *)); |
| 22 | int luaS_globaldefined (char *name); | 22 | int luaS_globaldefined (char *name); |
| 23 | TaggedString *luaS_collectudata (void); | ||
| 24 | void luaS_freeall (void); | ||
| 25 | |||
| 23 | 26 | ||
| 24 | #endif | 27 | #endif |
| @@ -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 | ||
| @@ -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 | ||
| 57 | void lua_open (void); | 57 | void lua_open (void); |
| 58 | void lua_close (void); | ||
| 58 | 59 | ||
| 59 | lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ | 60 | lua_Object lua_settagmethod (int tag, char *event); /* In: new method */ |
| 60 | lua_Object lua_gettagmethod (int tag, char *event); | 61 | lua_Object lua_gettagmethod (int tag, char *event); |
