SIP gc assert

Mark Roszko mark.roszko at gmail.com
Wed Apr 12 00:09:15 BST 2023


We are finding that the generated descriptors.c that comes
from sip_descriptors.c is causing crash asserts in python 3.11. One
notable reason is python 3.11 introduced asserts in various places to
stay on top of object lifetime

The assert looks like this

>gcmodule.c:442: update_refs: Assertion "gc_get_refs(gc) != 0" failed
>Enable tracemalloc to get the memory block allocation traceback

>object address : 000002C59FF0EF80
>object refcount : 0
>object type : 00007FFC02AA71C0
>object type name: sip.methoddescriptor
>object repr : <refcnt 0 at 000002C59FF0EF80>

>Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
>Python runtime state: initialized

After research, both sipMethodDescr_Type and sipVariableDescr_Type
have the Py_TPFLAGS_HAVE_GC flag set.

Per the python 3.11 manual for the HAVE_GC flag. The function
PyObject_GC_UnTrack should be called first in the dealloc slot
function before doing anything else

Adding the PyObject_GC_UnTrack calls appears to fix the assert for us


More information about the PyQt mailing list