From bae42a8bdee7ce75851e873cfd4afe20ba2a2043 Mon Sep 17 00:00:00 2001 From: "Joel B. Mohler" Date: Mon, 17 Nov 2014 12:55:41 -0500 Subject: [PATCH 1/3] copy all array_view members in copy constructor --- src/numpy_cpp.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/numpy_cpp.h b/src/numpy_cpp.h index f0608efa3bf4..62067c21ad41 100644 --- a/src/numpy_cpp.h +++ b/src/numpy_cpp.h @@ -369,9 +369,11 @@ class array_view : public detail::array_view_accessors array_view(const array_view &other, bool contiguous = false) : m_arr(NULL), m_data(NULL) { - if (!set((PyObject *)other.m_arr)) { - throw py::exception(); - } + m_arr = other.m_arr; + Py_INCREF(m_arr); + m_data = other.m_data; + m_shape = other.m_shape; + m_strides = other.m_strides; } array_view(PyArrayObject *arr, char *data, npy_intp *shape, npy_intp *strides) From f94ffd798c3a9da3a1ec38b9f1cc1dab66e71da1 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 17 Nov 2014 16:37:27 -0500 Subject: [PATCH 2/3] Use XINCREF in copy constructor and subview constructor, since arr may be NULL --- src/numpy_cpp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/numpy_cpp.h b/src/numpy_cpp.h index 62067c21ad41..f96bbb23e5f0 100644 --- a/src/numpy_cpp.h +++ b/src/numpy_cpp.h @@ -370,7 +370,7 @@ class array_view : public detail::array_view_accessors array_view(const array_view &other, bool contiguous = false) : m_arr(NULL), m_data(NULL) { m_arr = other.m_arr; - Py_INCREF(m_arr); + Py_XINCREF(m_arr); m_data = other.m_data; m_shape = other.m_shape; m_strides = other.m_strides; @@ -379,7 +379,7 @@ class array_view : public detail::array_view_accessors array_view(PyArrayObject *arr, char *data, npy_intp *shape, npy_intp *strides) { m_arr = arr; - Py_INCREF(arr); + Py_XINCREF(arr); m_data = data; m_shape = shape; m_strides = strides; From bbff7318842e29f9ab473a1af3c2751fcc2309b4 Mon Sep 17 00:00:00 2001 From: "Joel B. Mohler" Date: Tue, 18 Nov 2014 07:19:40 -0500 Subject: [PATCH 3/3] remove unused parameter 'contiguous' --- src/numpy_cpp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/numpy_cpp.h b/src/numpy_cpp.h index f96bbb23e5f0..f1b7ffaa015d 100644 --- a/src/numpy_cpp.h +++ b/src/numpy_cpp.h @@ -367,7 +367,7 @@ class array_view : public detail::array_view_accessors } } - array_view(const array_view &other, bool contiguous = false) : m_arr(NULL), m_data(NULL) + array_view(const array_view &other) : m_arr(NULL), m_data(NULL) { m_arr = other.m_arr; Py_XINCREF(m_arr);