Skip to content

Commit

Permalink
Fix fused function default argument coercion (#5614)
Browse files Browse the repository at this point in the history
Python object fused function arguments weren't being correctly
coerced, which meant that sometimes an int was being cast directly
to a PyObject*, causing a crash if you actually tried to use it.
  • Loading branch information
da-woods committed Aug 13, 2023
1 parent c0870f9 commit 6743394
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cython/Compiler/ExprNodes.py
Expand Up @@ -9718,6 +9718,8 @@ def analyse_default_args(self, env):
if not must_use_constants:
if arg.default.is_literal:
arg.default = DefaultLiteralArgNode(arg.pos, arg.default)
if arg.default.type:
arg.default = arg.default.coerce_to(arg.type, env)
else:
arg.is_dynamic = True
if arg.type.is_pyobject:
Expand Down
11 changes: 11 additions & 0 deletions tests/run/fused_def.pyx
Expand Up @@ -135,6 +135,17 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7,
print cython.typeof(obj), cython.typeof(myf), cython.typeof(myi)
print obj, "%.2f" % myf, myi, "%.2f" % f, i

def non_fused_opt(fused_t obj, value=5):
"""
PyObject constants as parts of fused functions weren't being created correctly
which would lead this to crash
>>> non_fused_opt(0)
5
>>> non_fused_opt("str", 10)
10
"""
print value

def run_cyfunction_check():
"""
tp_base of the fused function was being set incorrectly meaning
Expand Down

0 comments on commit 6743394

Please sign in to comment.