Skip to content

Commit

Permalink
removed prints and debug stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jimy-byerley committed Nov 5, 2021
1 parent ae30f63 commit 92c4efd
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions arrex/list.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ cdef class typedlist:
lastptr = self.ptr

# buffer protocol is less efficient that PyBytes_AS_STRING so we use it directly here where we know that owner is bytes
#self.owner = PyBytes_FromStringAndSize(NULL, size)
#self.ptr = PyBytes_AS_STRING(self.owner)
cdef buffer buff = buffer(size)
self.owner = buff
self.ptr = buff.ptr
self.owner = PyBytes_FromStringAndSize(NULL, size)
self.ptr = PyBytes_AS_STRING(self.owner)
#cdef buffer buff = buffer(size)
#self.owner = buff
#self.ptr = buff.ptr
self.allocated = size

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

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

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

if view.len % self.dtype.dsize:
PyBuffer_Release(&view)
raise TypeError('the given buffer must have a byte size multiple of dtype size')

if <size_t>view.len > self.allocated - self.size:
self._reallocate(max(2*self.size, self.size + view.len))
memcpy(self.ptr+self.size, view.buf, view.len)
Expand All @@ -339,6 +343,10 @@ cdef class typedlist:
if PyObject_CheckBuffer(other):
PyObject_GetBuffer(other, &view, PyBUF_SIMPLE)

if view.len % self.dtype.dsize:
PyBuffer_Release(&view)
raise TypeError('the given buffer must have a byte size multiple of dtype size')

result = typedlist.__new__(typedlist)
result.dtype = self.dtype
result._reallocate(self.size + view.len)
Expand Down Expand Up @@ -640,6 +648,12 @@ cdef class arrayiter:
return item




'''
# this is in reserve for debug purpose
# helps to keep track of buffers
cdef size_t buffer_id = 0
cdef size_t buffer_count = 0
Expand Down Expand Up @@ -667,3 +681,4 @@ cdef class buffer:
def __len__(self):
return self.size
'''

0 comments on commit 92c4efd

Please sign in to comment.