Skip to content

Commit

Permalink
MNT: support python 3.10
Browse files Browse the repository at this point in the history
In python/cpython#20290 CPython changed
`Py_TYPE` from a macro to an inline function.  This requires a code
change to us `Py_SET_TYPE` instead when using `Py_TYPE()` as a lvalue
in c code.

In python/cpython#20429 CPython changed
`Py_SIZE` from a macro to an inline function.  This requires a code
change to us `Py_SET_SIZE` instead of using `Py_SIZE` as a lvalue in c
code.
  • Loading branch information
tacaswell authored and Taiju Yamada committed Aug 9, 2023
1 parent 3bcc57a commit 86e96a0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/scalarapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,11 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
vobj->descr = descr;
Py_INCREF(descr);
vobj->obval = NULL;
#if PY_VERSION_HEX >= 0x030a0000
Py_SET_SIZE(vobj, itemsize);
#else
Py_SIZE(vobj) = itemsize;
#endif
vobj->flags = NPY_ARRAY_CARRAY | NPY_ARRAY_F_CONTIGUOUS | NPY_ARRAY_OWNDATA;
swap = 0;
if (PyDataType_HASFIELDS(descr)) {
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -3067,7 +3067,11 @@ void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *NPY_UNUSED(kwds))
return PyErr_NoMemory();
}
((PyVoidScalarObject *)ret)->obval = destptr;
#if PY_VERSION_HEX >= 0x030a0000
Py_SET_SIZE((PyVoidScalarObject *)ret, (int) memu);
#else
Py_SIZE((PyVoidScalarObject *)ret) = (int) memu;
#endif
((PyVoidScalarObject *)ret)->descr =
PyArray_DescrNewFromType(NPY_VOID);
((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;
Expand Down
4 changes: 4 additions & 0 deletions numpy/core/src/umath/_rational_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,11 @@ PyMODINIT_FUNC init_rational_tests(void) {
npyrational_arrfuncs.fill = npyrational_fill;
npyrational_arrfuncs.fillwithscalar = npyrational_fillwithscalar;
/* Left undefined: scanfunc, fromstr, sort, argsort */
#if PY_VERSION_HEX >= 0x030a0000
Py_SET_TYPE(&npyrational_descr, &PyArrayDescr_Type);
#else
Py_TYPE(&npyrational_descr) = &PyArrayDescr_Type;
#endif
npy_rational = PyArray_RegisterDataType(&npyrational_descr);
if (npy_rational<0) {
goto fail;
Expand Down
4 changes: 4 additions & 0 deletions numpy/f2py/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@
#else
\tm = #modulename#_module = Py_InitModule(\"#modulename#\", f2py_module_methods);
#endif
#if PY_VERSION_HEX >= 0x030a0000
\tPy_SET_TYPE(&PyFortran_Type, &PyType_Type);
#else
\tPy_TYPE(&PyFortran_Type) = &PyType_Type;
#endif
\timport_array();
\tif (PyErr_Occurred())
\t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return RETVAL;}
Expand Down
4 changes: 4 additions & 0 deletions numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ PyMODINIT_FUNC inittest_array_from_pyobj_ext(void) {
#else
m = wrap_module = Py_InitModule("test_array_from_pyobj_ext", f2py_module_methods);
#endif
#if PY_VERSION_HEX >= 0x030a0000
Py_SET_TYPE(&PyFortran_Type, &PyType_Type);
#else
Py_TYPE(&PyFortran_Type) = &PyType_Type;
#endif
import_array();
if (PyErr_Occurred())
Py_FatalError("can't initialize module wrap (failed to import numpy)");
Expand Down

0 comments on commit 86e96a0

Please sign in to comment.