Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue trying list.index indexing in FusedNode #5896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions Cython/Compiler/FusedNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,11 @@ def copy_cdef(self, env):
break

# replace old entry with new entries
try:
if self.node.entry in env.cfunc_entries:
cindex = env.cfunc_entries.index(self.node.entry)
except ValueError:
env.cfunc_entries.extend(new_cfunc_entries)
else:
env.cfunc_entries[cindex:cindex+1] = new_cfunc_entries
else:
env.cfunc_entries.extend(new_cfunc_entries)

if orig_py_func:
self.py_func = self.make_fused_cpdef(orig_py_func, env,
Expand Down
7 changes: 6 additions & 1 deletion Cython/Compiler/PyrexTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3294,7 +3294,12 @@ def declaration_code(self, entity_code,
if self.is_overridable:
arg_decl_list.append("int %s" % Naming.skip_dispatch_cname)
if self.optional_arg_count:
arg_decl_list.append(self.op_arg_struct.declaration_code(Naming.optional_args_cname))
if self.op_arg_struct:
arg_decl_list.append(self.op_arg_struct.declaration_code(Naming.optional_args_cname))
else:
# op_arg_struct may not be initialized at this point if this class is being used
# to prepare a Python error message or similar. In this case, just omit the args.
assert for_display
if self.has_varargs:
arg_decl_list.append("...")
arg_decl_code = ", ".join(arg_decl_list)
Expand Down
4 changes: 4 additions & 0 deletions tests/run/fused_cpdef.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cimport cython

cdef class C:
cpdef object has_default_struct(self, cython.floating x, a=?)
13 changes: 13 additions & 0 deletions tests/run/fused_cpdef.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,16 @@ def test_defaults():
>>> mutable_default(3,[])
[3]
"""

cdef class C:
cpdef object has_default_struct(self, cython.floating x, a=None):
return x, a

# https://github.com/cython/cython/issues/5588
# On some Python versions this was causing a compiler crash
def test_call_has_default_struct(C c, double x):
"""
>>> test_call_has_default_struct(C(), 5.)
(5.0, None)
"""
return c.has_default_struct(x)