author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年07月23日 16:46:07 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年07月23日 16:46:07 +0200 |
commit | ab41382754cda0fcd492d15a45e685e4a8bb5dbd (patch) | |
tree | b652aa20033920454e8c7e0a5c24499755d25b70 | |
parent | 1ad02b6c7e46e68dfa37d179f2cc0335184de8a9 (diff) | |
download | gsl-shell-ab41382754cda0fcd492d15a45e685e4a8bb5dbd.tar.gz |
-rw-r--r-- | fox-gui/gsl_shell_interp.cpp | 3 | ||||
-rw-r--r-- | fox-gui/gsl_shell_interp.h | 9 | ||||
-rw-r--r-- | gsl-shell-jit.c | 1 | ||||
-rw-r--r-- | lua-gsl/lua-gsl.c | 3 |
diff --git a/fox-gui/gsl_shell_interp.cpp b/fox-gui/gsl_shell_interp.cpp index d4a3aeca..0aba9ccb 100644 --- a/fox-gui/gsl_shell_interp.cpp +++ b/fox-gui/gsl_shell_interp.cpp @@ -128,6 +128,8 @@ static int incomplete(lua_State *L, int status) void gsl_shell::init() { + gsl_shell_open(this); + int status = lua_cpcall(this->L, pinit, NULL); if (unlikely(stderr_report(this->L, status))) @@ -140,6 +142,7 @@ void gsl_shell::init() void gsl_shell::close() { lua_close(this->L); + this->L = NULL; } int gsl_shell::error_report(int status) diff --git a/fox-gui/gsl_shell_interp.h b/fox-gui/gsl_shell_interp.h index 46b4f58a..d4669f99 100644 --- a/fox-gui/gsl_shell_interp.h +++ b/fox-gui/gsl_shell_interp.h @@ -9,6 +9,7 @@ extern "C" { #include "pthreadpp.h" #include "lua-gsl.h" #include "strpp.h" +#include "fatal.h" class gsl_shell : public gsl_shell_state { public: @@ -17,10 +18,14 @@ public: gsl_shell() { gsl_shell_init(this); - gsl_shell_open(this); } - ~gsl_shell() { gsl_shell_free(this); } + ~gsl_shell() + { + if (unlikely(this->L == NULL)) + fatal_exception("Attempt to dispose an open Lua state"); + gsl_shell_free(this); + } virtual void init(); virtual void close(); diff --git a/gsl-shell-jit.c b/gsl-shell-jit.c index 3e0446dd..f7692f8a 100644 --- a/gsl-shell-jit.c +++ b/gsl-shell-jit.c @@ -661,6 +661,7 @@ int main(int argc, char **argv) #ifdef USE_READLINE initialize_readline(); #endif + gsl_shell_init(gsl_shell); gsl_shell_open(gsl_shell); pthread_mutex_lock(&gsl_shell->exec_mutex); diff --git a/lua-gsl/lua-gsl.c b/lua-gsl/lua-gsl.c index 0f4524bc..004dba16 100644 --- a/lua-gsl/lua-gsl.c +++ b/lua-gsl/lua-gsl.c @@ -40,8 +40,6 @@ gsl_shell_open (struct gsl_shell_state *gs) fatal_exception("cannot create state: not enough memory"); global_state = gs; - - gsl_shell_init(gs); } void @@ -50,6 +48,7 @@ gsl_shell_init (struct gsl_shell_state *gs) pthread_mutex_init (&gs->exec_mutex, NULL); pthread_mutex_init (&gs->shutdown_mutex, NULL); gs->is_shutting_down = 0; + gs->L = NULL; } void |