From abc69145287ca5395545c4d11f86ac01ef656b6b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 17 Jan 2018 06:18:43 -0500 Subject: [PATCH] [libcalamares] Enforce singleton-ness of CalamaresPython::Helper - unset instance pointer on destruction - make constructor private, and the instance accessor should create an instance if there isn't one. --- src/libcalamares/JobQueue.cpp | 3 --- src/libcalamares/PythonHelper.cpp | 4 +++- src/libcalamares/PythonHelper.h | 2 +- src/libcalamares/PythonJob.cpp | 6 ++++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/libcalamares/JobQueue.cpp b/src/libcalamares/JobQueue.cpp index 3a2e9ff03..b5bdf0543 100644 --- a/src/libcalamares/JobQueue.cpp +++ b/src/libcalamares/JobQueue.cpp @@ -41,9 +41,6 @@ public: , m_queue( queue ) , m_jobIndex( 0 ) { -#ifdef WITH_PYTHON - new CalamaresPython::Helper( this ); -#endif } void setJobs( const JobList& jobs ) diff --git a/src/libcalamares/PythonHelper.cpp b/src/libcalamares/PythonHelper.cpp index 4f2f30e76..f274ac276 100644 --- a/src/libcalamares/PythonHelper.cpp +++ b/src/libcalamares/PythonHelper.cpp @@ -231,7 +231,9 @@ Helper::Helper( QObject* parent ) } Helper::~Helper() -{} +{ + s_instance = nullptr; +} boost::python::dict diff --git a/src/libcalamares/PythonHelper.h b/src/libcalamares/PythonHelper.h index e552a869d..d48e5eaab 100644 --- a/src/libcalamares/PythonHelper.h +++ b/src/libcalamares/PythonHelper.h @@ -48,7 +48,6 @@ class Helper : public QObject { Q_OBJECT public: - explicit Helper( QObject* parent = nullptr ); virtual ~Helper(); boost::python::dict createCleanNamespace(); @@ -57,6 +56,7 @@ public: private: friend Helper* Calamares::PythonJob::helper(); + explicit Helper( QObject* parent = nullptr ); static Helper* s_instance; boost::python::object m_mainModule; diff --git a/src/libcalamares/PythonJob.cpp b/src/libcalamares/PythonJob.cpp index faf2fa72d..a9fe4463e 100644 --- a/src/libcalamares/PythonJob.cpp +++ b/src/libcalamares/PythonJob.cpp @@ -381,8 +381,10 @@ PythonJob::emitProgress( qreal progressValue ) CalamaresPython::Helper* PythonJob::helper() { - return CalamaresPython::Helper::s_instance; - + auto ptr = CalamaresPython::Helper::s_instance; + if (!ptr) + ptr = new CalamaresPython::Helper; + return ptr; }