From d6c8b1f63cfc0715e86fb14eeee6d395da3d69d2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 4 Apr 2022 23:28:16 +0200 Subject: [PATCH] Fixed #1054 (only an issue in debug builds so far) --- src/pya/pya/pyaModule.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pya/pya/pyaModule.cc b/src/pya/pya/pyaModule.cc index 21fbc9ac1..6f5f41b7f 100644 --- a/src/pya/pya/pyaModule.cc +++ b/src/pya/pya/pyaModule.cc @@ -584,6 +584,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);