Skip to content
Snippets Groups Projects

Fix Numpy 1.20.0 by initializing PyArray_Descr portably

1 file
+ 9
23
Compare changes
  • Side-by-side
  • Inline
+ 9
23
@@ -655,24 +655,6 @@ SWIGINTERN bool swiglal_release_parent(void *ptr) {
(PyArray_FastTakeFunc*)NULL, // fasttake
};
// NumPy array descriptor function for type ACFTYPE.
static PyArray_Descr swiglal_py_array_objview_##ACFTYPE##_arrdescr = {
PyObject_HEAD_INIT(NULL)
(PyTypeObject*) NULL, // typeobj
NPY_VOIDLTR, // kind
NPY_VOIDLTR, // type
'=', // byteorder
NPY_LIST_PICKLE | NPY_USE_GETITEM | NPY_USE_SETITEM
| NPY_ITEM_IS_POINTER | NPY_NEEDS_INIT | NPY_NEEDS_PYAPI, // hasobject
0, // type_num
0, // elsize
0, // alignment
(PyArray_ArrayDescr*)NULL, // subarray
(PyObject*)NULL, // fields
(PyObject*)NULL, // names
&swiglal_py_array_objview_##ACFTYPE##_arrfuncs, // f
};
// This function returns the NumPy array descriptor appropriate for the supplied SWIG type
// descriptor. If no array descriptor exists, it creates one from the array descriptor for type
// ACFTYPE.
@@ -683,22 +665,26 @@ SWIGINTERN bool swiglal_release_parent(void *ptr) {
// Create NumPy array descriptor if none yet exists.
if (*pdescr == NULL) {
*pdescr = PyArray_DescrNew(&swiglal_py_array_objview_##ACFTYPE##_arrdescr);
*pdescr = PyArray_DescrNewFromType(NPY_OBJECT);
if (*pdescr == NULL) {
return NULL;
}
(*pdescr)->typeobj = SwigPyObject_type();
(*pdescr)->elsize = esize;
(*pdescr)->alignment = 1;
(*pdescr)->f = &swiglal_py_array_objview_##ACFTYPE##_arrfuncs;
// Numpy workaround for registering user-defined object types. See
// https://github.com/numpy/numpy/pull/18303,
// https://github.com/numpy/numpy/pull/17320
(*pdescr)->names = Py_BuildValue("(s)", "swigobj");
(*pdescr)->fields = Py_BuildValue("{s:(s,i)}", "swigobj", "O", 0);
if (PyArray_RegisterDataType(*pdescr) < 0) {
return NULL;
}
}
// PyArray_NewFromDescr appears to steal a reference to the descriptor passed to it, so a
// reference count increment is needed here.
Py_INCREF(*pdescr);
return *pdescr;
}
Loading