From a5c394cd7e5070a4581deb4281977e0f32565971 Mon Sep 17 00:00:00 2001
From: Robert Bradshaw <robertwb@gmail.com>
Date: Sun, 13 Jul 2014 03:17:58 -0700
Subject: [PATCH] Handle @cname laziness.

---
 Cython/Compiler/Nodes.py |  5 ++++-
 Cython/Utils.py          | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py
index 33f7df772..643871d4c 100644
--- a/Cython/Compiler/Nodes.py
+++ b/Cython/Compiler/Nodes.py
@@ -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)
diff --git a/Cython/Utils.py b/Cython/Utils.py
index f2eebdae5..23adef6a6 100644
--- a/Cython/Utils.py
+++ b/Cython/Utils.py
@@ -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()
+
-- 
2.30.9