Fixed #1054 (only an issue in debug builds so far)

This commit is contained in:
Matthias Koefferlein 2022-04-04 23:28:16 +02:00
parent 981db08dea
commit a1318599fe
1 changed files with 8 additions and 0 deletions

View File

@ -632,6 +632,14 @@ static std::string extract_python_name (const std::string &name)
static void
pya_object_deallocate (PyObject *self)
{
// This avoids an assertion in debug builds (Python, gcmodule.c - update_refs).
// In short, the GC expects not to see objects with refcount 0 and asserts.
// However, due to triggering of signals or similar, the destructor call below
// may trigger a GC (https://github.com/KLayout/klayout/issues/1054).
// According to the comments this may be turned into a release mode assertion, so
// we better work around it.
++self->ob_refcnt;
PYAObjectBase *p = PYAObjectBase::from_pyobject (self);
p->~PYAObjectBase ();
Py_TYPE (self)->tp_free (self);