Skip to content

Commit 3a863bf

Browse files
tacaswellTaiju Yamada
authored and
Taiju Yamada
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 e60e510 commit 3a863bf

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

numpy/core/src/multiarray/scalarapi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,11 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)
789789
vobj->descr = descr;
790790
Py_INCREF(descr);
791791
vobj->obval = NULL;
792+
#if PY_VERSION_HEX >= 0x030a0000
793+
Py_SET_SIZE(vobj, itemsize);
794+
#else
792795
Py_SIZE(vobj) = itemsize;
796+
#endif
793797
vobj->flags = NPY_ARRAY_CARRAY | NPY_ARRAY_F_CONTIGUOUS | NPY_ARRAY_OWNDATA;
794798
swap = 0;
795799
if (PyDataType_HASFIELDS(descr)) {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,7 +3067,11 @@ void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *NPY_UNUSED(kwds))
30673067
return PyErr_NoMemory();
30683068
}
30693069
((PyVoidScalarObject *)ret)->obval = destptr;
3070+
#if PY_VERSION_HEX >= 0x030a0000
3071+
Py_SET_SIZE((PyVoidScalarObject *)ret, (int) memu);
3072+
#else
30703073
Py_SIZE((PyVoidScalarObject *)ret) = (int) memu;
3074+
#endif
30713075
((PyVoidScalarObject *)ret)->descr =
30723076
PyArray_DescrNewFromType(NPY_VOID);
30733077
((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,11 @@ PyMODINIT_FUNC init_rational_tests(void) {
11931193
npyrational_arrfuncs.fill = npyrational_fill;
11941194
npyrational_arrfuncs.fillwithscalar = npyrational_fillwithscalar;
11951195
/* Left undefined: scanfunc, fromstr, sort, argsort */
1196+
#if PY_VERSION_HEX >= 0x030a0000
1197+
Py_SET_TYPE(&npyrational_descr, &PyArrayDescr_Type);
1198+
#else
11961199
Py_TYPE(&npyrational_descr) = &PyArrayDescr_Type;
1200+
#endif
11971201
npy_rational = PyArray_RegisterDataType(&npyrational_descr);
11981202
if (npy_rational<0) {
11991203
goto fail;

numpy/f2py/rules.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,11 @@
208208
#else
209209
\tm = #modulename#_module = Py_InitModule(\"#modulename#\", f2py_module_methods);
210210
#endif
211+
#if PY_VERSION_HEX >= 0x030a0000
212+
\tPy_SET_TYPE(&PyFortran_Type, &PyType_Type);
213+
#else
211214
\tPy_TYPE(&PyFortran_Type) = &PyType_Type;
215+
#endif
212216
\timport_array();
213217
\tif (PyErr_Occurred())
214218
\t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return RETVAL;}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ PyMODINIT_FUNC inittest_array_from_pyobj_ext(void) {
143143
#else
144144
m = wrap_module = Py_InitModule("test_array_from_pyobj_ext", f2py_module_methods);
145145
#endif
146+
#if PY_VERSION_HEX >= 0x030a0000
147+
Py_SET_TYPE(&PyFortran_Type, &PyType_Type);
148+
#else
146149
Py_TYPE(&PyFortran_Type) = &PyType_Type;
150+
#endif
147151
import_array();
148152
if (PyErr_Occurred())
149153
Py_FatalError("can't initialize module wrap (failed to import numpy)");

0 commit comments

Comments
 (0)