Closed petronny closed 6 months ago
The fact that is crashed in PyInit_shiboken2
implies that this might be a shiboken problem instead of a CPython one. With C extensions, you can easily crash CPython with incorrect code and there's nothing CPython can do.
From the backtrace it seems like PyDict_GetItemString()
gets a NULL
pointer from add_more_getsets
which is shiboken code. If I had to guess, that's where the issue is.
In any case, if this is indeed a CPython issue, you should be able to reproduce it without any 3rd party library. For this specific matter, I don't think this is a CPython bug.
The fact that is crashed in
PyInit_shiboken2
implies that this might be a shiboken problem instead of a CPython one. With C extensions, you can easily crash CPython with incorrect code and there's nothing CPython can do.From the backtrace it seems like
PyDict_GetItemString()
gets aNULL
pointer fromadd_more_getsets
which is shiboken code. If I had to guess, that's where the issue is.In any case, if this is indeed a CPython issue, you should be able to reproduce it without any 3rd party library. For this specific matter, I don't think this is a CPython bug.
Thank you for your reply. I believe some changes in Python 3.12 must be related to this issue since these two libaries can be loaded without any problem in Python 3.11. I will check if there is any change about PyDict_GetItemString()
.
FinishSignatureInitialization
calls PySide_PatchTypes
, which calls add_more_getsets
on different types here:
https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/shiboken2/libshiboken/signature.cpp?h=5.13#n873
which calls PyType_Ready
on type
and then tries to access its tp_dict
field:
https://code.qt.io/cgit/pyside/pyside-setup.git/tree/sources/shiboken2/libshiboken/signature.cpp?h=5.13#n628
But is it correct in 3.12 for static built-in types as PyCFunction_Type
/PyType_Type
/wrapper-descriptor? Docs say that tp_dict
is always equal to NULL
for these types and that PyType_GetDict
should be used.
https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dict
tp_dict
is always equal toNULL
for these types and thatPyType_GetDict
should be used. https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dict
That must be the reason. I'm trying to make a patch to add_more_getsets()
like directly returning 0 if dict pointer is NULL or reassign it to PyType_GetDict()
.
I add a line if (dict == NULL) dict = PyType_GetDict(type);
under PyObject *dict = type->tp_dict;
to ensure that dict pointer is not NULL. After rebuilding shiboken2 from source the segmentation fault is gone.
It looks like the problem is solved but the build of pyside2 still has an error. It can be bypassed by just removing this line but I appreciate if anybody can help to resolve it properly.
Traceback (most recent call last):
File "/build/pyside2/src/pyside-setup-opensource-src-5.15.13/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 317, in <module>
generate_all_pyi(outpath, options=options)
File "/build/pyside2/src/pyside-setup-opensource-src-5.15.13/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 294, in generate_all_pyi
generate_pyi(import_name, outpath, options)
File "/build/pyside2/src/pyside-setup-opensource-src-5.15.13/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 220, in generate_pyi
fmt = Formatter(outfile)
^^^^^^^^^^^^^^^^^^
File "/build/pyside2/src/pyside-setup-opensource-src-5.15.13/sources/pyside2/PySide2/QtCore/../support/generate_pyi.py", line 119, in __init__
typing.TypeVar.__repr__ = _typevar__repr__
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: cannot set '__repr__' attribute of immutable type 'typing.TypeVar'
make[2]: *** [sources/pyside2/PySide2/QtCore/CMakeFiles/QtCore_pyi.dir/build.make:70: sources/pyside2/PySide2/QtCore/CMakeFiles/QtCore_pyi] Error 1
make[1]: *** [CMakeFiles/Makefile2:1573: sources/pyside2/PySide2/QtCore/CMakeFiles/QtCore_pyi.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
Crash report
What happened?
TL;DR:
I'm trying to build shiboken2 (part of pyside2) with Python 3.12 on Arch Linux.
I'm awared that pyside2 doesn't officially support Python 3.12 even Python 3.11. But it actually used to work well with Python 3.11.
However, since Python 3.12 the build of pyside2 throws segmentation fault during
import PySide2
. We then noticed that directly installing pyside2 from pypi and runningimport PySide2
will also raise a similar segmentation fault. We believe these two segmentation faults are same so there is no need to actually run the build process.Then we found the segmentation fault is raised during
import shiboken2
when runningimport PySide2
with the pypi installation. And the minimal environment to reproduce the error is just grabbing the two libraries and try to load them with Python 3.12.See also: https://github.com/arch4edu/arch4edu/issues/268
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417]