From 405c6dec7987324395f7113eab02492b3044a9ed Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 28 May 2020 13:04:59 -0400 Subject: [PATCH] MNT: support python 3.10 In https://github.com/python/cpython/pull/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 https://github.com/python/cpython/pull/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. --- numpy/core/src/multiarray/scalarapi.c | 2 +- numpy/core/src/multiarray/scalartypes.c.src | 8 ++++---- numpy/core/src/umath/_rational_tests.c.src | 2 +- numpy/f2py/rules.py | 2 +- numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/numpy/core/src/multiarray/scalarapi.c b/numpy/core/src/multiarray/scalarapi.c index 8a7139fb23a7..f3c440dc625a 100644 --- a/numpy/core/src/multiarray/scalarapi.c +++ b/numpy/core/src/multiarray/scalarapi.c @@ -755,7 +755,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base) vobj->descr = descr; Py_INCREF(descr); vobj->obval = NULL; - Py_SIZE(vobj) = itemsize; + Py_SET_SIZE(vobj, itemsize); vobj->flags = NPY_ARRAY_CARRAY | NPY_ARRAY_F_CONTIGUOUS | NPY_ARRAY_OWNDATA; swap = 0; if (PyDataType_HASFIELDS(descr)) { diff --git a/numpy/core/src/multiarray/scalartypes.c.src b/numpy/core/src/multiarray/scalartypes.c.src index f13f50759fb6..a7c3e847a1f8 100644 --- a/numpy/core/src/multiarray/scalartypes.c.src +++ b/numpy/core/src/multiarray/scalartypes.c.src @@ -345,7 +345,7 @@ format_@name@(@type@ val, npy_bool scientific, * over-ride repr and str of array-scalar strings and unicode to * remove NULL bytes and then call the corresponding functions * of string and unicode. - * + * * FIXME: * is this really a good idea? * stop using Py_UNICODE here. @@ -1542,7 +1542,7 @@ static PyObject * return NULL; } #endif - + PyObject *tup; if (ndigits == Py_None) { tup = PyTuple_Pack(0); @@ -1568,7 +1568,7 @@ static PyObject * return ret; } #endif - + return obj; } /**end repeat**/ @@ -2774,7 +2774,7 @@ void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return PyErr_NoMemory(); } ((PyVoidScalarObject *)ret)->obval = destptr; - Py_SIZE((PyVoidScalarObject *)ret) = (int) memu; + Py_SET_SIZE((PyVoidScalarObject *)ret, (int) memu); ((PyVoidScalarObject *)ret)->descr = PyArray_DescrNewFromType(NPY_VOID); ((PyVoidScalarObject *)ret)->descr->elsize = (int) memu; diff --git a/numpy/core/src/umath/_rational_tests.c.src b/numpy/core/src/umath/_rational_tests.c.src index 651019a84fd3..13e33d0a51e4 100644 --- a/numpy/core/src/umath/_rational_tests.c.src +++ b/numpy/core/src/umath/_rational_tests.c.src @@ -1158,7 +1158,7 @@ PyMODINIT_FUNC PyInit__rational_tests(void) { npyrational_arrfuncs.fill = npyrational_fill; npyrational_arrfuncs.fillwithscalar = npyrational_fillwithscalar; /* Left undefined: scanfunc, fromstr, sort, argsort */ - Py_TYPE(&npyrational_descr) = &PyArrayDescr_Type; + Py_SET_TYPE(&npyrational_descr, &PyArrayDescr_Type); npy_rational = PyArray_RegisterDataType(&npyrational_descr); if (npy_rational<0) { goto fail; diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py index 6750bf705d88..ecfc71ae3a64 100755 --- a/numpy/f2py/rules.py +++ b/numpy/f2py/rules.py @@ -194,7 +194,7 @@ \tint i; \tPyObject *m,*d, *s, *tmp; \tm = #modulename#_module = PyModule_Create(&moduledef); -\tPy_TYPE(&PyFortran_Type) = &PyType_Type; +\tPy_SET_TYPE(&PyFortran_Type, &PyType_Type); \timport_array(); \tif (PyErr_Occurred()) \t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return m;} diff --git a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c index 83c0da2cf682..0db33e71448f 100644 --- a/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c +++ b/numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c @@ -144,7 +144,7 @@ static struct PyModuleDef moduledef = { PyMODINIT_FUNC PyInit_test_array_from_pyobj_ext(void) { PyObject *m,*d, *s; m = wrap_module = PyModule_Create(&moduledef); - Py_TYPE(&PyFortran_Type) = &PyType_Type; + Py_SET_TYPE(&PyFortran_Type, &PyType_Type); import_array(); if (PyErr_Occurred()) Py_FatalError("can't initialize module wrap (failed to import numpy)");