mirror of https://github.com/KLayout/klayout.git
[consider merging] avoid an assertion in the Python exit code for accessing an already destroyed Python object
This commit is contained in:
parent
87e2def285
commit
bee3d11f62
|
|
@ -859,6 +859,14 @@ PythonClassClientData::PythonClassClientData (const gsi::ClassBase *_cls, PyType
|
||||||
// .. nothing yet ..
|
// .. nothing yet ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PythonClassClientData::~PythonClassClientData ()
|
||||||
|
{
|
||||||
|
// This destructor is called from the exit code. Python may have shut down already.
|
||||||
|
// We must not try to release the objects in that case and simply don't care about them any longer.
|
||||||
|
py_type_object.release ();
|
||||||
|
py_type_object_static.release ();
|
||||||
|
}
|
||||||
|
|
||||||
PyTypeObject *
|
PyTypeObject *
|
||||||
PythonClassClientData::py_type (const gsi::ClassBase &cls_decl, bool as_static)
|
PythonClassClientData::py_type (const gsi::ClassBase &cls_decl, bool as_static)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -302,6 +302,7 @@ struct PythonClassClientData
|
||||||
: public gsi::PerClassClientSpecificData
|
: public gsi::PerClassClientSpecificData
|
||||||
{
|
{
|
||||||
PythonClassClientData (const gsi::ClassBase *_cls, PyTypeObject *_py_type, PyTypeObject *_py_type_static, PythonModule *module);
|
PythonClassClientData (const gsi::ClassBase *_cls, PyTypeObject *_py_type, PyTypeObject *_py_type_static, PythonModule *module);
|
||||||
|
~PythonClassClientData ();
|
||||||
|
|
||||||
PythonPtr py_type_object;
|
PythonPtr py_type_object;
|
||||||
PythonPtr py_type_object_static;
|
PythonPtr py_type_object_static;
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,13 @@ PythonPtr::~PythonPtr ()
|
||||||
Py_XDECREF (mp_obj);
|
Py_XDECREF (mp_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject *PythonPtr::release ()
|
||||||
|
{
|
||||||
|
PyObject *obj = mp_obj;
|
||||||
|
mp_obj = NULL;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
PythonPtr::operator bool () const
|
PythonPtr::operator bool () const
|
||||||
{
|
{
|
||||||
return mp_obj != NULL;
|
return mp_obj != NULL;
|
||||||
|
|
|
||||||
|
|
@ -211,6 +211,14 @@ public:
|
||||||
return mp_obj < other.mp_obj;
|
return mp_obj < other.mp_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Releases the object
|
||||||
|
*
|
||||||
|
* This method returns and resets the raw pointer without changing the
|
||||||
|
* reference count.
|
||||||
|
*/
|
||||||
|
PyObject *release ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PyObject *mp_obj;
|
PyObject *mp_obj;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue