Commit 990e1a15 authored by Stefan Behnel's avatar Stefan Behnel

Prevent crash when accessing the "__kwdefaults__" special attribute of fused functions.

Closes #1470.
parent 40ad34a0
...@@ -9460,7 +9460,8 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin): ...@@ -9460,7 +9460,8 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
if self.defaults_kwdict: if self.defaults_kwdict:
code.putln('__Pyx_CyFunction_SetDefaultsKwDict(%s, %s);' % ( code.putln('__Pyx_CyFunction_SetDefaultsKwDict(%s, %s);' % (
self.result(), self.defaults_kwdict.py_result())) self.result(), self.defaults_kwdict.py_result()))
if def_node.defaults_getter: if def_node.defaults_getter and not self.specialized_cpdefs:
# Fused functions do not support dynamic defaults, only their specialisations can have them for now.
code.putln('__Pyx_CyFunction_SetDefaultsGetter(%s, %s);' % ( code.putln('__Pyx_CyFunction_SetDefaultsGetter(%s, %s);' % (
self.result(), def_node.defaults_getter.entry.pyfunc_cname)) self.result(), def_node.defaults_getter.entry.pyfunc_cname))
if self.annotations_dict: if self.annotations_dict:
......
...@@ -58,12 +58,21 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7): ...@@ -58,12 +58,21 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7):
>>> opt_func("spam", f, i) >>> opt_func("spam", f, i)
str object double long str object double long
spam 5.60 9 5.60 9 spam 5.60 9 5.60 9
>>> opt_func("spam", f, myi=i)
str object double long
spam 5.60 9 5.60 9
>>> opt_func("spam", myf=f, myi=i)
str object double long
spam 5.60 9 5.60 9
>>> opt_func[str, float, int]("spam", f, i) >>> opt_func[str, float, int]("spam", f, i)
str object float int str object float int
spam 5.60 9 5.60 9 spam 5.60 9 5.60 9
>>> opt_func[str, cy.double, cy.long]("spam", f, i) >>> opt_func[str, cy.double, cy.long]("spam", f, i)
str object double long str object double long
spam 5.60 9 5.60 9 spam 5.60 9 5.60 9
>>> opt_func[str, cy.double, cy.long]("spam", f, myi=i)
str object double long
spam 5.60 9 5.60 9
>>> opt_func[str, float, cy.int]("spam", f, i) >>> opt_func[str, float, cy.int]("spam", f, i)
str object float int str object float int
spam 5.60 9 5.60 9 spam 5.60 9 5.60 9
...@@ -129,6 +138,28 @@ def test_opt_func(): ...@@ -129,6 +138,28 @@ def test_opt_func():
opt_func("ham", f, entry4) opt_func("ham", f, entry4)
def test_opt_func_introspection():
"""
>>> opt_func.__defaults__
(1.2, 7)
>>> opt_func.__kwdefaults__
>>> opt_func.__annotations__
{}
>>> opt_func[str, float, int].__defaults__
(1.2, 7)
>>> opt_func[str, float, int].__kwdefaults__
>>> opt_func[str, float, int].__annotations__
{}
>>> opt_func[str, cy.double, cy.long].__defaults__
(1.2, 7)
>>> opt_func[str, cy.double, cy.long].__kwdefaults__
>>> opt_func[str, cy.double, cy.long].__annotations__
{}
"""
def func_with_object(fused_with_object obj, cython.integral myi = 7): def func_with_object(fused_with_object obj, cython.integral myi = 7):
""" """
>>> func_with_object(1) >>> func_with_object(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