[Python-apps-team] Bug#641128: Bug#641128: cython: Compiler crash on 'DEF degree = 3.14/180' (squeeze regression)

Kirill Smelkov kirr at mns.spb.ru
Tue Sep 13 08:39:26 UTC 2011


package cython
tags 641128 patch fixed-upstream
thanks


Yaroslav, Ondřej,

On Sat, Sep 10, 2011 at 01:54:55PM -0400, Yaroslav Halchenko wrote:
> Hi Kirill,
> 
> could you please check if this issue is present in current cython
> version present in Debian unstable/testing 0.14.1 (or may be even recent
> upstream release, 0.15 iirc) ?

On Sat, Sep 10, 2011 at 02:52:52PM -0700, Ondřej Čertík wrote:
> Hi Kirill!
> 
> [snip]
>
> Thanks for reporting the bug. I verified, that it is present in
> 0.14.1+, but in the latest git master (upstream) b1adce4, it works
> again. So I assume it was already fixed upstream.


Thanks for providing feedback. Yes, the bug is already fixed in upstream
master, so I've bisected it and here are the results:

The bug was first introduced in 0.11.rc-407-g3d2aa77

commit 3d2aa773bd79e1e5751de2ea2148696f52580f42
Author: Stefan Behnel <scoder at users.berlios.de>
Date:   Wed Jul 8 21:13:14 2009 +0200

    fix __future__ division semantics for constant expressions and C integers
    
    --HG--
    rename : tests/run/future_division.pyx => tests/run/non_future_division.pyx

[...]
+    def find_compile_time_binary_operator(self, op1, op2):
+        func = compile_time_binary_operators[self.operator]
+        if self.operator == '/' and self.truedivision is None:
+            # => true div for floats, floor div for integers
+            if isinstance(op1, (int,long)) and isinstance(op2, (int,long)):
+                func = compile_time_binary_operators['//']
+        return func
+
+    def calculate_constant_result(self):
+        op1 = self.operand1.constant_result
+        op2 = self.operand2.constant_result
+        func = self.find_compile_time_binary_operator(op1, op2)
+        self.constant_result = func(
+            self.operand1.constant_result,
+            self.operand2.constant_result)
+
+    def compile_time_value(self, denv):
+        operand1 = self.operand1.compile_time_value(denv)
+        operand2 = self.operand2.compile_time_value(denv)
+        try:
+            func = self.find_compile_time_binary_operator(
+                self, operand1, operand2)
                 ^^^^
with erroneous extra `self`,


and fixed in 0.14.1-111-g78e134e (unfortunately without tests):

commit 78e134ede7646bacfaaafb71172fd4f86b890d0f
Author: Robert Bradshaw <robertwb at math.washington.edu>
Date:   Thu Mar 3 11:07:23 2011 -0800

    Fix compile time division.

diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py
index c965251..1fe8538 100755
--- a/Cython/Compiler/ExprNodes.py
+++ b/Cython/Compiler/ExprNodes.py
@@ -5992,7 +5992,7 @@ class DivNode(NumBinopNode):
         operand2 = self.operand2.compile_time_value(denv)
         try:
             func = self.find_compile_time_binary_operator(
-                self, operand1, operand2)
+                operand1, operand2)
             return func(operand1, operand2)
         except Exception, e:
             self.compile_time_value_error(e)


which I think should be backported to Debian Cython packages.



Thanks,
Kirill


P.S.

> What exactly is "def degree = 1.0" supposed to do? I know what this does:
> 
> cdef double degree = 1.0
> 
> But that is something different (I assume).

It's a compile-time definition. From Pyrex manual [1]:

"""
Conditional Compilation
=======================

Some features are available for conditional compilation and
compile-time constants within a Pyrex source file.
 
Compile-Time Definitions
------------------------

A compile-time constant can be defined using the DEF statement:
 
    DEF FavouriteFood = "spam"
    DEF ArraySize = 42
    DEF OtherArraySize = 2 * ArraySize + 17

The right-hand side of the DEF must be a valid compile-time expression.
Such expressions are made up of literal values and names defined using
DEF statements, combined using any of the Python expression syntax.

...
"""

[1] http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/version/Doc/Manual/basics.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-compile-time-division.patch
Type: text/x-diff
Size: 875 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/python-apps-team/attachments/20110913/dc9aed4c/attachment.patch>


More information about the Python-apps-team mailing list