Skip to content

Commit 0e58c3c

Browse files
tacaswellcharris
authored andcommitted
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 4d2702d commit 0e58c3c

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.
@@ -1570,7 +1570,7 @@ static PyObject *
15701570
return NULL;
15711571
}
15721572
#endif
1573-
1573+
15741574
PyObject *tup;
15751575
if (ndigits == Py_None) {
15761576
tup = PyTuple_Pack(0);
@@ -1596,7 +1596,7 @@ static PyObject *
15961596
return ret;
15971597
}
15981598
#endif
1599-
1599+
16001600
return obj;
16011601
}
16021602
/**end repeat**/
@@ -2802,7 +2802,7 @@ void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
28022802
return PyErr_NoMemory();
28032803
}
28042804
((PyVoidScalarObject *)ret)->obval = destptr;
2805-
Py_SIZE((PyVoidScalarObject *)ret) = (int) memu;
2805+
Py_SET_SIZE((PyVoidScalarObject *)ret, (int) memu);
28062806
((PyVoidScalarObject *)ret)->descr =
28072807
PyArray_DescrNewFromType(NPY_VOID);
28082808
((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)