8000 Merge pull request #16417 from tacaswell/fix_py310_compat · numpy/numpy@a96b18e · GitHub
[go: up one dir, main page]

Skip to content

Commit a96b18e

Browse files
authored
Merge pull request #16417 from tacaswell/fix_py310_compat
MAINT: support python 3.10
2 parents 470c783 + 77c2c23 commit a96b18e

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

numpy/core/include/numpy/npy_3kcompat.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ static NPY_INLINE int PyInt_Check(PyObject *op) {
6060
PySlice_GetIndicesEx((PySliceObject *)op, nop, start, end, step, slicelength)
6161
#endif
6262

63+
#if PY_VERSION_HEX < 0x030900a4
64+
/* Introduced in https://github.com/python/cpython/commit/d2ec81a8c99796b51fb8c49b77a7fe369863226f */
65+
#define Py_SET_TYPE(obj, typ) (Py_TYPE(obj) = typ)
66+
/* Introduced in https://github.com/python/cpython/commit/b10dc3e7a11fcdb97e285882eba6da92594f90f9 */
67+
#define Py_SET_SIZE(obj, size) (Py_SIZE(obj) = size)
68+
#endif
69+
70+
6371
#define Npy_EnterRecursiveCall(x) Py_EnterRecursiveCall(x)
6472

6573
/* Py_SETREF was added in 3.5.2, and only if Py_LIMITED_API is absent */
@@ -546,4 +554,5 @@ NpyCapsule_Check(PyObject *ptr)
546554
}
547555
#endif
548556

557+
549558
#endif /* _NPY_3KCOMPAT_H_ */

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)
0