From 3363dff2449814d83347d1bc40a0dffb14d6e308 Mon Sep 17 00:00:00 2001
From: Nikita Nemkin <nikita@nemkin.ru>
Date: Sat, 2 Mar 2013 01:57:52 +0600
Subject: [PATCH] Fixed explicit coercion of ctypedef'ed C types.

---
 Cython/Compiler/PyrexTypes.py     |   16 +++++++++-------
 tests/run/ctypedef_delegation.pyx |    9 +++++++++
 2 files changed, 18 insertions(+), 7 deletions(-)
 create mode 100644 tests/run/ctypedef_delegation.pyx

diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py
index 38b6982..c8116f7 100755
--- a/Cython/Compiler/PyrexTypes.py
+++ b/Cython/Compiler/PyrexTypes.py
@@ -295,9 +295,9 @@ def create_typedef_type(name, base_type, cname, is_external=0):
 class CTypedefType(BaseType):
     #
     #  Pseudo-type defined with a ctypedef statement in a
-    #  'cdef extern from' block. Delegates most attribute
-    #  lookups to the base type. ANYTHING NOT DEFINED
-    #  HERE IS DELEGATED!
+    #  'cdef extern from' block.
+    #  Delegates most attribute lookups to the base type.
+    #  (Anything not defined here or in the BaseType is delegated.)
     #
     #  qualified_name      string
     #  typedef_name        string
@@ -439,6 +439,9 @@ class CTypedefType(BaseType):
     def py_type_name(self):
         return self.typedef_base_type.py_type_name()
 
+    def can_coerce_to_pyobject(self, env):
+        return self.typedef_base_type.can_coerce_to_pyobject(env)
+
 
 class MemoryViewSliceType(PyrexType):
 
@@ -774,10 +777,9 @@ class MemoryViewSliceType(PyrexType):
 
 class BufferType(BaseType):
     #
-    #  Delegates most attribute
-    #  lookups to the base type. ANYTHING NOT DEFINED
-    #  HERE IS DELEGATED!
-
+    #  Delegates most attribute lookups to the base type.
+    #  (Anything not defined here or in the BaseType is delegated.)
+    #
     # dtype            PyrexType
     # ndim             int
     # mode             str
diff --git a/tests/run/ctypedef_delegation.pyx b/tests/run/ctypedef_delegation.pyx
new file mode 100644
index 0000000..19adfc2
--- /dev/null
+++ b/tests/run/ctypedef_delegation.pyx
@@ -0,0 +1,9 @@
+
+ctypedef char* LPSTR
+
+def typedef_delegation():
+    """
+    >>> typedef_delegation()
+    """
+    cdef LPSTR c_str = b"ascii"
+    assert <bytes>c_str == b"ascii"
-- 
1.7.3.1.msysgit.0

