Commit a5c394cd authored by Robert Bradshaw's avatar Robert Bradshaw

Handle @cname laziness.

parent 191b9231
......@@ -27,6 +27,7 @@ from .Code import UtilityCode
from .StringEncoding import EncodedString, escape_byte_string, split_string_literal
from . import Options
from . import DebugFlags
from Cython.Utils import LazyStr
absolute_path_length = 0
......@@ -2307,7 +2308,9 @@ class CFuncDefNode(FuncDefNode):
if omit_optional_args:
args = args[:len(args) - self.type.optional_arg_count]
arg_names = [arg.name for arg in args]
cfunc = ExprNodes.PythonCapiFunctionNode(self.pos, self.entry.name, self.entry.func_cname, self.type)
# The @cname decorator may mutate this later.
func_cname = LazyStr(lambda: self.entry.func_cname)
cfunc = ExprNodes.PythonCapiFunctionNode(self.pos, self.entry.name, func_cname, self.type)
cfunc.entry = self.entry
skip_dispatch = not is_module_scope or Options.lookup_module_cpdef
c_call = ExprNodes.SimpleCallNode(self.pos, function=cfunc, args=[ExprNodes.NameNode(self.pos, name=n) for n in arg_names], wrapper_call=skip_dispatch)
......
......@@ -399,3 +399,16 @@ def print_bytes(s, end=b'\n', file=sys.stdout, flush=True):
out.write(end)
if flush:
out.flush()
class LazyStr:
def __init__(self, callback):
self.callback = callback
def __str__(self):
return self.callback()
def __repr__(self):
return self.callback()
def __add__(self, right):
return self.callback() + right
def __radd__(self, left):
return left + self.callback()
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