Skip to content

Commit 0501b09

Browse files
committed
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.
1 parent 78f074f commit 0501b09

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

pcl/_pcl.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ cdef class SegmentationNormal:
129129
mpcl_sacnormal_set_axis(deref(self.me),ax,ay,az)
130130

131131

132-
# Empirically determine strides, for buffer support.
132+
# Empirically determine strides, for buffer protocol support.
133133
# XXX Is there a more elegant way to get these?
134134
cdef Py_ssize_t _strides[2]
135135
cdef PointCloud _pc_tmp = PointCloud(np.array([[1, 2, 3],
@@ -196,9 +196,9 @@ cdef class PointCloud:
196196
cdef Py_ssize_t npoints = self.thisptr().size()
197197

198198
if self._view_count == 0:
199-
self._view_count += 1
200199
self._shape[0] = npoints
201200
self._shape[1] = 3
201+
self._view_count += 1
202202

203203
buffer.buf = <char *>&(cpp.getptr_at(self.thisptr(), 0).x)
204204
buffer.format = 'f'

tests/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def test_asarray(self):
5353
a[:] += 6
5454
assert_array_almost_equal(p[0], a[0])
5555

56+
# Regression test: deleting a second view would previously
57+
# reset the view count to zero.
58+
b = np.asarray(p)
59+
del b
60+
61+
self.assertRaises(ValueError, p.resize, 2 * len(p))
62+
5663
def test_pickle(self):
5764
"""Test pickle support."""
5865
# In this testcase because picking reduces to pickling NumPy arrays.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy