Skip to content

Commit

Permalink
Set itemsize and format for array on Python 2
Browse files Browse the repository at this point in the history
Go ahead and set `itemsize` at the same time that `format` is being set
for the Python 2 `array` cases. These two properties are connected and
naturally go together. So this makes a bit more sense from a code
readability point of view.
  • Loading branch information
jakirkham committed Nov 24, 2018
1 parent 3578115 commit 7b09039
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cybuffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,18 @@ cdef class cybuffer(object):
if typecode == "B" or (PY2K and typecode == "c"):
return
elif typecode == "u":
if PY2K:
self.itemsize = Py_UNICODE_SIZE
if Py_UNICODE_SIZE == 2:
self._format = UCS2_TC
elif Py_UNICODE_SIZE == 4:
self._format = UCS4_TC
elif PY2K:
self.itemsize = self.obj.itemsize
self._format = typecode

# Adjust itemsize, shape, and strides based on casting
# Adjust shape and strides based on casting
if PY2K:
self.itemsize = self.obj.itemsize

len_nd_b = self._buf.ndim * sizeof(Py_ssize_t)
self._shape = <Py_ssize_t*>cpython.mem.PyMem_Malloc(len_nd_b)
self._strides = <Py_ssize_t*>cpython.mem.PyMem_Malloc(len_nd_b)
Expand Down

0 comments on commit 7b09039

Please sign in to comment.