From 0501b09b557c5a76183d53b3981fe83022cfd6b3 Mon Sep 17 00:00:00 2001 From: Lars Buitinck Date: Thu, 10 Dec 2015 18:11:42 +0100 Subject: [PATCH] Fix bug in buffer protocol support The view count was not correctly incremented beyond 1, so having two views and releasing one would bring it back to 0. --- pcl/_pcl.pyx | 4 ++-- tests/test.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pcl/_pcl.pyx b/pcl/_pcl.pyx index ee7bd80ec..795f9e108 100644 --- a/pcl/_pcl.pyx +++ b/pcl/_pcl.pyx @@ -129,7 +129,7 @@ cdef class SegmentationNormal: mpcl_sacnormal_set_axis(deref(self.me),ax,ay,az) -# Empirically determine strides, for buffer support. +# Empirically determine strides, for buffer protocol support. # XXX Is there a more elegant way to get these? cdef Py_ssize_t _strides[2] cdef PointCloud _pc_tmp = PointCloud(np.array([[1, 2, 3], @@ -196,9 +196,9 @@ cdef class PointCloud: cdef Py_ssize_t npoints = self.thisptr().size() if self._view_count == 0: - self._view_count += 1 self._shape[0] = npoints self._shape[1] = 3 + self._view_count += 1 buffer.buf = &(cpp.getptr_at(self.thisptr(), 0).x) buffer.format = 'f' diff --git a/tests/test.py b/tests/test.py index 8cd5a5f59..247476608 100644 --- a/tests/test.py +++ b/tests/test.py @@ -53,6 +53,13 @@ def test_asarray(self): a[:] += 6 assert_array_almost_equal(p[0], a[0]) + # Regression test: deleting a second view would previously + # reset the view count to zero. + b = np.asarray(p) + del b + + self.assertRaises(ValueError, p.resize, 2 * len(p)) + def test_pickle(self): """Test pickle support.""" # In this testcase because picking reduces to pickling NumPy arrays.