Merge pull request #16417 from tacaswell/fix_py310_compat · numpy/numpy@a96b18e (original) (raw)
File tree
6 files changed
lines changed
- tests/src/array_from_pyobj
6 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -60,6 +60,14 @@ static NPY_INLINE int PyInt_Check(PyObject *op) { | ||
60 | 60 | PySlice_GetIndicesEx((PySliceObject *)op, nop, start, end, step, slicelength) |
61 | 61 | #endif |
62 | 62 | |
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 | + | |
63 | 71 | #define Npy_EnterRecursiveCall(x) Py_EnterRecursiveCall(x) |
64 | 72 | |
65 | 73 | /* Py_SETREF was added in 3.5.2, and only if Py_LIMITED_API is absent */ |
@@ -546,4 +554,5 @@ NpyCapsule_Check(PyObject *ptr) | ||
546 | 554 | } |
547 | 555 | #endif |
548 | 556 | |
557 | + | |
549 | 558 | #endif /* _NPY_3KCOMPAT_H_ */ |
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
@@ -755,7 +755,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base) | |||
755 | 755 | vobj->descr = descr; | |
756 | 756 | Py_INCREF(descr); | |
757 | 757 | vobj->obval = NULL; | |
758 | -Py_SIZE(vobj) = itemsize; | ||
758 | +Py_SET_SIZE(vobj, itemsize); | ||
759 | 759 | vobj->flags = NPY_ARRAY_CARRAY | NPY_ARRAY_F_CONTIGUOUS | NPY_ARRAY_OWNDATA; |
760 | 760 | swap = 0; | |
761 | 761 | if (PyDataType_HASFIELDS(descr)) { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -345,7 +345,7 @@ format_@name@(@type@ val, npy_bool scientific, | ||
345 | 345 | * over-ride repr and str of array-scalar strings and unicode to |
346 | 346 | * remove NULL bytes and then call the corresponding functions |
347 | 347 | * of string and unicode. |
348 | - * | |
348 | + * | |
349 | 349 | * FIXME: |
350 | 350 | * is this really a good idea? |
351 | 351 | * stop using Py_UNICODE here. |
@@ -1542,7 +1542,7 @@ static PyObject * | ||
1542 | 1542 | return NULL; |
1543 | 1543 | } |
1544 | 1544 | #endif |
1545 | - | |
1545 | + | |
1546 | 1546 | PyObject *tup; |
1547 | 1547 | if (ndigits == Py_None) { |
1548 | 1548 | tup = PyTuple_Pack(0); |
@@ -1568,7 +1568,7 @@ static PyObject * | ||
1568 | 1568 | return ret; |
1569 | 1569 | } |
1570 | 1570 | #endif |
1571 | - | |
1571 | + | |
1572 | 1572 | return obj; |
1573 | 1573 | } |
1574 | 1574 | /**end repeat**/ |
@@ -2774,7 +2774,7 @@ void_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | ||
2774 | 2774 | return PyErr_NoMemory(); |
2775 | 2775 | } |
2776 | 2776 | ((PyVoidScalarObject *)ret)->obval = destptr; |
2777 | -Py_SIZE((PyVoidScalarObject *)ret) = (int) memu; | |
2777 | +Py_SET_SIZE((PyVoidScalarObject *)ret, (int) memu); | |
2778 | 2778 | ((PyVoidScalarObject *)ret)->descr = |
2779 | 2779 | PyArray_DescrNewFromType(NPY_VOID); |
2780 | 2780 | ((PyVoidScalarObject *)ret)->descr->elsize = (int) memu; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1158,7 +1158,7 @@ PyMODINIT_FUNC PyInit__rational_tests(void) { | ||
1158 | 1158 | npyrational_arrfuncs.fill = npyrational_fill; |
1159 | 1159 | npyrational_arrfuncs.fillwithscalar = npyrational_fillwithscalar; |
1160 | 1160 | /* Left undefined: scanfunc, fromstr, sort, argsort */ |
1161 | -Py_TYPE(&npyrational_descr) = &PyArrayDescr_Type; | |
1161 | +Py_SET_TYPE(&npyrational_descr, &PyArrayDescr_Type); | |
1162 | 1162 | npy_rational = PyArray_RegisterDataType(&npyrational_descr); |
1163 | 1163 | if (npy_rational<0) { |
1164 | 1164 | goto fail; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -194,7 +194,7 @@ | ||
194 | 194 | \tint i; |
195 | 195 | \tPyObject *m,*d, *s, *tmp; |
196 | 196 | \tm = #modulename#_module = PyModule_Create(&moduledef); |
197 | -\tPy_TYPE(&PyFortran_Type) = &PyType_Type; | |
197 | +\tPy_SET_TYPE(&PyFortran_Type, &PyType_Type); | |
198 | 198 | \timport_array(); |
199 | 199 | \tif (PyErr_Occurred()) |
200 | 200 | \t\t{PyErr_SetString(PyExc_ImportError, \"can't initialize module #modulename# (failed to import numpy)\"); return m;} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -144,7 +144,7 @@ static struct PyModuleDef moduledef = { | ||
144 | 144 | PyMODINIT_FUNC PyInit_test_array_from_pyobj_ext(void) { |
145 | 145 | PyObject *m,*d, *s; |
146 | 146 | m = wrap_module = PyModule_Create(&moduledef); |
147 | -Py_TYPE(&PyFortran_Type) = &PyType_Type; | |
147 | +Py_SET_TYPE(&PyFortran_Type, &PyType_Type); | |
148 | 148 | import_array(); |
149 | 149 | if (PyErr_Occurred()) |
150 | 150 | Py_FatalError("can't initialize module wrap (failed to import numpy)"); |