Commit f1543dde authored by Stefan Behnel's avatar Stefan Behnel

Explicitly re-allow memoryviews in default argument structs after disallowing...

Explicitly re-allow memoryviews in default argument structs after disallowing them in structs generally.
Closes #2114.
parent cf12b089
......@@ -9114,7 +9114,6 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
if not arg.default.is_literal:
arg.is_dynamic = True
if arg.type.is_pyobject:
# FIXME: should we include memory views here?
nonliteral_objects.append(arg)
else:
nonliteral_other.append(arg)
......@@ -9152,7 +9151,7 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
for arg in nonliteral_other:
entry = scope.declare_var(arg.name, arg.type, None,
Naming.arg_prefix + arg.name,
allow_pyobject=False)
allow_pyobject=False, allow_memoryview=True)
self.defaults.append((arg, entry))
entry = module_scope.declare_struct_or_union(
None, 'struct', scope, 1, None, cname=cname)
......
......@@ -795,7 +795,7 @@ class CFuncDeclaratorNode(CDeclaratorNode):
scope.declare_var(arg_count_member, PyrexTypes.c_int_type, self.pos)
for arg in func_type.args[len(func_type.args) - self.optional_arg_count:]:
scope.declare_var(arg.name, arg.type, arg.pos, allow_pyobject=1)
scope.declare_var(arg.name, arg.type, arg.pos, allow_pyobject=True, allow_memoryview=True)
struct_cname = env.mangle(Naming.opt_arg_prefix, self.base.name)
......
......@@ -1862,7 +1862,7 @@ class StructOrUnionScope(Scope):
def declare_var(self, name, type, pos,
cname = None, visibility = 'private',
api = 0, in_pxd = 0, is_cdef = 0,
allow_pyobject = 0):
allow_pyobject=False, allow_memoryview=False):
# Add an entry for an attribute.
if not cname:
cname = name
......@@ -1875,7 +1875,7 @@ class StructOrUnionScope(Scope):
self.var_entries.append(entry)
if type.is_pyobject and not allow_pyobject:
error(pos, "C struct/union member cannot be a Python object")
elif type.is_memoryviewslice and not allow_pyobject:
elif type.is_memoryviewslice and not allow_memoryview:
# Memory views wrap their buffer owner as a Python object.
error(pos, "C struct/union member cannot be a memory view")
if visibility != 'private':
......
......@@ -171,6 +171,31 @@ def test_dynamic_defaults_fused():
print "i", i, "func result", f(1.0), "defaults", get_defaults(f)
def test_memoryview_none(const unsigned char[:] b=None):
"""
>>> test_memoryview_none()
>>> test_memoryview_none(None)
>>> test_memoryview_none(b'abc')
97
"""
if b is None:
return None
return b[0]
def test_memoryview_bytes(const unsigned char[:] b=b'xyz'):
"""
>>> test_memoryview_bytes()
120
>>> test_memoryview_bytes(None)
>>> test_memoryview_bytes(b'abc')
97
"""
if b is None:
return None
return b[0]
@cython.test_fail_if_path_exists(
'//NameNode[@entry.in_closure = True]',
'//NameNode[@entry.from_closure = True]')
......
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