Skip to content
Snippets Groups Projects
Commit 67592976 authored by David Gobbi's avatar David Gobbi
Browse files

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.
parent 09096c29
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment