Skip to content

Commit 405c6de

Browse files
committed
MNT: support python 3.10
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.
1 parent 076c599 commit 405c6de

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

numpy/core/src/multiarray/scalarapi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
755755
vobj->descr = descr;
756756
Py_INCREF(descr);
757757
vobj->obval = NULL;
758-
Py_SIZE(vobj) = itemsize;
758+
Py_SET_SIZE(vobj, itemsize);
759759
vobj->flags = NPY_ARRAY_CARRAY | NPY_ARRAY_F_CONTIGUOUS | NPY_ARRAY_OWNDATA;
760760
swap = 0;
761761
if (PyDataType_HASFIELDS(descr)) {

numpy/core/src/multiarray/scalartypes.c.src

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ format_@name@(@type@ val, npy_bool scientific,
345345
* over-ride repr and str of array-scalar strings and unicode to
346346
* remove NULL bytes and then call the corresponding functions
347347
* of string and unicode.
348-
*
348+
*
349349
* FIXME:
350350
* is this really a good idea?
351351
* stop using Py_UNICODE here.
@@ -1542,7 +1542,7 @@ static PyObject *
15421542
return NULL;
15431543
}
15441544
#endif
1545-
1545+
15461546
PyObject *tup;
15471547
if (ndigits == Py_None) {
15481548
tup = PyTuple_Pack(0);
@@ -1568,7 +1568,7 @@ static PyObject *
15681568
return ret;
15691569
}
15701570
#endif
1571-
1571+
15721572
return obj;
15731573
}
15741574
/**end repeat**/
@@ -2774,7 +2774,7 @@ void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
27742774
return PyErr_NoMemory();
27752775
}
27762776
((PyVoidScalarObject *)ret)->obval = destptr;
2777-
Py_SIZE((PyVoidScalarObject *)ret) = (int) memu;
2777+
Py_SET_SIZE((PyVoidScalarObject *)ret, (int) memu);
27782778
((PyVoidScalarObject *)ret)->descr =
27792779
PyArray_DescrNewFromType(NPY_VOID);
27802780
((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;

numpy/core/src/umath/_rational_tests.c.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ PyMODINIT_FUNC PyInit__rational_tests(void) {
11581158
npyrational_arrfuncs.fill = npyrational_fill;
11591159
npyrational_arrfuncs.fillwithscalar = npyrational_fillwithscalar;
11601160
/* Left undefined: scanfunc, fromstr, sort, argsort */
1161-
Py_TYPE(&npyrational_descr) = &PyArrayDescr_Type;
1161+
Py_SET_TYPE(&npyrational_descr, &PyArrayDescr_Type);
11621162
npy_rational = PyArray_RegisterDataType(&npyrational_descr);
11631163
if (npy_rational<0) {
11641164
goto fail;

numpy/f2py/rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
\tint i;
195195
\tPyObject *m,*d, *s, *tmp;
196196
\tm = #modulename#_module = PyModule_Create(&moduledef);
197-
\tPy_TYPE(&PyFortran_Type) = &PyType_Type;
197+
\tPy_SET_TYPE(&PyFortran_Type, &PyType_Type);
198198
\timport_array();
199199
\tif (PyErr_Occurred())
200200
\t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return m;}

numpy/f2py/tests/src/array_from_pyobj/wrapmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static struct PyModuleDef moduledef = {
144144
PyMODINIT_FUNC PyInit_test_array_from_pyobj_ext(void) {
145145
PyObject *m,*d, *s;
146146
m = wrap_module = PyModule_Create(&moduledef);
147-
Py_TYPE(&PyFortran_Type) = &PyType_Type;
147+
Py_SET_TYPE(&PyFortran_Type, &PyType_Type);
148148
import_array();
149149
if (PyErr_Occurred())
150150
Py_FatalError("can't initialize module wrap (failed to import numpy)");

0 commit comments

Comments
 (0)