Skip to content

Commit 321895c

Browse files
etejedorguitargeek
authored andcommitted
[PyROOT] Py_TYPE is changed to an inline static function in Py3.11
As mentioned in the Python docs: https://docs.python.org/3.11/whatsnew/3.11.html Already available upstream in: wlav/CPyCppyy@a8f41df
1 parent b4cb1b0 commit 321895c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

bindings/pyroot/cppyy/CPyCppyy/src/CPPConstructor.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ PyObject* CPyCppyy::CPPConstructor::Call(
122122
if (pyclass) {
123123
self->SetSmart((PyObject*)Py_TYPE(self));
124124
Py_DECREF((PyObject*)Py_TYPE(self));
125-
Py_TYPE(self) = (PyTypeObject*)pyclass;
125+
Py_SET_TYPE(self, (PyTypeObject*)pyclass);
126126
}
127127
}
128128

bindings/pyroot/cppyy/CPyCppyy/src/CPyCppyy.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ inline Py_ssize_t PyNumber_AsSsize_t(PyObject* obj, PyObject*) {
304304
#define CPyCppyy_PyCFunction_Call PyCFunction_Call
305305
#endif
306306

307+
// Py_TYPE is changed to an inline static function in 3.11
308+
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
309+
static inline
310+
void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) { ob->ob_type = type; }
311+
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
312+
#endif
313+
307314
// C++ version of the cppyy API
308315
#include "Cppyy.h"
309316

0 commit comments

Comments
 (0)