summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/arrayfunction_override.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/numpy/core/src/multiarray/arrayfunction_override.c b/numpy/core/src/multiarray/arrayfunction_override.c
index e27bb516e..c9b579ffe 100644
--- a/numpy/core/src/multiarray/arrayfunction_override.c
+++ b/numpy/core/src/multiarray/arrayfunction_override.c
@@ -227,11 +227,11 @@ get_args_and_kwargs(
PyTuple_SET_ITEM(args, i, fast_args[i]);
}
kwargs = PyDict_New();
+ if (kwargs == NULL) {
+ Py_DECREF(args);
+ return -1;
+ }
if (kwnames != NULL) {
- if (kwargs == NULL) {
- Py_DECREF(args);
- return -1;
- }
Py_ssize_t nkwargs = PyTuple_GET_SIZE(kwnames);
for (Py_ssize_t i = 0; i < nkwargs; i++) {
PyObject *key = PyTuple_GET_ITEM(kwnames, i);
@@ -301,12 +301,7 @@ array_implement_c_array_function_creation(
return Py_NotImplemented;
}
- dispatch_types = PyTuple_Pack(1, Py_TYPE(like));
- if (dispatch_types == NULL) {
- goto finish;
- }
-
- /* We have to call __array_function__ properly, which needs some prep */
+ /* We needs args and kwargs for __array_function__ (when not using it). */
if (fast_args != NULL) {
assert(args == NULL);
assert(kwargs == NULL);
@@ -315,6 +310,15 @@ array_implement_c_array_function_creation(
goto finish;
}
}
+ else {
+ Py_INCREF(args);
+ Py_INCREF(kwargs);
+ }
+
+ dispatch_types = PyTuple_Pack(1, Py_TYPE(like));
+ if (dispatch_types == NULL) {
+ goto finish;
+ }
/* The like argument must be present in the keyword arguments, remove it */
if (PyDict_DelItem(kwargs, npy_ma_str_like) < 0) {
@@ -342,6 +346,7 @@ array_implement_c_array_function_creation(
public_api, dispatch_types, args, kwargs);
if (result == Py_NotImplemented) {
+ /* This shouldn't really happen as there is only one type, but... */
Py_DECREF(result);
result = NULL;
set_no_matching_types_error(public_api, dispatch_types);