summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2020-02-02 09:36:56 +0200
committerGitHub <noreply@github.com>2020-02-02 09:36:56 +0200
commit330435bb3420d798de08f86bf47287e55cf9e516 (patch)
tree5a52ff880633d36e8f81c05b23518f3f3146b72c /numpy
parent94e516b7d55ea762e13f690c095172b8fcd47bc8 (diff)
parent5ee5012fbf7be3cf081407d5666a8733d965907d (diff)
downloadnumpy-330435bb3420d798de08f86bf47287e55cf9e516.tar.gz
Merge pull request #15427 from seberg/deprecate-unused-c-api
DEP: Schedule unused C-API functions for removal/disabling
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/arrayobject.c4
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c5
-rw-r--r--numpy/core/src/multiarray/ctors.c56
-rw-r--r--numpy/core/src/multiarray/ctors.h8
-rw-r--r--numpy/core/src/umath/ufunc_object.c43
5 files changed, 92 insertions, 24 deletions
diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c
index 06d92785c..cf8f9ddae 100644
--- a/numpy/core/src/multiarray/arrayobject.c
+++ b/numpy/core/src/multiarray/arrayobject.c
@@ -278,8 +278,8 @@ PyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)
* Get either an array object we can copy from, or its parameters
* if there isn't a convenient array available.
*/
- if (PyArray_GetArrayParamsFromObject(src_object, PyArray_DESCR(dest),
- 0, &dtype, &ndim, dims, &src, NULL) < 0) {
+ if (PyArray_GetArrayParamsFromObject_int(src_object,
+ PyArray_DESCR(dest), 0, &dtype, &ndim, dims, &src) < 0) {
Py_DECREF(src_object);
return -1;
}
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index d4774c2b2..9fed47814 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -13,6 +13,7 @@
#include "numpy/npy_math.h"
#include "common.h"
+#include "ctors.h"
#include "scalartypes.h"
#include "mapping.h"
@@ -255,11 +256,11 @@ PyArray_AdaptFlexibleDType(PyObject *data_obj, PyArray_Descr *data_dtype,
int ndim = 0;
npy_intp dims[NPY_MAXDIMS];
list = PyArray_ToList((PyArrayObject *)data_obj);
- result = PyArray_GetArrayParamsFromObject(
+ result = PyArray_GetArrayParamsFromObject_int(
list,
retval,
0, &dtype,
- &ndim, dims, &arr, NULL);
+ &ndim, dims, &arr);
Py_DECREF(list);
Py_XDECREF(arr);
if (result < 0) {
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 0616bed65..8f2e9c3d1 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -1574,7 +1574,7 @@ fail:
}
-/*NUMPY_API
+/*
* Retrieves the array parameters for viewing/converting an arbitrary
* PyObject* to a NumPy array. This allows the "innate type and shape"
* of Python list-of-lists to be discovered without
@@ -1629,16 +1629,14 @@ fail:
* validate and possibly copy arr itself ...
* }
* ... use arr ...
- * context is passed to PyArray_FromArrayAttr, which ignores it. Since this is
- * a NUMPY_API function, we cannot remove it.
*/
NPY_NO_EXPORT int
-PyArray_GetArrayParamsFromObject(PyObject *op,
+PyArray_GetArrayParamsFromObject_int(PyObject *op,
PyArray_Descr *requested_dtype,
npy_bool writeable,
PyArray_Descr **out_dtype,
int *out_ndim, npy_intp *out_dims,
- PyArrayObject **out_arr, PyObject *context)
+ PyArrayObject **out_arr)
{
PyObject *tmp;
@@ -1738,7 +1736,7 @@ PyArray_GetArrayParamsFromObject(PyObject *op,
* this should be changed!
*/
if (!writeable) {
- tmp = PyArray_FromArrayAttr(op, requested_dtype, context);
+ tmp = PyArray_FromArrayAttr(op, requested_dtype, NULL);
if (tmp != Py_NotImplemented) {
*out_arr = (PyArrayObject *)tmp;
return (*out_arr) == NULL ? -1 : 0;
@@ -1900,13 +1898,41 @@ PyArray_GetArrayParamsFromObject(PyObject *op,
return -1;
}
+
+/*NUMPY_API*/
+NPY_NO_EXPORT int
+PyArray_GetArrayParamsFromObject(PyObject *op,
+ PyArray_Descr *requested_dtype,
+ npy_bool writeable,
+ PyArray_Descr **out_dtype,
+ int *out_ndim, npy_intp *out_dims,
+ PyArrayObject **out_arr, PyObject *context)
+{
+ /* NumPy 1.19, 2020-01-24 */
+ if (DEPRECATE(
+ "PyArray_GetArrayParamsFromObject() C-API function is deprecated "
+ "and expected to be removed rapidly. If you are using it (i.e. see "
+ "this warning/error), please notify the NumPy developers. "
+ "As of now it is expected that any use case is served similarly "
+ "well by `PyArray_FromAny()` and this function is unused outside "
+ "of NumPy itself.") < 0) {
+ return -1;
+ }
+
+ if (context != NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "'context' must be NULL");
+ return -1;
+ }
+
+ return PyArray_GetArrayParamsFromObject_int(op,
+ requested_dtype, writeable, out_dtype, out_ndim, out_dims,
+ out_arr);
+}
+
+
/*NUMPY_API
* Does not check for NPY_ARRAY_ENSURECOPY and NPY_ARRAY_NOTSWAPPED in flags
* Steals a reference to newtype --- which can be NULL
- *
- * context is passed to PyArray_GetArrayParamsFromObject, which passes it to
- * PyArray_FromArrayAttr, which raises if it is not NULL. Since this is a
- * NUMPY_API function, we cannot remove it.
*/
NPY_NO_EXPORT PyObject *
PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
@@ -1921,10 +1947,14 @@ PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
int ndim = 0;
npy_intp dims[NPY_MAXDIMS];
+ if (context != NULL) {
+ PyErr_SetString(PyExc_RuntimeError, "'context' must be NULL");
+ return NULL;
+ }
+
/* Get either the array or its parameters if it isn't an array */
- if (PyArray_GetArrayParamsFromObject(op, newtype,
- 0, &dtype,
- &ndim, dims, &arr, context) < 0) {
+ if (PyArray_GetArrayParamsFromObject_int(op,
+ newtype, 0, &dtype, &ndim, dims, &arr) < 0) {
Py_XDECREF(newtype);
return NULL;
}
diff --git a/numpy/core/src/multiarray/ctors.h b/numpy/core/src/multiarray/ctors.h
index 4768e4efd..9e63cd7d2 100644
--- a/numpy/core/src/multiarray/ctors.h
+++ b/numpy/core/src/multiarray/ctors.h
@@ -30,6 +30,14 @@ PyArray_New(
PyTypeObject *, int nd, npy_intp const *,
int, npy_intp const*, void *, int, int, PyObject *);
+NPY_NO_EXPORT int
+PyArray_GetArrayParamsFromObject_int(PyObject *op,
+ PyArray_Descr *requested_dtype,
+ npy_bool writeable,
+ PyArray_Descr **out_dtype,
+ int *out_ndim, npy_intp *out_dims,
+ PyArrayObject **out_arr);
+
NPY_NO_EXPORT PyObject *
PyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,
int max_depth, int flags, PyObject *context);
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 9f9b6830e..f34fbaf7f 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -3052,17 +3052,15 @@ fail:
return retval;
}
-/*UFUNC_API
- *
+/*
* This generic function is called with the ufunc object, the arguments to it,
* and an array of (pointers to) PyArrayObjects which are NULL.
*
* 'op' is an array of at least NPY_MAXARGS PyArrayObject *.
*/
-NPY_NO_EXPORT int
-PyUFunc_GenericFunction(PyUFuncObject *ufunc,
- PyObject *args, PyObject *kwds,
- PyArrayObject **op)
+static int
+PyUFunc_GenericFunction_int(PyUFuncObject *ufunc,
+ PyObject *args, PyObject *kwds, PyArrayObject **op)
{
int nin, nout;
int i, nop;
@@ -3268,6 +3266,27 @@ fail:
return retval;
}
+
+/*UFUNC_API*/
+NPY_NO_EXPORT int
+PyUFunc_GenericFunction(PyUFuncObject *ufunc,
+ PyObject *args, PyObject *kwds, PyArrayObject **op)
+{
+ /* NumPy 1.19, 2020-01-24 */
+ if (DEPRECATE(
+ "PyUFunc_GenericFunction() C-API function is deprecated "
+ "and expected to be removed rapidly. If you are using it (i.e. see "
+ "this warning/error), please notify the NumPy developers. "
+ "As of now it is expected that any use case is served better by "
+ "the direct use of `PyObject_Call(ufunc, args, kwargs)`. "
+ "PyUFunc_GenericFunction function has slightly different "
+ "untested behaviour.") < 0) {
+ return -1;
+ }
+ return PyUFunc_GenericFunction_int(ufunc, args, kwds, op);
+}
+
+
/*
* Given the output type, finds the specified binary op. The
* ufunc must have nin==2 and nout==1. The function may modify
@@ -4679,7 +4698,7 @@ ufunc_generic_call(PyUFuncObject *ufunc, PyObject *args, PyObject *kwds)
return override;
}
- errval = PyUFunc_GenericFunction(ufunc, args, kwds, mps);
+ errval = PyUFunc_GenericFunction_int(ufunc, args, kwds, mps);
if (errval < 0) {
return NULL;
}
@@ -4973,6 +4992,16 @@ PyUFunc_FromFuncAndDataAndSignatureAndIdentity(PyUFuncGenericFunction *func, voi
NPY_NO_EXPORT int
PyUFunc_SetUsesArraysAsData(void **data, size_t i)
{
+ /* NumPy 1.19, 2020-01-24 */
+ if (DEPRECATE(
+ "PyUFunc_SetUsesArraysAsData() C-API function is deprecated "
+ "and expected to be removed rapidly. If you are using it (i.e. see "
+ "this warning/error), please notify the NumPy developers. "
+ "It is currently assumed that this function is simply unused and "
+ "its removal will facilitate the implementation of better "
+ "approaches.") < 0) {
+ return -1;
+ }
data[i] = (void*)PyUFunc_SetUsesArraysAsData;
return 0;
}