Skip to content

Commit

Permalink
Merge 3578115 into 3a3d414
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Nov 24, 2018
2 parents 3a3d414 + 3578115 commit de79e1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import array
import glob
import os
import sys
Expand Down Expand Up @@ -68,6 +69,12 @@ def run_tests(self):
"DEF PY2K = " + str(sys.version_info.major == 2) + "\n",
"DEF PY3K = " + str(sys.version_info.major == 3) + "\n"
])
if sys.version_info.major < 4:
Py_UNICODE_SIZE = array.array('u').itemsize
f.writelines([
"DEF Py_UNICODE_SIZE = " + str(Py_UNICODE_SIZE) + "\n",
])

with open("src/version.pxi", "w") as f:
f.writelines([
"__version__ = " + "\"" + str(version) + "\""
Expand Down
11 changes: 3 additions & 8 deletions src/cybuffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ include "version.pxi"


cdef extern from "Python.h":
size_t Py_UNICODE_SIZE

object PyMemoryView_FromObject(object obj)


Expand Down Expand Up @@ -162,15 +160,12 @@ cdef class cybuffer(object):
# Workaround some special cases with the builtin array
cdef size_t len_nd_b
cdef int n_1
if isinstance(self.obj, array):
if (PY2K or PY3K) and isinstance(self.obj, array):
# Fix-up typecode
typecode = self.obj.typecode
if typecode == "B":
return
elif PY2K and typecode == "c":
self._format = UBYTE_TC
if typecode == "B" or (PY2K and typecode == "c"):
return
elif (PY2K or PY3K) and typecode == "u":
elif typecode == "u":
if Py_UNICODE_SIZE == 2:
self._format = UCS2_TC
elif Py_UNICODE_SIZE == 4:
Expand Down

0 comments on commit de79e1e

Please sign in to comment.