Commit cd6fb6ad authored by Dag Sverre Seljebotn's avatar Dag Sverre Seljebotn

Moved cached builtin init to Code.py for consistency

parent d65fd747
......@@ -168,8 +168,13 @@ class GlobalState(object):
self.utildefwriter = rootwriter.new_writer()
self.decls_writer = rootwriter.new_writer()
self.pystring_table = rootwriter.new_writer()
self.init_cached_builtins_writer = rootwriter.new_writer()
self.initwriter = rootwriter.new_writer()
if Options.cache_builtins:
self.init_cached_builtins_writer.enter_cfunc_scope()
self.init_cached_builtins_writer.putln("static int __Pyx_InitCachedBuiltins(void) {")
self.initwriter.enter_cfunc_scope()
self.initwriter.putln("").putln("static int __Pyx_InitGlobals(void) {")
......@@ -197,19 +202,28 @@ class GlobalState(object):
Naming.stringtab_cname,
self.initwriter.error_goto(self.module_pos)))
if Options.cache_builtins:
(self.init_cached_builtins_writer
.putln("return 0;")
.put_label(self.init_cached_builtins_writer.error_label)
.putln("return -1;")
.putln("}")
.exit_cfunc_scope()
)
(self.initwriter
.putln("return 0;")
.put_label(self.initwriter.error_label)
.putln("return -1;")
.putln("}")
.exit_cfunc_scope()
)
self.initwriter.exit_cfunc_scope()
def insert_py_string_table_into(self, code):
def insert_initcode_into(self, code):
if self.pystring_table_needed:
code.insert(self.pystring_table)
def insert_initglobals_into(self, code):
if Options.cache_builtins:
code.insert(self.init_cached_builtins_writer)
code.insert(self.initwriter)
def put_pyobject_decl(self, entry):
......@@ -268,8 +282,16 @@ class GlobalState(object):
self.put_pyobject_decl(entry)
def add_cached_builtin_decl(self, entry):
if self.should_declare(entry.cname, entry):
self.put_pyobject_decl(entry)
if Options.cache_builtins:
if self.should_declare(entry.cname, entry):
self.put_pyobject_decl(entry)
self.init_cached_builtins_writer.putln('%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
entry.interned_cname,
entry.cname,
self.init_cached_builtins_writer.error_goto(entry.pos)))
#
# File name state
......
......@@ -256,7 +256,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
self.generate_cached_builtins_decls(env, code)
self.body.generate_function_definitions(env, code, options.transforms)
code.mark_pos(None)
self.generate_py_string_table(env, code)
self.generate_typeobj_definitions(env, code)
self.generate_method_table(env, code)
self.generate_filename_init_prototype(code)
......@@ -1456,9 +1455,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln(
"};")
def generate_py_string_table(self, env, code):
code.globalstate.insert_py_string_table_into(code)
def generate_filename_init_prototype(self, code):
code.putln("");
code.putln("static void %s(void); /*proto*/" % Naming.fileinit_cname)
......@@ -1527,7 +1523,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_module_init_func(self, imported_modules, env, code):
# Insert code stream of __Pyx_InitGlobals
code.globalstate.insert_initglobals_into(code)
code.globalstate.insert_initcode_into(code)
code.enter_cfunc_scope()
code.putln("")
......@@ -1556,8 +1552,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
if Options.cache_builtins:
code.putln("/*--- Builtin init code ---*/")
self.generate_builtin_init_code(env, code)
code.putln(code.error_goto_if_neg("__Pyx_InitCachedBuiltins()",
self.pos))
code.putln("%s = 0;" % Naming.skip_dispatch_cname);
code.putln("/*--- Global init code ---*/")
......@@ -1714,19 +1711,6 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
Naming.preimport_cname,
code.error_goto(self.pos)));
def generate_builtin_init_code(self, env, code):
# Lookup and cache builtin objects.
if Options.cache_builtins:
for entry in env.cached_builtins:
#assert entry.interned_cname is not None
code.putln(
'%s = __Pyx_GetName(%s, %s); if (!%s) %s' % (
entry.cname,
Naming.builtins_cname,
entry.interned_cname,
entry.cname,
code.error_goto(entry.pos)))
def generate_global_init_code(self, env, code):
# Generate code to initialise global PyObject *
# variables to None.
......
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