Skip to content

Commit

Permalink
Added python3.11 compatibility for c-module
Browse files Browse the repository at this point in the history
  • Loading branch information
andershenja committed Jul 4, 2024
1 parent 8013b75 commit c9021d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pyhlhdf/pyhlcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ PyObject* PyHlhdf_StringOrUnicode_FromASCII(const char *buffer, Py_ssize_t size)
PyModuleDef_HEAD_INIT, name, doc, -1, methods, NULL, NULL, NULL, NULL }; \
ob = PyModule_Create(&moduledef);

#define MOD_INIT_SETUP_TYPE(itype, otype) Py_TYPE(&itype) = otype
#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE)
static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type)
{ ob->ob_type = type; }
#define Py_SET_TYPE(ob, type) _Py_SET_TYPE((PyObject*)(ob), type)
#endif

#define MOD_INIT_SETUP_TYPE(itype, otype) Py_SET_TYPE(&itype, otype)
#define MOD_INIT_VERIFY_TYPE_READY(type) if (PyType_Ready(type) < 0) return MOD_INIT_ERROR

#else
Expand Down
4 changes: 2 additions & 2 deletions test/python/rave_info_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static PyTypeObject RaveInfoType_Type = {
(getattrofunc)_getattr_typeo, /*tp_getattro*/
(setattrofunc)0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
(traverseproc)0, /*tp_traverse*/
(inquiry)0, /*tp_clear*/
Expand Down Expand Up @@ -378,7 +378,7 @@ static PyTypeObject RaveInfoObject_Type = {
(getattrofunc)_getattro_object,/*tp_getattro*/
(setattrofunc)_setattro_object,/*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
(traverseproc)0, /*tp_traverse*/
(inquiry)0, /*tp_clear*/
Expand Down

0 comments on commit c9021d2

Please sign in to comment.