#
# 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
self.requires = requires
self._cache = {}
self.specialize_list = []
+ self.proto_block = proto_block
def specialize(self, pyrex_type=None, **data):
# Dicts aren't hashable...
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
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:
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',
--- /dev/null
+"""
+>>> 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