Commit efc33c7c authored by Mark Florisson's avatar Mark Florisson

Disallow taking address of memoryview slices

parent 59c083a1
...@@ -244,7 +244,7 @@ class ExprNode(Node): ...@@ -244,7 +244,7 @@ class ExprNode(Node):
return 0 return 0
def is_addressable(self): def is_addressable(self):
return self.is_lvalue() return self.is_lvalue() and not self.type.is_memoryviewslice
def is_ephemeral(self): def is_ephemeral(self):
# An ephemeral node is one whose result is in # An ephemeral node is one whose result is in
...@@ -1638,7 +1638,7 @@ class NameNode(AtomicExprNode): ...@@ -1638,7 +1638,7 @@ class NameNode(AtomicExprNode):
not self.entry.is_readonly not self.entry.is_readonly
def is_addressable(self): def is_addressable(self):
return self.entry.is_variable return self.entry.is_variable and not self.type.is_memoryviewslice
def is_ephemeral(self): def is_ephemeral(self):
# Name nodes are never ephemeral, even if the # Name nodes are never ephemeral, even if the
...@@ -7069,7 +7069,10 @@ class AmpersandNode(ExprNode): ...@@ -7069,7 +7069,10 @@ class AmpersandNode(ExprNode):
self.operand.analyse_types(env) self.operand.analyse_types(env)
argtype = self.operand.type argtype = self.operand.type
if not (argtype.is_cfunction or self.operand.is_addressable()): if not (argtype.is_cfunction or self.operand.is_addressable()):
self.error("Taking address of non-lvalue") if argtype.is_memoryviewslice:
self.error("Cannot take address of memoryview slice")
else:
self.error("Taking address of non-lvalue")
return return
if argtype.is_pyobject: if argtype.is_pyobject:
self.error("Cannot take address of Python variable") self.error("Cannot take address of Python variable")
......
...@@ -60,6 +60,9 @@ four_D[None, None, None, None, None] ...@@ -60,6 +60,9 @@ four_D[None, None, None, None, None]
cdef int[:, :, :, :, :, :, :, :] eight_D = object() cdef int[:, :, :, :, :, :, :, :] eight_D = object()
cdef double[:] m
print <long> &m
# These are VALID # These are VALID
cdef int[::view.indirect_contiguous, ::view.contiguous] a9 cdef int[::view.indirect_contiguous, ::view.contiguous] a9
four_D[None, None, None] four_D[None, None, None]
...@@ -89,4 +92,5 @@ _ERRORS = u''' ...@@ -89,4 +92,5 @@ _ERRORS = u'''
58:6: More dimensions than the maximum number of buffer dimensions were used. 58:6: More dimensions than the maximum number of buffer dimensions were used.
59:6: More dimensions than the maximum number of buffer dimensions were used. 59:6: More dimensions than the maximum number of buffer dimensions were used.
61:9: More dimensions than the maximum number of buffer dimensions were used. 61:9: More dimensions than the maximum number of buffer dimensions were used.
64:13: Cannot take address of memoryview slice
''' '''
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