Fix #384
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 1 Oct 2009 18:53:54 +0000 (20:53 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 1 Oct 2009 18:53:54 +0000 (20:53 +0200)
Cython/Compiler/Code.py
Cython/Compiler/ModuleNode.py
Cython/Compiler/PyrexTypes.py
tests/run/division_T384.pyx [new file with mode: 0644]

index ef345faf0f30b6a090265130a18f133dcd29d25e..3a6dc39b89d5b6a481c0bbea13b81c9355f41878 100644 (file)
@@ -24,7 +24,9 @@ class UtilityCode(object):
     #
     # hashes/equals by instance
     
-    def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None):
+    def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None,
+                 proto_block='utility_code_proto'):
+        # proto_block: Which code block to dump prototype in. See GlobalState.
         self.proto = proto
         self.impl = impl
         self.init = init
@@ -32,6 +34,7 @@ class UtilityCode(object):
         self.requires = requires
         self._cache = {}
         self.specialize_list = []
+        self.proto_block = proto_block
 
     def specialize(self, pyrex_type=None, **data):
         # Dicts aren't hashable...
@@ -51,7 +54,7 @@ class UtilityCode(object):
                                         none_or_sub(self.impl, data),
                                         none_or_sub(self.init, data),
                                         none_or_sub(self.cleanup, data),
-                                        requires)
+                                        requires, self.proto_block)
             self.specialize_list.append(s)
             return s
 
@@ -60,7 +63,7 @@ class UtilityCode(object):
             for dependency in self.requires:
                 output.use_utility_code(dependency)
         if self.proto:
-            output['utility_code_proto'].put(self.proto)
+            output[self.proto_block].put(self.proto)
         if self.impl:
             output['utility_code_def'].put(self.impl)
         if self.init:
@@ -390,8 +393,10 @@ class GlobalState(object):
 
     code_layout = [
         'h_code',
-        'utility_code_proto',
+        'complex_numbers_utility_code',
+        'utility_code_proto_before_types',
         'type_declarations',
+        'utility_code_proto',
         'module_declarations',
         'typeinfo',
         'before_global_var',
index 429f8415d298e1729e0ace0bff740ac79191f308..655f0c8d05667d8de2532925d13e00cc5e5e6be8 100644 (file)
@@ -2515,4 +2515,4 @@ packed_struct_utility_code = UtilityCode(proto="""
 #else
 #define __Pyx_PACKED
 #endif
-""", impl="")
+""", impl="", proto_block='utility_code_proto_before_types')
index 17d886c53589a40209e6eb2f27fd0e35914e1cee..88fe325ac91d8082ca7509dbd6b018eebe993633 100644 (file)
@@ -612,7 +612,7 @@ static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x) {
     }
     return (%(type)s)__Pyx_PyInt_As%(SignWord)sLong(x);
 }
-""")
+""") #fool emacs: '
 
 c_long_from_py_function = UtilityCode(
 proto="""
@@ -1013,7 +1013,7 @@ proto="""
     }
 
 #endif
-""")
+""", proto_block='complex_numbers_utility_code')
 
 
 class CArrayType(CType):
diff --git a/tests/run/division_T384.pyx b/tests/run/division_T384.pyx
new file mode 100644 (file)
index 0000000..7c4ba4a
--- /dev/null
@@ -0,0 +1,20 @@
+"""
+>>> test(3)
+(3+1j)
+"""
+
+cimport cython
+
+ctypedef Py_ssize_t index_t
+
+ctypedef double complex mycomplex
+
+ctypedef struct MyStruct:
+    mycomplex a, b
+
+@cython.cdivision(False)
+def test(index_t x):
+    cdef index_t y = x // 2
+    cdef MyStruct s
+    s.a = x + y*1j
+    return s.a