Commit 750ce9c4 authored by Robert Bradshaw's avatar Robert Bradshaw

Pass types as object, not name, in array conversion utility code.

This fixes #1737.
parent b5ef664c
......@@ -2276,8 +2276,7 @@ class CArrayType(CPointerBaseType):
if not self.base_type.create_to_py_utility_code(env):
return False
base_type = self.base_type.declaration_code("", pyrex=1)
safe_typename = re.sub('[^a-zA-Z0-9]', '__', base_type)
safe_typename = self.base_type.specialization_name()
to_py_function = "__Pyx_carray_to_py_%s" % safe_typename
to_tuple_function = "__Pyx_carray_to_tuple_%s" % safe_typename
......@@ -2285,7 +2284,7 @@ class CArrayType(CPointerBaseType):
context = {
'cname': to_py_function,
'to_tuple_cname': to_tuple_function,
'base_type': base_type,
'base_type': self.base_type,
}
env.use_utility_code(CythonUtilityCode.load(
"carray.to_py", "CConvert.pyx",
......@@ -2315,14 +2314,12 @@ class CArrayType(CPointerBaseType):
if not self.base_type.create_from_py_utility_code(env):
return False
base_type = self.base_type.declaration_code("", pyrex=1)
safe_typename = re.sub('[^a-zA-Z0-9]', '__', base_type)
from_py_function = "__Pyx_carray_from_py_%s" % safe_typename
from_py_function = "__Pyx_carray_from_py_%s" % self.base_type.specialization_name()
from .UtilityCode import CythonUtilityCode
context = {
'cname': from_py_function,
'base_type': base_type,
'base_type': self.base_type,
}
env.use_utility_code(CythonUtilityCode.load(
"carray.from_py", "CConvert.pyx",
......
......@@ -5,6 +5,10 @@ IS_PY3 = sys.version_info[0] >= 3
IS_32BIT_PY2 = not IS_PY3 and sys.maxint < 2**32
from libc cimport stdint
from libc.stdint cimport int64_t as my_int64_t
def unlongify(v):
# on 32bit Py2.x platforms, 'unsigned int' coerces to a Python long => fix doctest output here.
s = repr(v)
......@@ -67,6 +71,30 @@ cpdef tuple tuple_from_typedef_int_array():
return v
def from_cimported_int_array():
"""
>>> from_cimported_int_array()
[1, 2, 3]
"""
cdef stdint.int32_t[3] v
v[0] = 1
v[1] = 2
v[2] = 3
return v
def from_cimported_as_int_array():
"""
>>> from_cimported_as_int_array()
[1, 2, 3]
"""
cdef my_int64_t[3] v
v[0] = 1
v[1] = 2
v[2] = 3
return v
def from_int_array_array():
"""
>>> from_int_array_array()
......
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