diff options
author | Benedikt Tutzer <e1225461@student.tuwien.ac.at> | 2018-08-20 14:44:03 +0200 |
---|---|---|
committer | Benedikt Tutzer <e1225461@student.tuwien.ac.at> | 2018-08-20 14:44:03 +0200 |
commit | 5864db3c2bf353d4ee124d35aa2f911c4249edbc (patch) | |
tree | 2c6962b3114b44f91b3fbe016b9afc5fb38f0a0f | |
parent | d79a2808cf2446fa21d91a6141f6fbe2318c03ec (diff) | |
download | yosys-5864db3c2bf353d4ee124d35aa2f911c4249edbc.tar.gz yosys-5864db3c2bf353d4ee124d35aa2f911c4249edbc.tar.bz2 yosys-5864db3c2bf353d4ee124d35aa2f911c4249edbc.zip |
Fixed issue when using a python plugin in the yosys shell
-rw-r--r-- | kernel/python_wrappers.cc | 11 | ||||
-rw-r--r-- | kernel/yosys.cc | 16 | ||||
-rw-r--r-- | kernel/yosys.h | 5 |
3 files changed, 28 insertions, 4 deletions
diff --git a/kernel/python_wrappers.cc b/kernel/python_wrappers.cc index 197be0853..af1f80929 100644 --- a/kernel/python_wrappers.cc +++ b/kernel/python_wrappers.cc @@ -2783,10 +2783,13 @@ namespace YOSYS_PYTHON { struct Initializer { Initializer() { - Yosys::log_streams.push_back(&std::cout); - Yosys::log_error_stderr = true; - Yosys::yosys_setup(); - Yosys::yosys_banner(); + if(!Yosys::yosys_already_setup()) + { + Yosys::log_streams.push_back(&std::cout); + Yosys::log_error_stderr = true; + Yosys::yosys_setup(); + Yosys::yosys_banner(); + } } Initializer(Initializer const &) {} diff --git a/kernel/yosys.cc b/kernel/yosys.cc index 8e16ba01d..8380fe75d 100644 --- a/kernel/yosys.cc +++ b/kernel/yosys.cc @@ -55,6 +55,16 @@ # include <sys/sysctl.h> #endif +#ifdef WITH_PYTHON +#if PY_MAJOR_VERSION >= 3 +# define INIT_MODULE PyInit_libyosys + extern "C" PyObject* INIT_MODULE(); +#else +# define INIT_MODULE initlibyosys + extern "C" void INIT_MODULE(); +#endif +#endif + #include <limits.h> #include <errno.h> @@ -482,6 +492,7 @@ void yosys_setup() IdString::get_reference(empty_id.index_); #ifdef WITH_PYTHON + PyImport_AppendInittab((char*)"libyosys", INIT_MODULE); Py_Initialize(); PyRun_SimpleString("import sys"); PyRun_SimpleString("sys.path.append(\"./\")"); @@ -496,6 +507,11 @@ void yosys_setup() log_push(); } +bool yosys_already_setup() +{ + return already_setup; +} + bool already_shutdown = false; void yosys_shutdown() diff --git a/kernel/yosys.h b/kernel/yosys.h index 4380a5b69..6ed0f8b20 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -278,6 +278,11 @@ namespace hashlib { } void yosys_setup(); + +#ifdef WITH_PYTHON +bool yosys_already_setup(); +#endif + void yosys_shutdown(); #ifdef YOSYS_ENABLE_TCL |