Commit c0440965 authored by Mark Florisson's avatar Mark Florisson

Provide better error message when memoryview data cannot be converted to object

parent bd673cc3
...@@ -2548,7 +2548,6 @@ class IndexNode(ExprNode): ...@@ -2548,7 +2548,6 @@ class IndexNode(ExprNode):
warning(index.pos, "Index should be typed for more " warning(index.pos, "Index should be typed for more "
"efficient access", level=2) "efficient access", level=2)
IndexNode.warned_untyped_idx = True IndexNode.warned_untyped_idx = True
elif index.type.is_int:
self.memslice_index = True self.memslice_index = True
index = index.coerce_to(index_type, env) index = index.coerce_to(index_type, env)
indices[i] = index indices[i] = index
......
...@@ -341,11 +341,14 @@ cdef class memoryview(object): ...@@ -341,11 +341,14 @@ cdef class memoryview(object):
cdef bytes bytesitem cdef bytes bytesitem
# Do a manual and complete check here instead of this easy hack # Do a manual and complete check here instead of this easy hack
bytesitem = itemp[:self.view.itemsize] bytesitem = itemp[:self.view.itemsize]
result = struct.unpack(self.view.format, bytesitem) try:
if len(self.view.format) == 1: result = struct.unpack(self.view.format, bytesitem)
return result[0] except struct.error:
raise ValueError("Unable to convert item to object")
return result else:
if len(self.view.format) == 1:
return result[0]
return result
cdef assign_item_from_object(self, char *itemp, object value): cdef assign_item_from_object(self, char *itemp, object value):
"""Only used if instantiated manually by the user, or if Cython doesn't """Only used if instantiated manually by the user, or if Cython doesn't
......
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