Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #81 from larsmans/fixes
Browse files Browse the repository at this point in the history
Fix bug in buffer protocol support
  • Loading branch information
nzjrs committed Feb 4, 2016
2 parents a03b8d8 + 0501b09 commit 97f5f17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pcl/_pcl.pyx
Expand Up @@ -138,7 +138,7 @@ cdef class SegmentationNormal:
return min_angle, max_angle


# 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],
Expand Down Expand Up @@ -205,9 +205,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 = <char *>&(cpp.getptr_at(self.thisptr(), 0).x)
buffer.format = 'f'
Expand Down
7 changes: 7 additions & 0 deletions tests/test.py
Expand Up @@ -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.
Expand Down

0 comments on commit 97f5f17

Please sign in to comment.