Commit 6fc9c910 authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Fix #384

parent d36f3b8a
...@@ -24,7 +24,9 @@ class UtilityCode(object): ...@@ -24,7 +24,9 @@ class UtilityCode(object):
# #
# hashes/equals by instance # 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.proto = proto
self.impl = impl self.impl = impl
self.init = init self.init = init
...@@ -32,6 +34,7 @@ class UtilityCode(object): ...@@ -32,6 +34,7 @@ class UtilityCode(object):
self.requires = requires self.requires = requires
self._cache = {} self._cache = {}
self.specialize_list = [] self.specialize_list = []
self.proto_block = proto_block
def specialize(self, pyrex_type=None, **data): def specialize(self, pyrex_type=None, **data):
# Dicts aren't hashable... # Dicts aren't hashable...
...@@ -51,7 +54,7 @@ class UtilityCode(object): ...@@ -51,7 +54,7 @@ class UtilityCode(object):
none_or_sub(self.impl, data), none_or_sub(self.impl, data),
none_or_sub(self.init, data), none_or_sub(self.init, data),
none_or_sub(self.cleanup, data), none_or_sub(self.cleanup, data),
requires) requires, self.proto_block)
self.specialize_list.append(s) self.specialize_list.append(s)
return s return s
...@@ -60,7 +63,7 @@ class UtilityCode(object): ...@@ -60,7 +63,7 @@ class UtilityCode(object):
for dependency in self.requires: for dependency in self.requires:
output.use_utility_code(dependency) output.use_utility_code(dependency)
if self.proto: if self.proto:
output['utility_code_proto'].put(self.proto) output[self.proto_block].put(self.proto)
if self.impl: if self.impl:
output['utility_code_def'].put(self.impl) output['utility_code_def'].put(self.impl)
if self.init: if self.init:
...@@ -390,8 +393,10 @@ class GlobalState(object): ...@@ -390,8 +393,10 @@ class GlobalState(object):
code_layout = [ code_layout = [
'h_code', 'h_code',
'utility_code_proto', 'complex_numbers_utility_code',
'utility_code_proto_before_types',
'type_declarations', 'type_declarations',
'utility_code_proto',
'module_declarations', 'module_declarations',
'typeinfo', 'typeinfo',
'before_global_var', 'before_global_var',
......
...@@ -2515,4 +2515,4 @@ packed_struct_utility_code = UtilityCode(proto=""" ...@@ -2515,4 +2515,4 @@ packed_struct_utility_code = UtilityCode(proto="""
#else #else
#define __Pyx_PACKED #define __Pyx_PACKED
#endif #endif
""", impl="") """, impl="", proto_block='utility_code_proto_before_types')
...@@ -612,7 +612,7 @@ static INLINE %(type)s __Pyx_PyInt_As%(SignWord)s%(TypeName)s(PyObject* x) { ...@@ -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); return (%(type)s)__Pyx_PyInt_As%(SignWord)sLong(x);
} }
""") """) #fool emacs: '
c_long_from_py_function = UtilityCode( c_long_from_py_function = UtilityCode(
proto=""" proto="""
...@@ -1013,7 +1013,7 @@ proto=""" ...@@ -1013,7 +1013,7 @@ proto="""
} }
#endif #endif
""") """, proto_block='complex_numbers_utility_code')
class CArrayType(CType): class CArrayType(CType):
......
"""
>>> 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment