Skip to content

Commit 92c4efd

Browse files
committed
removed prints and debug stuff
1 parent ae30f63 commit 92c4efd

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

arrex/list.pyx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,11 @@ cdef class typedlist:
217217
lastptr = self.ptr
218218

219219
# buffer protocol is less efficient that PyBytes_AS_STRING so we use it directly here where we know that owner is bytes
220-
#self.owner = PyBytes_FromStringAndSize(NULL, size)
221-
#self.ptr = PyBytes_AS_STRING(self.owner)
222-
cdef buffer buff = buffer(size)
223-
self.owner = buff
224-
self.ptr = buff.ptr
220+
self.owner = PyBytes_FromStringAndSize(NULL, size)
221+
self.ptr = PyBytes_AS_STRING(self.owner)
222+
#cdef buffer buff = buffer(size)
223+
#self.owner = buff
224+
#self.ptr = buff.ptr
225225
self.allocated = size
226226

227227
#print('** reallocate', sys.getrefcount(self.owner), sys.getrefcount(lastowner), lastowner is None)
@@ -299,7 +299,7 @@ cdef class typedlist:
299299
self.size += self.dtype.dsize
300300

301301
def clear(self):
302-
''' remove all elements from the array, very fast operation '''
302+
''' remove all elements from the array but does not deallocate, very fast operation '''
303303
self.size = 0
304304

305305
cpdef int extend(self, other) except *:
@@ -313,6 +313,10 @@ cdef class typedlist:
313313
if PyObject_CheckBuffer(other):
314314
PyObject_GetBuffer(other, &view, PyBUF_SIMPLE)
315315

316+
if view.len % self.dtype.dsize:
317+
PyBuffer_Release(&view)
318+
raise TypeError('the given buffer must have a byte size multiple of dtype size')
319+
316320
if <size_t>view.len > self.allocated - self.size:
317321
self._reallocate(max(2*self.size, self.size + view.len))
318322
memcpy(self.ptr+self.size, view.buf, view.len)
@@ -339,6 +343,10 @@ cdef class typedlist:
339343
if PyObject_CheckBuffer(other):
340344
PyObject_GetBuffer(other, &view, PyBUF_SIMPLE)
341345

346+
if view.len % self.dtype.dsize:
347+
PyBuffer_Release(&view)
348+
raise TypeError('the given buffer must have a byte size multiple of dtype size')
349+
342350
result = typedlist.__new__(typedlist)
343351
result.dtype = self.dtype
344352
result._reallocate(self.size + view.len)
@@ -640,6 +648,12 @@ cdef class arrayiter:
640648
return item
641649

642650

651+
652+
653+
'''
654+
# this is in reserve for debug purpose
655+
# helps to keep track of buffers
656+
643657
cdef size_t buffer_id = 0
644658
cdef size_t buffer_count = 0
645659
@@ -667,3 +681,4 @@ cdef class buffer:
667681
668682
def __len__(self):
669683
return self.size
684+
'''

0 commit comments

Comments
 (0)