More fine-grained type declaration (makes new buffmt work in C++)
authorDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Mon, 11 May 2009 20:52:49 +0000 (22:52 +0200)
committerDag Sverre Seljebotn <dagss@student.matnat.uio.no>
Mon, 11 May 2009 20:52:49 +0000 (22:52 +0200)
Cython/Compiler/Buffer.py
Cython/Compiler/Code.py
Cython/Compiler/ModuleNode.py

index 6c46edf5730cad2d1ff989553ed4f36d93f4f266..0f89869cd72b154cb1571015f254777d94821c7d 100644 (file)
@@ -607,6 +607,8 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth):
     if dtype.is_error: return
     complex_possible = dtype.is_struct_or_union and dtype.can_be_complex()
 
+    code = proto.globalstate['typeinfo']
+
     if maxdepth <= 0:
         assert False
 
@@ -620,12 +622,12 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth):
         assert len(fields) > 0
         types = [get_type_information_cname(proto, f.type, maxdepth - 1)
                  for f in fields]
-        impl.putln("static __Pyx_StructField %s[] = {" % structinfo_name, safe=True)
+        code.putln("static __Pyx_StructField %s[] = {" % structinfo_name, safe=True)
         for f, typeinfo in zip(fields, types):
-            impl.putln('  {&%s, "%s", offsetof(%s, %s)},' %
+            code.putln('  {&%s, "%s", offsetof(%s, %s)},' %
                        (typeinfo, f.name, dtype.declaration_code(""), f.cname), safe=True)
-        impl.putln('  {NULL, NULL, 0}', safe=True)
-        impl.putln("};", safe=True)
+        code.putln('  {NULL, NULL, 0}', safe=True)
+        code.putln("};", safe=True)
     else:
         assert False
             
@@ -647,8 +649,7 @@ def type_information_code(proto, impl, name, structinfo_name, dtype, maxdepth):
         print dtype
         assert False
 
-    proto.putln('static __Pyx_TypeInfo %s;' % name)
-    impl.putln(('static __Pyx_TypeInfo %s = { "%s", %s, sizeof(%s), \'%s\' };'
+    code.putln(('static __Pyx_TypeInfo %s = { "%s", %s, sizeof(%s), \'%s\' };'
                 ) % (name,
                      rep,
                      structinfo_name,
index 1ee0b4b5db8f92733f7ff789fc22f6334d6a4573..515e2acafa08226233f97754c103fe65b4e31736 100644 (file)
@@ -230,15 +230,12 @@ class GlobalState(object):
 
     code_layout = [
         'h_code',
+        'type_declarations',
+        'module_declarations',
+        'typeinfo',
         'before_global_var',
         'global_var',
-        'after_global_var',
-        
-        'utility_proto',
-        'pystring_table',
-        'init_cached_builtins',
-        'init',
-        'utility_def',
+        'all_the_rest',
     ]
     
 
index db0a10608def2e74af0a7f081468af9796b7d22c..a5b6bd1943028764bac8766d3340ee7fd564edc7 100644 (file)
@@ -271,7 +271,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         self.generate_interned_string_decls(env, code)
         self.generate_py_string_decls(env, code)
 
-        code = globalstate['after_global_var']
+        code = globalstate['all_the_rest']
 
         self.generate_cached_builtins_decls(env, code)
         self.body.generate_function_definitions(env, code)
@@ -290,7 +290,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
         self.generate_filename_table(code)
         self.generate_utility_functions(env, code, h_code)
 
-        self.generate_declarations_for_modules(env, modules, h_code)
+        self.generate_declarations_for_modules(env, modules, globalstate)
         h_code.write('\n')
 
         globalstate.close_global_decls()
@@ -399,18 +399,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             self.generate_exttype_vtable_struct(entry, code)
             self.generate_exttype_vtabptr_declaration(entry, code)
 
-    def generate_declarations_for_modules(self, env, modules, code):
-        code.putln("")
-        code.putln("/* Type declarations */")
+    def generate_declarations_for_modules(self, env, modules, globalstate):
+        typecode = globalstate['type_declarations']
+        typecode.putln("")
+        typecode.putln("/* Type declarations */")
         vtab_list, vtabslot_list = self.sort_type_hierarchy(modules, env)
         self.generate_type_definitions(
-            env, modules, vtab_list, vtabslot_list, code)
+            env, modules, vtab_list, vtabslot_list, typecode)
+        modulecode = globalstate['module_declarations']
         for module in modules:
             defined_here = module is env
-            code.putln("/* Module declarations from %s */" %
+            modulecode.putln("/* Module declarations from %s */" %
                        module.qualified_name.encode("ASCII", "ignore"))
-            self.generate_global_declarations(module, code, defined_here)
-            self.generate_cfunction_predeclarations(module, code, defined_here)
+            self.generate_global_declarations(module, modulecode, defined_here)
+            self.generate_cfunction_predeclarations(module, modulecode, defined_here)
 
     def generate_module_preamble(self, env, cimported_modules, code):
         code.putln('/* Generated by Cython %s on %s */' % (