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 charris committed May 29, 2020
1 parent 4d2702d commit 0e58c3c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion numpy/core/src/multiarray/scalarapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
8 changes: 4 additions & 4 deletions numpy/core/src/multiarray/scalartypes.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1570,7 +1570,7 @@ static PyObject *
return NULL;
}
#endif

PyObject *tup;
if (ndigits == Py_None) {
tup = PyTuple_Pack(0);
Expand All @@ -1596,7 +1596,7 @@ static PyObject *
return ret;
}
#endif

return obj;
}
/**end repeat**/
Expand Down Expand Up @@ -2802,7 +2802,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;
Expand Down
2 changes: 1 addition & 1 deletion numpy/core/src/umath/_rational_tests.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand Down
2 changes: 1 addition & 1 deletion numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)");
Expand Down

0 comments on commit 0e58c3c

Please sign in to comment.