-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython3.13.patch
More file actions
49 lines (47 loc) · 2.34 KB
/
Copy pathpython3.13.patch
File metadata and controls
49 lines (47 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From 675929762a09ad0b40cb2667918a7061c47a418c Mon Sep 17 00:00:00 2001
From: David Gobbi <david.gobbi@gmail.com>
Date: Sat, 14 Sep 2024 08:35:21 -0600
Subject: [PATCH] Python 3.13 fix for missing dict segfault
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.
---
Wrapping/PythonCore/PyVTKNamespace.cxx | 6 ++++--
Wrapping/PythonCore/PyVTKTemplate.cxx | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Wrapping/PythonCore/PyVTKNamespace.cxx b/Wrapping/PythonCore/PyVTKNamespace.cxx
index bed60dc47cb..c1823084086 100644
--- a/Wrapping/PythonCore/PyVTKNamespace.cxx
+++ b/Wrapping/PythonCore/PyVTKNamespace.cxx
@@ -112,8 +112,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* pyname = PyUnicode_FromString(name);
PyObject* args = PyTuple_Pack(1, pyname);
diff --git a/Wrapping/PythonCore/PyVTKTemplate.cxx b/Wrapping/PythonCore/PyVTKTemplate.cxx
index 26421f60f07..e7780bf1007 100644
--- a/Wrapping/PythonCore/PyVTKTemplate.cxx
+++ b/Wrapping/PythonCore/PyVTKTemplate.cxx
@@ -761,8 +761,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* pyname = PyUnicode_FromString(name);
PyObject* pydoc = PyUnicode_FromString(docstring);