Commit 91f2c2ed authored by Stefan Behnel's avatar Stefan Behnel

Fix a compiler crash when looking up cython.view.array() as a callable...

Fix a compiler crash when looking up cython.view.array() as a callable function with non-trivial keyword arguments.

Closes #1598.
parent 4b61de60
...@@ -3020,22 +3020,22 @@ class TransformBuiltinMethods(EnvTransform): ...@@ -3020,22 +3020,22 @@ class TransformBuiltinMethods(EnvTransform):
def visit_GeneralCallNode(self, node): def visit_GeneralCallNode(self, node):
function = node.function.as_cython_attribute() function = node.function.as_cython_attribute()
if function: if function == u'cast':
# NOTE: assuming simple tuple/dict nodes for positional_args and keyword_args
args = node.positional_args.args args = node.positional_args.args
kwargs = node.keyword_args.compile_time_value(None) kwargs = node.keyword_args.compile_time_value(None)
if function == u'cast': if (len(args) != 2 or len(kwargs) > 1 or
if (len(args) != 2 or len(kwargs) > 1 or (len(kwargs) == 1 and 'typecheck' not in kwargs)):
(len(kwargs) == 1 and 'typecheck' not in kwargs)): error(node.function.pos,
error(node.function.pos, u"cast() takes exactly two arguments and an optional typecheck keyword")
u"cast() takes exactly two arguments and an optional typecheck keyword") else:
type = args[0].analyse_as_type(self.current_env())
if type:
typecheck = kwargs.get('typecheck', False)
node = ExprNodes.TypecastNode(
node.function.pos, type=type, operand=args[1], typecheck=typecheck)
else: else:
type = args[0].analyse_as_type(self.current_env()) error(args[0].pos, "Not a type")
if type:
typecheck = kwargs.get('typecheck', False)
node = ExprNodes.TypecastNode(
node.function.pos, type=type, operand=args[1], typecheck=typecheck)
else:
error(args[0].pos, "Not a type")
self.visitchildren(node) self.visitchildren(node)
return node return node
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
# these imports allow testing different ways to access [[cython.]view.]array()
from cython.view cimport array from cython.view cimport array
from cython cimport view as v from cython cimport view as v
cimport cython as cy cimport cython as cy
...@@ -20,7 +21,7 @@ def contiguity(): ...@@ -20,7 +21,7 @@ def contiguity():
2 3 2 3
2 2
''' '''
cdef v.array cvarray = v.array(shape=(2,3), itemsize=sizeof(int), format="i", mode='c') cdef v.array cvarray = cy.view.array(shape=(2,3), itemsize=sizeof(int), format="i", mode='c')
assert cvarray.len == 2*3*sizeof(int), (cvarray.len, 2*3*sizeof(int)) assert cvarray.len == 2*3*sizeof(int), (cvarray.len, 2*3*sizeof(int))
assert cvarray.itemsize == sizeof(int) assert cvarray.itemsize == sizeof(int)
print cvarray.strides[0], cvarray.strides[1] print cvarray.strides[0], cvarray.strides[1]
......
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