[Cython] Cython-0.17 builtin type import bug
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
[Cython] assignment to reference argument bug, revisited
Are there any plans to fix the "Assignment to reference" bug mentioned here? https://groups.google.com/forum/?fromgroups=#!topic/cython-users/j58Sp3QMrD4 > Oh, yes, of course. Good old C++, where local T& x is unassignable but > assigning to an argument T& x is a common idiom. This is a bug in Cython. This is still broken in 0.19.2, and a casual inspection of 0.20rc1 suggests that it is broken there as well. Is the fix as simple as this? --- ExprNodes.py~ 2014-01-16 12:31:08.377573000 -0500 +++ ExprNodes.py2014-01-16 12:30:56.945501000 -0500 @@ -1605,7 +1605,7 @@ class NameNode(AtomicExprNode): if self.type.is_const: error(self.pos, "Assignment to const '%s'" % self.name) -if self.type.is_reference: +if self.type.is_reference and not self.entry.is_arg: error(self.pos, "Assignment to reference '%s'" % self.name) if not self.is_lvalue(): error(self.pos, "Assignment to non-lvalue '%s'" This seems to work for me, but ... I wonder if it is also correct to set self.entry.cf_unused = True for the case of assignment to reference arguments, to avoid CYTHON_UNUSED annotations in the function definitions and unused variable warnings. -- Bob ___ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel