<div dir="ltr">Of interest to those who have not seen it — a discussion of the many problems around Python's C API, and what folks are doing to ameliorate them:<div><br></div><div><a href="https://pyfound.blogspot.com/2023/05/the-python-language-summit-2023-three.html">https://pyfound.blogspot.com/2023/05/the-python-language-summit-2023-three.html</a><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 9 Jun 2023 at 09:56, Thomas Caswell <<a href="mailto:tcaswell@gmail.com">tcaswell@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I am also seeing segfaults with the cpython main branch + pyqt6.  I had a suspicion it was that change, but had not had time to verify or make a minimal example (making a Matplotlib figure segfaulted).  <div><br></div><div>numpy and cython also had issues, see <a href="https://github.com/python/cpython/issues/104614" target="_blank">https://github.com/python/cpython/issues/104614</a> , however even with those PRs landed I'm still seeing segfaults with PyQt6.<div><br></div><div>Tom</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jun 8, 2023 at 5:22 PM Florian Bruhin <<a href="mailto:me@the-compiler.org" target="_blank">me@the-compiler.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hey,<br>
<br>
When trying PyQt 6.5.1 with Python 3.12 Beta 2, something like:<br>
<br>
        import sys<br>
        from PyQt6.QtWidgets import QWidget, QApplication<br>
<br>
        class Mixin: pass<br>
        class Command(Mixin, QWidget): pass<br>
<br>
        app = QApplication(sys.argv)<br>
        cmd = Command()<br>
        cmd.show()<br>
        app.exec()<br>
<br>
segfaults here on the "cmd.Command()" line:<br>
<br>
        _PyDict_Next (op=0x0, ppos=0x7fffffffbd50, pkey=0x7fffffffbd58,<br>
pvalue=0x7fffffffbd60, phash=phash@entry=0x0) at Objects/dictobject.c:2114<br>
        2114       if (!PyDict_Check(op))<br>
        (gdb) bt<br>
        #0  _PyDict_Next (op=0x0, ppos=0x7fffffffbd50, pkey=0x7fffffffbd58,<br>
pvalue=0x7fffffffbd60, phash=phash@entry=0x0) at Objects/dictobject.c:2114<br>
        #1  0x000055555572a37e in PyDict_Next (op=<optimized out>,<br>
ppos=<optimized out>, pkey=<optimized out>, pvalue=<optimized out>) at<br>
Objects/dictobject.c:2189<br>
        #2  0x00007ffff2436499 in trawl_hierarchy(_typeobject*,<br>
qpycore_metaobject*, QMetaObjectBuilder&, QList<EnumFlag>&,<br>
QList<_qpycore_pyqtSignal const*>&, QMap<unsigned int, std::pair<_object*,<br>
_object*> >&) ()<br>
           from .../lib/python3.12/site-packages/PyQt6/<a href="http://QtCore.abi3.so" rel="noreferrer" target="_blank">QtCore.abi3.so</a><br>
        #3  0x00007ffff2436cc7 in trawl_hierarchy(_typeobject*,<br>
qpycore_metaobject*, QMetaObjectBuilder&, QList<EnumFlag>&,<br>
QList<_qpycore_pyqtSignal const*>&, QMap<unsigned int, std::pair<_object*,<br>
_object*> >&) ()<br>
           from .../lib/python3.12/site-packages/PyQt6/<a href="http://QtCore.abi3.so" rel="noreferrer" target="_blank">QtCore.abi3.so</a><br>
        #4  0x00007ffff2436cc7 in trawl_hierarchy(_typeobject*,<br>
qpycore_metaobject*, QMetaObjectBuilder&, QList<EnumFlag>&,<br>
QList<_qpycore_pyqtSignal const*>&, QMap<unsigned int, std::pair<_object*,<br>
_object*> >&) ()<br>
           from .../lib/python3.12/site-packages/PyQt6/<a href="http://QtCore.abi3.so" rel="noreferrer" target="_blank">QtCore.abi3.so</a><br>
        #5  0x00007ffff24357ba in<br>
qpycore_get_dynamic_metaobject(_sipWrapperType*) [clone .part.0] () from<br>
.../lib/python3.12/site-packages/PyQt6/<a href="http://QtCore.abi3.so" rel="noreferrer" target="_blank">QtCore.abi3.so</a><br>
        #6  0x00007ffff24363d8 in qpycore_get_qmetaobject(_sipWrapperType*,<br>
_sipTypeDef const*) () from .../lib/python3.12/site-<br>
packages/PyQt6/<a href="http://QtCore.abi3.so" rel="noreferrer" target="_blank">QtCore.abi3.so</a><br>
        #7  0x00007ffff242a4e5 in qpycore_qobject_finalisation(_object*,<br>
QObject*, _object*, _object**) () from .../lib/python3.12/site-<br>
packages/PyQt6/<a href="http://QtCore.abi3.so" rel="noreferrer" target="_blank">QtCore.abi3.so</a><br>
        #8  0x00007ffff74efbbc in sipSimpleWrapper_init (self=0x7ffff765ebb0,<br>
args=(), kwds=0x0) at sip_core.c:8950<br>
        #9  0x0000555555758f0d in type_call (type=<optimized out>,<br>
type@entry=0x555555e53e60, args=args@entry=(), kwds=kwds@entry=0x0) at<br>
Objects/typeobject.c:1671<br>
        [...]<br>
<br>
(Note the op=0x0).<br>
<br>
I tried to build a debug PyQt, but it couldn't find Python.h of my<br>
(non-systemwide) debug Python, and I couldn't find a way to make sip-install<br>
pass a custom -I to gcc.<br>
<br>
I was able to bisect it in CPython to this commit:<br>
<a href="https://github.com/python/cpython/commit/de64e7561680fdc5358001e9488091e75d4174a3" rel="noreferrer" target="_blank">https://github.com/python/cpython/commit/de64e7561680fdc5358001e9488091e75d417<br>
4a3</a><br>
which moves tp_dict/tp_bases/tp_mro to PyInterpreterState.<br>
<br>
I lack the context to tell more about what's happening here.<br>
Is this a CPython bug? If so, is there any chance of reproducing it without<br>
PyQt involved?<br>
<br>
Thanks,<br>
<br>
Florian<br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Thomas Caswell<br><a href="mailto:tcaswell@gmail.com" target="_blank">tcaswell@gmail.com</a></div>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><a href="https://damonlynch.net" target="_blank">https://damonlynch.net</a><br></div></div>