Skip to content

Commit

Permalink
Fix compatibility with Python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed May 23, 2023
1 parent 1ee8596 commit 5bd4bc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/customizedTemplates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,19 @@ PyObject * newcarrayobject_template<GenoIterator>(GenoIterator begin, GenoIterat
}
//
op->ob_iter = begin;
#if PY_VERSION_HEX >= 0x030b0000
# ifdef MUTANTALLELE
Py_SET_SIZE(op, end.index() - begin.index());
# else
Py_SET_SIZE(op, end - begin);
# endif
# else
# ifdef MUTANTALLELE
Py_SIZE(op) = end.index() - begin.index();
# else
Py_SIZE(op) = end - begin;
# endif
#endif
return (PyObject *)op;
}

Expand All @@ -708,7 +716,11 @@ PyObject * newcarrayobject_template<LineageIterator>(LineageIterator begin, Line
}
//
op->ob_iter = begin;
#if PY_VERSION_HEX >= 0x030b0000
Py_SET_SIZE(op, end - begin);
#else
Py_SIZE(op) = end - begin;
#endif
return (PyObject *)op;
}

Expand Down Expand Up @@ -1510,7 +1522,11 @@ PyObject * newcarrayobject_template<GenoIterator>(GenoIterator begin, GenoIterat
}
//
op->ob_iter = begin;
#if PY_VERSION_HEX >= 0x030b0000
Py_SET_SIZE(op, end - begin);
#else
Py_SIZE(op) = end - begin;
#endif
return (PyObject *)op;
}

Expand All @@ -1529,7 +1545,11 @@ PyObject * newcarrayobject_template<LineageIterator>(LineageIterator begin, Line
}
//
op->ob_iter = begin;
#if PY_VERSION_HEX >= 0x030b0000
Py_SET_SIZE(op, end - begin);
#else
Py_SIZE(op) = end - begin;
#endif
return (PyObject *)op;
}

Expand Down
10 changes: 9 additions & 1 deletion src/customizedTypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1513,13 +1513,21 @@ PyObject * PyDefDict_New()

int initCustomizedTypes(PyObject * m)
{
#if PY_VERSION_HEX >= 0x030b0000
Py_SET_TYPE(&Arraytype, &PyType_Type);
if (PyType_Ready(&Arraytype) < 0)
return -1;
//
Py_SET_TYPE(&defdict_type, &PyType_Type);
defdict_type.tp_base = &PyDict_Type;
#else
Py_TYPE(&Arraytype) = &PyType_Type;
if (PyType_Ready(&Arraytype) < 0)
return -1;
//
Py_TYPE(&defdict_type) = &PyType_Type;
defdict_type.tp_base = &PyDict_Type;

#endif
if (PyType_Ready(&defdict_type) < 0)
return -1;

Expand Down
3 changes: 3 additions & 0 deletions src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ using std::ofstream;

// compile and eval enables compiling string to byte code
#include "compile.h"

#if PY_VERSION_HEX < 0x030b0000
#include "eval.h"
#endif

// for kbhit
#if defined (_WIN32) || defined (__WIN32__)
Expand Down

0 comments on commit 5bd4bc9

Please sign in to comment.