[Pyrex] Bad code generation in Pyrex 0.9.4.1

Daniele Varrazzo daniele.varrazzo at gmail.com
Wed Oct 4 22:27:10 UTC 2006


On 9/28/06, Konrad Hinsen <konrad.hinsen at laposte.net> wrote:
> I think I found a bug in Pyrex; it generates bad C code for one of my
> modules. Reduced to the bare minimum, my Pyrex module becomes
>
>         cdef class vector:
>             def __div__(vector self, double factor):
>                 result = vector()
>                 return result

Maybe the following patch fixes the problem. With the patch on,
__pyx_v_result is assigned before  __pyx_v_factor, so it is ready to
be DECREF'd in case of __pyx_v_factor conversion failure.

I wasn't be able to reproduce the segfault anyway - but the code was
obviously wrong.

I neither could test the fix with other examples but yours: i checked
my Pyrex projects and i never used code triggering the bug.

I'd like to report regression test results, but i don't have a mac
handy. I'd rather try to let the unittest work on linux.

Please, let me know if the patch is acceptable.

Daniele

--- Nodes.py.bak        2006-10-04 23:53:18.000000000 +0200
+++ Nodes.py    2006-10-04 23:53:20.000000000 +0200
@@ -1722,11 +1722,11 @@
         self.generate_argument_parsing_code(code)
         self.generate_argument_increfs(lenv, code)
         #self.generate_stararg_getting_code(code)
-        self.generate_argument_conversion_code(code)
         # ----- Initialise local variables
         for entry in lenv.var_entries:
             if entry.type.is_pyobject and entry.init_to_none:
                 code.put_init_var_to_py_none(entry)
+        self.generate_argument_conversion_code(code)
         # ----- Check types of arguments
         self.generate_argument_type_tests(code)
         # ----- Function body



More information about the Pyrex mailing list