-rw-r--r-- | gsl-shell.c | 6 | ||||
-rw-r--r-- | lua-utils.c | 13 | ||||
-rw-r--r-- | lua-utils.h | 3 | ||||
-rw-r--r-- | makeflags | 4 |
diff --git a/gsl-shell.c b/gsl-shell.c index 97b6893d..9638df04 100644 --- a/gsl-shell.c +++ b/gsl-shell.c @@ -556,6 +556,12 @@ int main (int argc, char **argv) { s.argv = argv; status = lua_cpcall(L, &pmain, &s); report(L, status); + + /* we clear the globals stack and make a full gc collect to avoid + problem with finalizers execution order for plots and + graphical objects. */ + mlua_table_clear (L, LUA_GLOBALSINDEX); + lua_gc (L, LUA_GCCOLLECT, 0); lua_close(L); pthread_mutex_destroy (gsl_shell_mutex); diff --git a/lua-utils.c b/lua-utils.c index d9006b30..0d4c9aa7 100644 --- a/lua-utils.c +++ b/lua-utils.c @@ -302,3 +302,16 @@ mlua_plotref_add (lua_State *L, int key_index, int val_index) lua_rawset (L, -3); lua_pop (L, 1); } + +void +mlua_table_clear (lua_State *L, int index) +{ + lua_pushnil (L); /* first key */ + while (lua_next(L, index) != 0) + { + lua_pop (L, 1); + lua_pushvalue (L, -1); + lua_pushnil (L); + lua_rawset (L, index); + } +} diff --git a/lua-utils.h b/lua-utils.h index b7382863..633c4375 100644 --- a/lua-utils.h +++ b/lua-utils.h @@ -66,12 +66,13 @@ extern lua_Number mlua_named_number (lua_State *L, int index, extern void mlua_fenv_set (lua_State *L, int index, int fenv_index); extern void mlua_fenv_get (lua_State *L, int index, int fenv_index); +extern void mlua_table_clear (lua_State *L, int index); + extern void mlua_set_fenv_ref (lua_State *L, int refidx); extern int mlua_window_ref (lua_State *L, int index); extern void mlua_window_unref (lua_State *L, int id); extern void prepare_window_ref_table (lua_State *L); - extern void prepare_plotref_table (lua_State *L); extern void mlua_plotref_add (lua_State *L, int key_index, int val_index); @@ -8,6 +8,6 @@ ifeq ($(strip $(DEBUG)), yes) CFLAGS = -g -Wall CXXFLAGS = -g -Wall else - CFLAGS = -O2 -Wall - CXXFLAGS = -O2 -fno-exceptions -fno-rtti -Wall + CFLAGS = -O3 -Wall + CXXFLAGS = -O3 -fno-exceptions -fno-rtti -Wall endif |