From ae5890e01739fee3b9adf5f9402f9d6c0e1c974f Mon Sep 17 00:00:00 2001 From: Marco Biasini <mvbiasini@gmail.com> Date: Fri, 23 Aug 2013 08:39:28 +0200 Subject: [PATCH] fix another segfault on exit --- .../gui/src/python_shell/python_interpreter_worker.cc | 8 ++++++-- modules/io/pymod/export_pdb_io.cc | 2 +- modules/io/src/mol/io_profile.cc | 2 ++ modules/io/src/mol/io_profile.hh | 10 ++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/gui/src/python_shell/python_interpreter_worker.cc b/modules/gui/src/python_shell/python_interpreter_worker.cc index 47dbcfc9e..68f38a247 100644 --- a/modules/gui/src/python_shell/python_interpreter_worker.cc +++ b/modules/gui/src/python_shell/python_interpreter_worker.cc @@ -53,8 +53,12 @@ PythonInterpreterWorker::PythonInterpreterWorker(): PythonInterpreterWorker::~PythonInterpreterWorker() { - // we have to manually run the exit functions because we cannot use Py_Finalize due to some problems in boost python - run_command_(std::pair<unsigned int, QString>(0,"import atexit\natexit._run_exitfuncs()\n")); + // we have to manually run the exit functions because we cannot use + // Py_Finalize due to some problems in boost python. + run_command_(std::pair<unsigned int, QString>(0, + "import atexit\n" + "atexit._run_exitfuncs()\n")); + //Py_Finalize(); } void PythonInterpreterWorker::Wake() diff --git a/modules/io/pymod/export_pdb_io.cc b/modules/io/pymod/export_pdb_io.cc index 6fe425aa7..237b2918c 100644 --- a/modules/io/pymod/export_pdb_io.cc +++ b/modules/io/pymod/export_pdb_io.cc @@ -34,7 +34,7 @@ void (PDBWriter::*write_a)(const mol::EntityHandle&)=&PDBWriter::Write; void (PDBWriter::*write_b)(const mol::EntityView&)=&PDBWriter::Write; void remove_profiles() { - IOProfileRegistry::Instance().RemoveProfiles(); + IOProfileRegistry::RemoveProfiles(); } void export_pdb_io() diff --git a/modules/io/src/mol/io_profile.cc b/modules/io/src/mol/io_profile.cc index e48837e80..1d9f77fa0 100644 --- a/modules/io/src/mol/io_profile.cc +++ b/modules/io/src/mol/io_profile.cc @@ -2,6 +2,7 @@ namespace ost { namespace io { +bool IOProfileRegistry::alive = false; IOProfileRegistry& IOProfileRegistry::Instance() { static IOProfileRegistry reg; @@ -11,6 +12,7 @@ IOProfileRegistry& IOProfileRegistry::Instance() IOProfileRegistry::IOProfileRegistry(): profiles_() { + IOProfileRegistry::alive = true; profiles_["DEFAULT"]=IOProfile(); } diff --git a/modules/io/src/mol/io_profile.hh b/modules/io/src/mol/io_profile.hh index 188ed158b..4f14b35e3 100644 --- a/modules/io/src/mol/io_profile.hh +++ b/modules/io/src/mol/io_profile.hh @@ -85,12 +85,18 @@ public: } IOProfile& GetDefault() { return profiles_["DEFAULT"]; } - void RemoveProfiles() { - profiles_.clear(); + static void RemoveProfiles() { + if (IOProfileRegistry::alive) { + IOProfileRegistry::Instance().profiles_.clear(); + } + } + ~IOProfileRegistry() { + alive = false; } private: IOProfileRegistry(); std::map<String, IOProfile> profiles_; + static bool alive; }; }} -- GitLab