aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-05-26 11:42:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-05-26 11:42:51 -0300
commite1249970c2d058d173e7b1c1dc7deab1ccd68b7d (patch)
tree7692598a31f8cb2da8902daf705cb8ba0915bed0
parent9d6f4e48a663691cdf1612f14ca7c66b608f98f7 (diff)
downloadlua-e1249970c2d058d173e7b1c1dc7deab1ccd68b7d.tar.gz
lua-e1249970c2d058d173e7b1c1dc7deab1ccd68b7d.tar.bz2
lua-e1249970c2d058d173e7b1c1dc7deab1ccd68b7d.zip
new API function to force garbage collection.
-rw-r--r--inout.c8
-rw-r--r--lua.h5
-rw-r--r--table.c13
3 files changed, 18 insertions, 8 deletions
diff --git a/inout.c b/inout.c
index 6b3e490f..d0bd707e 100644
--- a/inout.c
+++ b/inout.c
@@ -5,7 +5,7 @@
5** Also provides some predefined lua functions. 5** Also provides some predefined lua functions.
6*/ 6*/
7 7
8char *rcs_inout="$Id: inout.c,v 2.57 1997/04/06 14:14:27 roberto Exp roberto $"; 8char *rcs_inout="$Id: inout.c,v 2.58 1997/04/15 17:32:47 roberto Exp roberto $";
9 9
10#include <stdio.h> 10#include <stdio.h>
11#include <string.h> 11#include <string.h>
@@ -310,6 +310,11 @@ static void rawsettable (void)
310} 310}
311 311
312 312
313static void luaI_collectgarbage (void)
314{
315 lua_pushnumber(lua_collectgarbage(luaL_opt_number(1, 0)));
316}
317
313 318
314/* 319/*
315** Internal functions 320** Internal functions
@@ -320,6 +325,7 @@ static struct {
320} int_funcs[] = { 325} int_funcs[] = {
321 {"assert", luaI_assert}, 326 {"assert", luaI_assert},
322 {"call", luaI_call}, 327 {"call", luaI_call},
328 {"callgc", luaI_collectgarbage},
323 {"dofile", lua_internaldofile}, 329 {"dofile", lua_internaldofile},
324 {"dostring", lua_internaldostring}, 330 {"dostring", lua_internaldostring},
325 {"error", luaI_error}, 331 {"error", luaI_error},
diff --git a/lua.h b/lua.h
index f5bbf008..b6c99e57 100644
--- a/lua.h
+++ b/lua.h
@@ -2,7 +2,7 @@
2** LUA - An Extensible Extension Language 2** LUA - An Extensible Extension Language
3** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil 3** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
4** e-mail: lua@tecgraf.puc-rio.br 4** e-mail: lua@tecgraf.puc-rio.br
5** $Id: lua.h,v 4.2 1997/04/04 22:24:51 roberto Exp roberto $ 5** $Id: lua.h,v 4.3 1997/04/15 16:52:20 roberto Exp roberto $
6*/ 6*/
7 7
8 8
@@ -84,6 +84,9 @@ void lua_unref (int ref);
84lua_Object lua_createtable (void); 84lua_Object lua_createtable (void);
85 85
86 86
87long lua_collectgarbage (long limit);
88
89
87/* =============================================================== */ 90/* =============================================================== */
88/* some useful macros */ 91/* some useful macros */
89 92
diff --git a/table.c b/table.c
index 86266a96..1f65b411 100644
--- a/table.c
+++ b/table.c
@@ -3,7 +3,7 @@
3** Module to control static tables 3** Module to control static tables
4*/ 4*/
5 5
6char *rcs_table="$Id: table.c,v 2.68 1997/04/07 14:48:53 roberto Exp roberto $"; 6char *rcs_table="$Id: table.c,v 2.69 1997/05/14 18:38:29 roberto Exp roberto $";
7 7
8#include "luamem.h" 8#include "luamem.h"
9#include "auxlib.h" 9#include "auxlib.h"
@@ -29,7 +29,7 @@ Word lua_nconstant = 0;
29static Long lua_maxconstant = 0; 29static Long lua_maxconstant = 0;
30 30
31 31
32#define GARBAGE_BLOCK 50 32#define GARBAGE_BLOCK 100
33 33
34 34
35void luaI_initsymbol (void) 35void luaI_initsymbol (void)
@@ -189,7 +189,7 @@ static void markall (void)
189} 189}
190 190
191 191
192static void lua_collectgarbage (void) 192long lua_collectgarbage (long limit)
193{ 193{
194 long recovered = 0; 194 long recovered = 0;
195 Hash *freetable; 195 Hash *freetable;
@@ -199,21 +199,22 @@ static void lua_collectgarbage (void)
199 freetable = luaI_hashcollector(&recovered); 199 freetable = luaI_hashcollector(&recovered);
200 freestr = luaI_strcollector(&recovered); 200 freestr = luaI_strcollector(&recovered);
201 freefunc = luaI_funccollector(&recovered); 201 freefunc = luaI_funccollector(&recovered);
202 gc_block = 2*(gc_block-recovered);
203 gc_nentity -= recovered; 202 gc_nentity -= recovered;
203 gc_block = (limit == 0) ? 2*(gc_block-recovered) : gc_nentity+limit;
204 luaI_hashcallIM(freetable); 204 luaI_hashcallIM(freetable);
205 luaI_strcallIM(freestr); 205 luaI_strcallIM(freestr);
206 call_nilIM(); 206 call_nilIM();
207 luaI_hashfree(freetable); 207 luaI_hashfree(freetable);
208 luaI_strfree(freestr); 208 luaI_strfree(freestr);
209 luaI_funcfree(freefunc); 209 luaI_funcfree(freefunc);
210 return recovered;
210} 211}
211 212
212 213
213void lua_pack (void) 214void lua_pack (void)
214{ 215{
215 if (gc_nentity++ >= gc_block) 216 if (++gc_nentity >= gc_block)
216 lua_collectgarbage(); 217 lua_collectgarbage(0);
217} 218}
218 219
219 220