From: Dag Sverre Seljebotn Date: Thu, 1 Oct 2009 18:53:54 +0000 (+0200) Subject: Fix #384 X-Git-Tag: 0.12.alpha0~188 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6fc9c910cdabd9242cf9c14d238a7bbf9c461a9b;p=cython.git Fix #384 --- diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index ef345faf..3a6dc39b 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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', diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 429f8415..655f0c8d 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2515,4 +2515,4 @@ packed_struct_utility_code = UtilityCode(proto=""" #else #define __Pyx_PACKED #endif -""", impl="") +""", impl="", proto_block='utility_code_proto_before_types') diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 17d886c5..88fe325a 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -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 index 00000000..7c4ba4ab --- /dev/null +++ b/tests/run/division_T384.pyx @@ -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