Fix obscure bug w/ complex (only present when compiling many files in one run)
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 14 May 2009 17:42:54 +0000 (19:42 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Thu, 14 May 2009 17:42:54 +0000 (19:42 +0200)
Cython/Compiler/PyrexTypes.py

index 17e4cf597efae036685900e26f19a27a63d73a1a..6cc6e511929891bca8b49ff76924eb97ddb6af70 100644 (file)
@@ -718,6 +718,7 @@ class CComplexType(CNumericType):
         self.real_type = real_type
         CNumericType.__init__(self, real_type.rank + 0.5, real_type.signed)
         self.binops = {}
+        self.from_parts = "%s_from_parts" % self.specalization_name()
     
     def __cmp__(self, other):
         if isinstance(self, CComplexType) and isinstance(other, CComplexType):
@@ -737,13 +738,13 @@ class CComplexType(CNumericType):
                     or src_type is error_type)
 
     def create_declaration_utility_code(self, env):
-        if not hasattr(self, 'from_parts'):
-            self.from_parts = "%s_from_parts" % self.specalization_name()
-            env.use_utility_code(complex_generic_utility_code)
-            env.use_utility_code(
-                complex_arithmatic_utility_code.specialize(self, 
-                            math_h_modifier = self.real_type.math_h_modifier,
-                            real_type = self.real_type.declaration_code('')))
+        # This must always be run, because a single CComplexType instance can be shared
+        # across multiple compilations (the one created in the module scope)
+        env.use_utility_code(complex_generic_utility_code)
+        env.use_utility_code(
+            complex_arithmatic_utility_code.specialize(self, 
+                math_h_modifier = self.real_type.math_h_modifier,
+                real_type = self.real_type.declaration_code('')))
         return True
 
     def create_from_py_utility_code(self, env):