Commit 7b95089f authored by Stefan Behnel's avatar Stefan Behnel

Use global constants for default arguments of cpdef functions/methods and def...

Use global constants for default arguments of cpdef functions/methods and def methods in cdef classes as using the CyFunction defaults requires passing the CyFunction as self (which we currently don't do for methods in cdef classes).
Properly fixing this requires changing the call signature of CyFunction.
parent f857f09f
...@@ -8733,11 +8733,12 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin): ...@@ -8733,11 +8733,12 @@ class PyCFunctionNode(ExprNode, ModuleNameMixin):
default_kwargs = [] default_kwargs = []
annotations = [] annotations = []
# For global cpdef functions and cpdef methods in cdef classes, we must use global constants # For global cpdef functions and def/cpdef methods in cdef classes, we must use global constants
# for default arguments to avoid the dependency on the CyFunction object as 'self' argument # for default arguments to avoid the dependency on the CyFunction object as 'self' argument
# in the underlying C function. Basically, cpdef functions/methods are static C functions, # in the underlying C function. Basically, cpdef functions/methods are static C functions,
# so their optional arguments must be static, too. # so their optional arguments must be static, too.
must_use_constants = self.def_node.is_wrapper and (env.is_c_class_scope or env.is_module_scope) # TODO: change CyFunction implementation to pass both function object and owning object for method calls
must_use_constants = env.is_c_class_scope or (self.def_node.is_wrapper and env.is_module_scope)
for arg in self.def_node.args: for arg in self.def_node.args:
if arg.default and not must_use_constants: if arg.default and not must_use_constants:
......
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