Skip to content

Python 3.13 fix for missing dict segfault

David Gobbi requested to merge dgobbi/vtk:python313-fixes into master

The purpose of this MR is to fix a segfault that occurs when importing VTK modules into Python 3.13. The segfault is related to the fact that two of vtk-python's support classes (the PyVTKTemplate_Type for wrapping C++ templates, and the PyVTKNamespace_Type for wrapping C++ namespaces) are derived from Python's PyModule_Type.

Python 3.13 removed a safety net from PyModule_Type's tp_init slot that created the module's md_dict member if it was NULL. This safety net was removed because, since Python 3.11, the md_dict is created by tp_new and is never expected to be NULL. So, in our own code, we must ensure that tp_new is called before tp_init in order to avoid a segfault due to a NULL md_dict.

Also remove the makeSuite() call from vtkmodules.test.Testing, since makeSuite() has been removed from the unittest module in Python 3.13, and its use caused an AttributeError in many of VTK's tests.

Additionally, Py_GetProgramName() has been deprecated in Python 3.13, so we only use it for old (pre-3.8) versions of Python. Note that we don't use Py_SetProgramName() for Python 3.8+ either.

Closes #19466 (closed)
Closes #19469 (closed)

Edited by David Gobbi

Merge request reports

Loading