From e1249970c2d058d173e7b1c1dc7deab1ccd68b7d Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 26 May 1997 11:42:51 -0300 Subject: [PATCH] new API function to force garbage collection. --- inout.c | 8 +++++++- lua.h | 5 ++++- table.c | 13 +++++++------ 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 @@ ** Also provides some predefined lua functions. */ -char *rcs_inout="$Id: inout.c,v 2.57 1997/04/06 14:14:27 roberto Exp roberto $"; +char *rcs_inout="$Id: inout.c,v 2.58 1997/04/15 17:32:47 roberto Exp roberto $"; #include #include @@ -310,6 +310,11 @@ static void rawsettable (void) } +static void luaI_collectgarbage (void) +{ + lua_pushnumber(lua_collectgarbage(luaL_opt_number(1, 0))); +} + /* ** Internal functions @@ -320,6 +325,7 @@ static struct { } int_funcs[] = { {"assert", luaI_assert}, {"call", luaI_call}, + {"callgc", luaI_collectgarbage}, {"dofile", lua_internaldofile}, {"dostring", lua_internaldostring}, {"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 @@ ** LUA - An Extensible Extension Language ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil ** e-mail: lua@tecgraf.puc-rio.br -** $Id: lua.h,v 4.2 1997/04/04 22:24:51 roberto Exp roberto $ +** $Id: lua.h,v 4.3 1997/04/15 16:52:20 roberto Exp roberto $ */ @@ -84,6 +84,9 @@ void lua_unref (int ref); lua_Object lua_createtable (void); +long lua_collectgarbage (long limit); + + /* =============================================================== */ /* some useful macros */ diff --git a/table.c b/table.c index 86266a96..1f65b411 100644 --- a/table.c +++ b/table.c @@ -3,7 +3,7 @@ ** Module to control static tables */ -char *rcs_table="$Id: table.c,v 2.68 1997/04/07 14:48:53 roberto Exp roberto $"; +char *rcs_table="$Id: table.c,v 2.69 1997/05/14 18:38:29 roberto Exp roberto $"; #include "luamem.h" #include "auxlib.h" @@ -29,7 +29,7 @@ Word lua_nconstant = 0; static Long lua_maxconstant = 0; -#define GARBAGE_BLOCK 50 +#define GARBAGE_BLOCK 100 void luaI_initsymbol (void) @@ -189,7 +189,7 @@ static void markall (void) } -static void lua_collectgarbage (void) +long lua_collectgarbage (long limit) { long recovered = 0; Hash *freetable; @@ -199,21 +199,22 @@ static void lua_collectgarbage (void) freetable = luaI_hashcollector(&recovered); freestr = luaI_strcollector(&recovered); freefunc = luaI_funccollector(&recovered); - gc_block = 2*(gc_block-recovered); gc_nentity -= recovered; + gc_block = (limit == 0) ? 2*(gc_block-recovered) : gc_nentity+limit; luaI_hashcallIM(freetable); luaI_strcallIM(freestr); call_nilIM(); luaI_hashfree(freetable); luaI_strfree(freestr); luaI_funcfree(freefunc); + return recovered; } void lua_pack (void) { - if (gc_nentity++ >= gc_block) - lua_collectgarbage(); + if (++gc_nentity >= gc_block) + lua_collectgarbage(0); }