If a builtin type that differs between Python 2 and 3 (e.g., unicode) is imported, then malformed C code is emitted by Cython-0.17: there is an extraneous, unbalanced #if.
Here's a small reproducer: shell$ cat foo.pyx cdef extern from "Python.h": ctypedef class __builtin__.unicode [object PyUnicodeObject]: pass shell$ cython foo.pyx warning: foo.pyx:2:4: unicode already a builtin Cython type shell$ gcc -c -fPIC -I/usr/include/python2.6 foo.c foo.c:5:1: error: unterminated #else foo.c: In function 'initfoo': foo.c:574: error: expected declaration or statement at end of input foo.c:535: error: label '__pyx_L1_error' used but not defined This works for Cython-0.16 and earlier. I think this was broken by ... https://github.com/cython/cython/commit/558f4ef1c48ce091fa15b9319eb0f92cd4758f09 This patch for ModuleNode.generate_type_import_call seems to fix it: --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2281,7 +2281,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): module_name = '__Pyx_BUILTIN_MODULE_NAME' if type.name in Code.non_portable_builtins_map: condition, replacement = Code.non_portable_builtins_map[type.name] - code.putln("#if %s" % condition) if objstruct in Code.basicsize_builtins_map: # Some builtin types have a tp_basicsize which differs from sizeof(...): sizeof_objstruct = Code.basicsize_builtins_map[objstruct] Thanks, -- Bob _______________________________________________ cython-devel mailing list cython-devel@python.org http://mail.python.org/mailman/listinfo/cython-devel