Commit c7a7c577 authored by Robert Bradshaw's avatar Robert Bradshaw

array fixes for py3

parent 008e1f62
...@@ -50,7 +50,7 @@ from libc cimport stdlib ...@@ -50,7 +50,7 @@ from libc cimport stdlib
from libc.string cimport strcat, strncat, \ from libc.string cimport strcat, strncat, \
memset, memchr, memcmp, memcpy, memmove memset, memchr, memcmp, memcpy, memmove
from cpython.ref cimport PyTypeObject from cpython.ref cimport PyTypeObject, Py_TYPE
from cpython.exc cimport PyErr_BadArgument from cpython.exc cimport PyErr_BadArgument
cdef extern from *: # Hard-coded utility code hack. cdef extern from *: # Hard-coded utility code hack.
...@@ -67,7 +67,6 @@ cdef extern from *: # Hard-coded utility code hack. ...@@ -67,7 +67,6 @@ cdef extern from *: # Hard-coded utility code hack.
cdef __cythonbufferdefaults__ = {'ndim' : 1, 'mode':'c'} cdef __cythonbufferdefaults__ = {'ndim' : 1, 'mode':'c'}
cdef: cdef:
PyTypeObject* ob_type
Py_ssize_t length # == ob_size (by union) Py_ssize_t length # == ob_size (by union)
arraydescr* ob_descr # struct arraydescr *ob_descr; arraydescr* ob_descr # struct arraydescr *ob_descr;
...@@ -131,7 +130,7 @@ cdef inline array clone(array template, Py_ssize_t length, bint zero): ...@@ -131,7 +130,7 @@ cdef inline array clone(array template, Py_ssize_t length, bint zero):
type will be same as template. type will be same as template.
if zero is true, new array will be initialized with zeroes.""" if zero is true, new array will be initialized with zeroes."""
cdef array op cdef array op
op = newarrayobject(template.ob_type, length, template.ob_descr) op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
if zero and op is not None: if zero and op is not None:
memset(op._c, 0, length * op.ob_descr.itemsize) memset(op._c, 0, length * op.ob_descr.itemsize)
return op return op
...@@ -139,7 +138,7 @@ cdef inline array clone(array template, Py_ssize_t length, bint zero): ...@@ -139,7 +138,7 @@ cdef inline array clone(array template, Py_ssize_t length, bint zero):
cdef inline array copy(array self): cdef inline array copy(array self):
""" make a copy of an array. """ """ make a copy of an array. """
cdef array op cdef array op
op = newarrayobject(self.ob_type, self.length, self.ob_descr) op = newarrayobject(Py_TYPE(self), self.length, self.ob_descr)
memcpy(op._c, self._c, op.length * op.ob_descr.itemsize) memcpy(op._c, self._c, op.length * op.ob_descr.itemsize)
return op return op
......
...@@ -3,6 +3,7 @@ cdef extern from "Python.h": ...@@ -3,6 +3,7 @@ cdef extern from "Python.h":
ctypedef struct PyObject: ctypedef struct PyObject:
Py_ssize_t ob_refcnt Py_ssize_t ob_refcnt
PyTypeObject *ob_type PyTypeObject *ob_type
cdef PyTypeObject *Py_TYPE(object)
##################################################################### #####################################################################
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment