diff options
author | mattip <matti.picus@gmail.com> | 2018-12-10 23:37:27 +0200 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2018-12-10 23:37:27 +0200 |
commit | a3be55e49fa0cce3695bee2532f4305290d010a3 (patch) | |
tree | 2b6c3663045c563397aec53c66d4f11e73c12f94 /numpy/core | |
parent | 1c7a2f928dac1e66296fc2d097901b249b68d592 (diff) | |
download | numpy-a3be55e49fa0cce3695bee2532f4305290d010a3.tar.gz |
MAINT: comment, fix from review
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/common/ufunc_override.c | 7 | ||||
-rw-r--r-- | numpy/core/src/multiarray/common.c | 5 |
2 files changed, 10 insertions, 2 deletions
diff --git a/numpy/core/src/common/ufunc_override.c b/numpy/core/src/common/ufunc_override.c index 3bc34c3f5..e1aae8ea6 100644 --- a/numpy/core/src/common/ufunc_override.c +++ b/numpy/core/src/common/ufunc_override.c @@ -93,15 +93,18 @@ PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj, PyObject * return 0; } if (PyTuple_CheckExact(*out_kwd_obj)) { + /* + * The C-API recommends calling PySequence_Fast before any of the other + * PySequence_Fast* functions. This is required for PyPy + */ PyObject *seq = PySequence_Fast(*out_kwd_obj, "cannot convert"); int ret; if (seq == NULL) { return -1; } - Py_DECREF(*out_kwd_obj); *out_objs = PySequence_Fast_ITEMS(seq); ret = PySequence_Fast_GET_SIZE(seq); - *out_kwd_obj = seq; + Py_SETREF(*out_kwd_obj, seq); return ret; } else { diff --git a/numpy/core/src/multiarray/common.c b/numpy/core/src/multiarray/common.c index 3e5221a59..84ad04723 100644 --- a/numpy/core/src/multiarray/common.c +++ b/numpy/core/src/multiarray/common.c @@ -441,11 +441,16 @@ PyArray_DTypeFromObjectHelper(PyObject *obj, int maxdims, } /* Recursive case, first check the sequence contains only one type */ + /* + * The C-API recommends calling PySequence_Fast before any of the other + * PySequence_Fast* functions. This is required for PyPy + */ seq = PySequence_Fast(obj, "Could not convert object to sequence"); if (seq == NULL) { goto fail; } size = PySequence_Fast_GET_SIZE(seq); + /* objects is borrowed, do not release seq */ objects = PySequence_Fast_ITEMS(seq); common_type = size > 0 ? Py_TYPE(objects[0]) : NULL; for (i = 1; i < size; ++i) { |