From bba66f999d939604a567bc8dd0cfb113c9eb4dc0 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Mon, 11 May 2009 22:52:49 +0200 Subject: [PATCH] More fine-grained type declaration (makes new buffmt work in C++) --- Cython/Compiler/Buffer.py | 13 +++++++------ Cython/Compiler/Code.py | 11 ++++------- Cython/Compiler/ModuleNode.py | 20 +++++++++++--------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Cython/Compiler/Buffer.py b/Cython/Compiler/Buffer.py index 6c46edf5..0f89869c 100644 --- a/Cython/Compiler/Buffer.py +++ b/Cython/Compiler/Buffer.py @@ -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, diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 1ee0b4b5..515e2aca 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -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', ] diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index db0a1060..a5b6bd19 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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 */' % ( -- 2.26.2