Commit 50cba685 authored by Robert Bradshaw's avatar Robert Bradshaw

Array variables have an address despite not being lvalues.

parent 7b8f9874
......@@ -237,6 +237,9 @@ class ExprNode(Node):
def is_lvalue(self):
return 0
def is_addressable(self):
return self.is_lvalue()
def is_ephemeral(self):
# An ephemeral node is one whose result is in
# a Python temporary and we suspect there are no
......@@ -1619,6 +1622,9 @@ class NameNode(AtomicExprNode):
not self.entry.type.is_array and \
not self.entry.is_readonly
def is_addressable(self):
return self.entry.is_variable
def is_ephemeral(self):
# Name nodes are never ephemeral, even if the
# result is in a temporary.
......@@ -6576,7 +6582,7 @@ class AmpersandNode(ExprNode):
def analyse_types(self, env):
self.operand.analyse_types(env)
argtype = self.operand.type
if not (argtype.is_cfunction or self.operand.is_lvalue()):
if not (argtype.is_cfunction or self.operand.is_addressable()):
self.error("Taking address of non-lvalue")
return
if argtype.is_pyobject:
......
ctypedef int five_ints[5]
def test_array_address(int ix, int x):
"""
>>> test_array_address(0, 100)
100
>>> test_array_address(2, 200)
200
"""
cdef five_ints a
a[:] = [1, 2, 3, 4, 5]
cdef five_ints *a_ptr = &a
a_ptr[0][ix] = x
return a[ix]
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