Avoid to call lua_open in the gsl_shell constructor - gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrancesco Abbate <francesco.bbt@gmail.com>2012年07月23日 16:46:07 +0200
committerFrancesco Abbate <francesco.bbt@gmail.com>2012年07月23日 16:46:07 +0200
commitab41382754cda0fcd492d15a45e685e4a8bb5dbd (patch)
treeb652aa20033920454e8c7e0a5c24499755d25b70
parent1ad02b6c7e46e68dfa37d179f2cc0335184de8a9 (diff)
downloadgsl-shell-ab41382754cda0fcd492d15a45e685e4a8bb5dbd.tar.gz
Avoid to call lua_open in the gsl_shell constructor
Diffstat
-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
4 files changed, 12 insertions, 4 deletions
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
generated by cgit v1.2.3 (git 2.39.1) at 2025年10月02日 14:04:32 +0000

AltStyle によって変換されたページ (->オリジナル) /