cython-devel

changeset 2365:09b4a8a9798b

Fix #384
author Dag Sverre Seljebotn <dagss@student.matnat.uio.no>
date Thu Oct 01 20:53:54 2009 +0200 (3 years ago)
parents 2b16874a1779
children 6996543cb873
files Cython/Compiler/Code.py Cython/Compiler/ModuleNode.py Cython/Compiler/PyrexTypes.py tests/run/division_T384.pyx
line diff
1.1 --- a/Cython/Compiler/Code.py Sat Sep 26 23:05:04 2009 -0700 1.2 +++ b/Cython/Compiler/Code.py Thu Oct 01 20:53:54 2009 +0200 1.3 @@ -24,7 +24,9 @@ 1.4 # 1.5 # hashes/equals by instance 1.6 1.7 - def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None): 1.8 + def __init__(self, proto=None, impl=None, init=None, cleanup=None, requires=None, 1.9 + proto_block='utility_code_proto'): 1.10 + # proto_block: Which code block to dump prototype in. See GlobalState. 1.11 self.proto = proto 1.12 self.impl = impl 1.13 self.init = init 1.14 @@ -32,6 +34,7 @@ 1.15 self.requires = requires 1.16 self._cache = {} 1.17 self.specialize_list = [] 1.18 + self.proto_block = proto_block 1.19 1.20 def specialize(self, pyrex_type=None, **data): 1.21 # Dicts aren't hashable... 1.22 @@ -51,7 +54,7 @@ 1.23 none_or_sub(self.impl, data), 1.24 none_or_sub(self.init, data), 1.25 none_or_sub(self.cleanup, data), 1.26 - requires) 1.27 + requires, self.proto_block) 1.28 self.specialize_list.append(s) 1.29 return s 1.30 1.31 @@ -60,7 +63,7 @@ 1.32 for dependency in self.requires: 1.33 output.use_utility_code(dependency) 1.34 if self.proto: 1.35 - output['utility_code_proto'].put(self.proto) 1.36 + output[self.proto_block].put(self.proto) 1.37 if self.impl: 1.38 output['utility_code_def'].put(self.impl) 1.39 if self.init: 1.40 @@ -390,8 +393,10 @@ 1.41 1.42 code_layout = [ 1.43 'h_code', 1.44 + 'complex_numbers_utility_code', 1.45 + 'utility_code_proto_before_types', 1.46 + 'type_declarations', 1.47 'utility_code_proto', 1.48 - 'type_declarations', 1.49 'module_declarations', 1.50 'typeinfo', 1.51 'before_global_var',
2.1 --- a/Cython/Compiler/ModuleNode.py Sat Sep 26 23:05:04 2009 -0700 2.2 +++ b/Cython/Compiler/ModuleNode.py Thu Oct 01 20:53:54 2009 +0200 2.3 @@ -2515,4 +2515,4 @@ 2.4 #else 2.5 #define __Pyx_PACKED 2.6 #endif 2.7 -""", impl="") 2.8 +""", impl="", proto_block='utility_code_proto_before_types')
3.1 --- a/Cython/Compiler/PyrexTypes.py Sat Sep 26 23:05:04 2009 -0700 3.2 +++ b/Cython/Compiler/PyrexTypes.py Thu Oct 01 20:53:54 2009 +0200 3.3 @@ -612,7 +612,7 @@ 3.4 } 3.5 return (%(type)s)__Pyx_PyInt_As%(SignWord)sLong(x); 3.6 } 3.7 -""") 3.8 +""") #fool emacs: ' 3.9 3.10 c_long_from_py_function = UtilityCode( 3.11 proto=""" 3.12 @@ -1013,7 +1013,7 @@ 3.13 } 3.14 3.15 #endif 3.16 -""") 3.17 +""", proto_block='complex_numbers_utility_code') 3.18 3.19 3.20 class CArrayType(CType):
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tests/run/division_T384.pyx Thu Oct 01 20:53:54 2009 +0200 4.3 @@ -0,0 +1,20 @@ 4.4 +""" 4.5 +>>> test(3) 4.6 +(3+1j) 4.7 +""" 4.8 + 4.9 +cimport cython 4.10 + 4.11 +ctypedef Py_ssize_t index_t 4.12 + 4.13 +ctypedef double complex mycomplex 4.14 + 4.15 +ctypedef struct MyStruct: 4.16 + mycomplex a, b 4.17 + 4.18 +@cython.cdivision(False) 4.19 +def test(index_t x): 4.20 + cdef index_t y = x // 2 4.21 + cdef MyStruct s 4.22 + s.a = x + y*1j 4.23 + return s.a