[Pyrex] Bug in CoerceFromPyTypeNode in 0.9.5

Peter Johnson peter at tortall.net
Sun Jan 28 21:34:39 UTC 2007


Testcase:

cdef extern from *:
     ctypedef enum foo:
         FOO
cdef void func():
     cdef foo x
     map = [FOO]
     x = map[0]

Peter

On Sun, 28 Jan 2007, Peter Johnson wrote:

> I've run into a bug in 0.9.5 in ExprNodes.py line 2936:
>
>   File "/usr/local/lib/python2.4/site-packages/Pyrex/Compiler/ExprNodes.py",
> line 402, in generate_evaluation_code
>     self.generate_result_code(code)
>   File "/usr/local/lib/python2.4/site-packages/Pyrex/Compiler/ExprNodes.py",
> line 2936, in generate_result_code
>     rhs = typecast(rhs, self.type, c_long_type)
> NameError: global name 'c_long_type' is not defined
>
> This is a bug (c_long_type needs to be qualified), but changing this to use
> PyrexTypes.c_long_type doesn't get me much further:
>
>   File "/usr/local/lib/python2.4/site-packages/Pyrex/Compiler/ExprNodes.py",
> line 402, in generate_evaluation_code
>     self.generate_result_code(code)
>   File "/usr/local/lib/python2.4/site-packages/Pyrex/Compiler/ExprNodes.py",
> line 2936, in generate_result_code
>     rhs = typecast(rhs, self.type, PyrexTypes.c_long_type)
>   File "/usr/local/lib/python2.4/site-packages/Pyrex/Compiler/PyrexTypes.py",
> line 821, in typecast
>     if to_type is from_type or \
> AttributeError: 'str' object has no attribute 'is_pyobject'
>
> This is because rhs is assigned to a string right before the typecast call in
> ExprNodes.py:
>
>         rhs = "%s(%s)" % (function, operand)
>         if self.type.is_enum:
>             rhs = typecast(rhs, self.type, PyrexTypes.c_long_type)
>
> and the typecast code in PyrexTypes.py is:
>
> def typecast(to_type, from_type, expr_code):
>     if to_type is from_type or \
>         (not to_type.is_pyobject and assignable_from(to_type, from_type)):
>             return expr_code
>     else:
>         #print "typecast: to", to_type, "from", from_type ###
>         return to_type.cast_code(expr_code)
>
> Neither of these code paths handle to_type being a string.  I suspect the bug
> is in the ExprNodes.py function, but I'm not sure what the correct fix is
> supposed to be.
>
> I'll work on getting a small testcase together for this.
>
> Thanks,
> Peter
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>



More information about the Pyrex mailing list