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) {")
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):
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
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)
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)
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("")
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 ---*/")
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.