[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.
This commit is contained in:
Adriaan de Groot 2018-01-17 06:18:43 -05:00
parent 86b899566e
commit abc6914528
4 changed files with 8 additions and 7 deletions

View File

@ -41,9 +41,6 @@ public:
, m_queue( queue )
, m_jobIndex( 0 )
{
#ifdef WITH_PYTHON
new CalamaresPython::Helper( this );
#endif
}
void setJobs( const JobList& jobs )

View File

@ -231,7 +231,9 @@ Helper::Helper( QObject* parent )
}
Helper::~Helper()
{}
{
s_instance = nullptr;
}
boost::python::dict

View File

@ -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;

View File

@ -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;
}