Details
Description
Observation
PySide generates Interface files by introspection. The generator is used in the build process since 5.12.1 .
By running a build with python 3.5, we now experience a crash in the build system, since generate_pyi.py creates a segfault. When running the build again with the option "--reuse-build", it seems to work. But actually the script is not run at all because the first run could not remove its lock directory.
Details And Debugging
Running a Python trace, the crash could be located in the file contextlib.py, which is used heavily by enumerating the PySide functions and types. The top-level functions are correctly generated, but when Python enters the context of
Replacing this module by a newer version (Python 3.6 ands Python 3.7 tested), the problem goes away. But now, a crash happens in the finalization code of PySide.
PySide generates a function called cleanTypesAttributes for every class, that is called when the class shuts down. When Python 3.5 calls this function on the testbinding module, is creates a segfault. It was impossible to circumvent this segfault. Example:
void cleanTypesAttributes(void) { for (int i = 0, imax = SBK_testbinding_IDX_COUNT; i < imax; i++) { PyObject *pyType = reinterpret_cast<PyObject*>(SbktestbindingTypes[i]); if (pyType && PyObject_HasAttrString(pyType, "staticMetaObject")) PyObject_SetAttrString(pyType, "staticMetaObject", Py_None); } }
This error could only prevented by skipping this code. Even the PyObject_HasAttrString call causes the crash, already.
Analysis And Conclusion
This problem looks first like a pure Python 3.5 bug that newer versions do not have. It can be circumvented by replacing contextlib.py.
The second problem does only exist in the testbinding module, which indicates that something is wrong with it, too. Removing the cleanTypesAttributes does not really harm on shutdown, but the problem is therefore circumvented but not solved.
This problem could creep into our codebase unrecognized, because we do not test multiple Python versions automatically, yet. We should improve this.
Attachments
For Gerrit Dashboard: PYSIDE-953 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
254317,4 | Prevent Python 3.5 From Crashing The Build | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
254793,2 | Amend The Python 3.5 Fix | 5.12 | pyside/pyside-setup | Status: MERGED | +2 | 0 |