From 75f31f569796fdf1f23793e97795a3ef54512f81 Mon Sep 17 00:00:00 2001 From: Orion Poplawski Date: Tue, 8 Oct 2024 08:00:53 -0600 Subject: [PATCH] Add upstream patch to fix segmentation fault on import with Python 3.13 (rhbz#2310520) --- vtk-python3.13.patch | 90 ++++++++++++++++++++++++++++++++++++++++++++ vtk.spec | 10 ++++- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 vtk-python3.13.patch diff --git a/vtk-python3.13.patch b/vtk-python3.13.patch new file mode 100644 index 0000000..0bea05f --- /dev/null +++ b/vtk-python3.13.patch @@ -0,0 +1,90 @@ +diff --git a/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx b/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx +index 0471594..bc92c85 100644 +--- a/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx ++++ b/Utilities/PythonInterpreter/vtkPythonInterpreter.cxx +@@ -114,7 +114,9 @@ wchar_t* vtk_Py_UTF8ToWide(const char* arg) + + return result; + } ++#endif + ++#if PY_VERSION_HEX < 0x03080000 + std::string vtk_Py_WideToUTF8(const wchar_t* arg) + { + std::string result; +@@ -859,15 +861,20 @@ void vtkPythonInterpreter::SetupVTKPythonPaths() + if (vtklib.empty()) + { + VTKPY_DEBUG_MESSAGE( +- "`GetVTKVersion` library couldn't be found. Will use `Py_GetProgramName` next."); ++ "`GetVTKVersion` library couldn't be found. Will use `sys.executable` next."); + } + + if (vtklib.empty()) + { +-#if PY_VERSION_HEX >= 0x03000000 +- vtklib = vtk_Py_WideToUTF8(Py_GetProgramName()); ++#if PY_VERSION_HEX >= 0x03080000 ++ vtkPythonScopeGilEnsurer gilEnsurer; ++ PyObject* executable_path = PySys_GetObject("executable"); ++ if (executable_path != Py_None) ++ { ++ vtklib = PyUnicode_AsUTF8AndSize(executable_path, nullptr); ++ } + #else +- vtklib = Py_GetProgramName(); ++ vtklib = vtk_Py_WideToUTF8(Py_GetProgramName()); + #endif + } + +diff --git a/Wrapping/Python/vtkmodules/test/Testing.py b/Wrapping/Python/vtkmodules/test/Testing.py +index 59186bb..d0643c1 100644 +--- a/Wrapping/Python/vtkmodules/test/Testing.py ++++ b/Wrapping/Python/vtkmodules/test/Testing.py +@@ -513,8 +513,10 @@ def test(cases): + """ + # Make the test suites from the arguments. + suites = [] +- for case in cases: +- suites.append(unittest.makeSuite(case[0], case[1])) ++ loader = unittest.TestLoader() ++ # the "name" is ignored (it was always just 'test') ++ for test,name in cases: ++ suites.append(loader.loadTestsFromTestCase(test)) + test_suite = unittest.TestSuite(suites) + + # Now run the tests. +diff --git a/Wrapping/PythonCore/PyVTKNamespace.cxx b/Wrapping/PythonCore/PyVTKNamespace.cxx +index 927eef1..7460eb7 100644 +--- a/Wrapping/PythonCore/PyVTKNamespace.cxx ++++ b/Wrapping/PythonCore/PyVTKNamespace.cxx +@@ -113,8 +113,10 @@ PyObject* PyVTKNamespace_New(const char* name) + { + // make sure python has readied the type object + PyType_Ready(&PyVTKNamespace_Type); +- // call the allocator provided by python for this type +- self = PyVTKNamespace_Type.tp_alloc(&PyVTKNamespace_Type, 0); ++ // call the superclass new function ++ PyObject* empty = PyTuple_New(0); ++ self = PyVTKNamespace_Type.tp_base->tp_new(&PyVTKNamespace_Type, empty, nullptr); ++ Py_DECREF(empty); + // call the superclass init function + PyObject* args = PyTuple_New(1); + PyTuple_SET_ITEM(args, 0, PyString_FromString(name)); +diff --git a/Wrapping/PythonCore/PyVTKTemplate.cxx b/Wrapping/PythonCore/PyVTKTemplate.cxx +index e0ff31e..c89900f 100644 +--- a/Wrapping/PythonCore/PyVTKTemplate.cxx ++++ b/Wrapping/PythonCore/PyVTKTemplate.cxx +@@ -788,8 +788,10 @@ PyObject* PyVTKTemplate_New(const char* name, const char* docstring) + { + // make sure python has readied the type object + PyType_Ready(&PyVTKTemplate_Type); +- // call the allocator provided by python for this type +- PyObject* self = PyVTKTemplate_Type.tp_alloc(&PyVTKTemplate_Type, 0); ++ // call the superclass new function ++ PyObject* empty = PyTuple_New(0); ++ PyObject* self = PyVTKTemplate_Type.tp_base->tp_new(&PyVTKTemplate_Type, empty, nullptr); ++ Py_DECREF(empty); + // call the superclass init function + PyObject* args = PyTuple_New(2); + PyTuple_SET_ITEM(args, 0, PyString_FromString(name)); diff --git a/vtk.spec b/vtk.spec index dd03878..d3ce529 100644 --- a/vtk.spec +++ b/vtk.spec @@ -54,7 +54,7 @@ Summary: The Visualization Toolkit - A high level 3D visualization library Name: vtk Version: 9.2.6 -Release: 17%{?dist} +Release: 18%{?dist} License: BSD-3-Clause Source0: https://www.vtk.org/files/release/9.2/VTK-%{version}.tar.gz Source1: https://www.vtk.org/files/release/9.2/VTKData-%{version}.tar.gz @@ -66,6 +66,10 @@ Patch1: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/9616.patch # Add missing includes for gcc 13 # https://gitlab.kitware.com/vtk/vtk/-/issues/18782 Patch2: vtk-include.patch +# Fix segfault with Python 3.13 +# https://bugzilla.redhat.com/show_bug.cgi?id=2310520 +# Backport of https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11486 +Patch3: vtk-python3.13.patch URL: https://vtk.org/ @@ -849,6 +853,10 @@ cat xorg.log %changelog +* Tue Oct 08 2024 Orion Poplawski - 9.2.6-18 +- Add upstream patch to fix segmentation fault on import with Python 3.13 + (rhbz#2310520) + * Sat Jul 20 2024 Fedora Release Engineering - 9.2.6-17 - Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild