[Cython] Bug in Cython producing incorrect C code

mark florisson markflorisson88 at gmail.com
Tue Jan 24 19:51:37 CET 2012


On 24 January 2012 18:30, Vitja Makarov <vitja.makarov at gmail.com> wrote:
> 2012/1/24 Robert Bradshaw <robertwb at math.washington.edu>:
>> On Tue, Jan 24, 2012 at 6:09 AM, Vitja Makarov <vitja.makarov at gmail.com> wrote:
>>> 2012/1/24 mark florisson <markflorisson88 at gmail.com>:
>>>> On 24 January 2012 11:37, Konrad Hinsen <konrad.hinsen at fastmail.net> wrote:
>>>>> Compiling the attached Cython file produced the attached C file which
>>>>> has errors in lines 532-534:
>>>>>
>>>>>  __pyx_v_self->xx = None;
>>>>>  __pyx_v_self->yy = None;
>>>>>  __pyx_v_self->zz = None;
>>>>>
>>>>> There is no C symbol "None", so this doesn't compile.
>>>>>
>>>>> I first noticed the bug in Cython 0.15, but it's still in the latest
>>>>> revision from Github.
>>>>>
>>>>> Konrad.
>>>>>
>>>>> _______________________________________________
>>>>> cython-devel mailing list
>>>>> cython-devel at python.org
>>>>> http://mail.python.org/mailman/listinfo/cython-devel
>>>>>
>>>>
>>>> Hm, it seems the problem is that the call to the builtin float results
>>>> in SimpleCallNode being replaced with PythonCApiNode, which then
>>>> generates the result code, but the list of coerced nodes are
>>>> CloneNodes of the original rhs, and CloneNode does not generate the
>>>> result code of the original rhs (i.e. allocate and assign to a temp),
>>>> which results in a None result.
>>>>
>>>> Maybe CascadedAssignmentNode should replace CloneNode.arg with the
>>>> latest self.rhs in generate_assignment_code? I'm not entirely sure.
>
> Seems like a hack to me.
>
>>>
>>>
>>> May be it's better to run OptimizeBuiltinCalls before
>>> AnalyseExpressionsTransform?
>>
>> Doesn't OptimizeBuiltinCalls take advantage of type information?
>
> Yes, it does :(
>
> So as Mark said the problem is CascadedAssignmentNode.coerced_rhs_list
> is created before rhs is updated.
>

I think deferring the CloneNode creation to code generation time works
(are there any known problem with doing type coercions at code
generation time?). E.g. save 'env' during analyse_types and in
generate_assignment_code do

    rhs = CloneNode(self.rhs).coerce_to(lhs.type, self.env)
    rhs.generate_evaluation_code(code)
    lhs.generate_assignment_code(rhs, code)

Seems to work.

>
> --
> vitja.
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel


More information about the cython-devel mailing list