summaryrefslogtreecommitdiff
path: root/Cython/Compiler/ModuleNode.py
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r--Cython/Compiler/ModuleNode.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py
index d0687624f..99b2f0028 100644
--- a/Cython/Compiler/ModuleNode.py
+++ b/Cython/Compiler/ModuleNode.py
@@ -2939,7 +2939,7 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
# start of module init/exec function (pre/post PEP 489)
code.putln("{")
-
+ code.putln('int stringtab_initialized = 0;')
tempdecl_code = code.insertion_point()
profile = code.globalstate.directives['profile']
@@ -3012,7 +3012,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("#endif")
code.putln("/*--- Initialize various global constants etc. ---*/")
- code.put_error_if_neg(self.pos, "__Pyx_InitGlobals()")
+ code.put_error_if_neg(self.pos, "__Pyx_InitConstants()")
+ code.putln("stringtab_initialized = 1;")
+ code.put_error_if_neg(self.pos, "__Pyx_InitGlobals()") # calls any utility code
+
code.putln("#if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || "
"__PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)")
@@ -3095,7 +3098,9 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
for cname, type in code.funcstate.all_managed_temps():
code.put_xdecref(cname, type)
code.putln('if (%s) {' % env.module_cname)
- code.putln('if (%s) {' % env.module_dict_cname)
+ code.putln('if (%s && stringtab_initialized) {' % env.module_dict_cname)
+ # We can run into errors before the module or stringtab are initialized.
+ # In this case it is not safe to add a traceback (because it uses the stringtab)
code.put_add_traceback(EncodedString("init %s" % env.qualified_name))
code.globalstate.use_utility_code(Nodes.traceback_utility_code)
# Module reference and module dict are in global variables which might still be needed