cython-devel

changeset 2112:c951607190c2

Ticket #216, Exceptions in __Pyx_InitGlobals() lead to a crash
author Robert Bradshaw <robertwb@math.washington.edu>
date Thu Sep 10 00:06:45 2009 -0700 (3 years ago)
parents 8157444859b4
children 41c5c91cbc5b
files Cython/Compiler/ModuleNode.py
line diff
1.1 --- a/Cython/Compiler/ModuleNode.py Wed Sep 09 17:30:09 2009 -0300 1.2 +++ b/Cython/Compiler/ModuleNode.py Thu Sep 10 00:06:45 2009 -0700 1.3 @@ -1635,6 +1635,7 @@ 1.4 code.putln("{") 1.5 tempdecl_code = code.insertion_point() 1.6 1.7 + self.generate_filename_init_call(code) 1.8 code.putln("#ifdef CYTHON_REFNANNY") 1.9 code.putln("void* __pyx_refchk = NULL;") 1.10 code.putln("__Pyx_Refnanny = __Pyx_ImportRefcountAPI(\"refnanny\");") 1.11 @@ -1656,7 +1657,6 @@ 1.12 1.13 code.putln("/*--- Library function declarations ---*/") 1.14 env.generate_library_function_declarations(code) 1.15 - self.generate_filename_init_call(code) 1.16 1.17 code.putln("/*--- Threads initialization code ---*/") 1.18 code.putln("#if defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS") 1.19 @@ -1665,12 +1665,12 @@ 1.20 code.putln("#endif") 1.21 code.putln("#endif") 1.22 1.23 + code.putln("/*--- Module creation code ---*/") 1.24 + self.generate_module_creation_code(env, code) 1.25 + 1.26 code.putln("/*--- Initialize various global constants etc. ---*/") 1.27 code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos)) 1.28 1.29 - code.putln("/*--- Module creation code ---*/") 1.30 - self.generate_module_creation_code(env, code) 1.31 - 1.32 if Options.cache_builtins: 1.33 code.putln("/*--- Builtin init code ---*/") 1.34 code.putln(code.error_goto_if_neg("__Pyx_InitCachedBuiltins()", 1.35 @@ -1710,9 +1710,13 @@ 1.36 code.put_var_xdecrefs(env.temp_entries) 1.37 for cname, type in code.funcstate.all_managed_temps(): 1.38 code.put_xdecref(cname, type) 1.39 - code.putln('__Pyx_AddTraceback("%s");' % env.qualified_name) 1.40 + code.putln('if (%s) {' % env.module_cname) 1.41 + code.putln('__Pyx_AddTraceback("init %s");' % env.qualified_name) 1.42 env.use_utility_code(Nodes.traceback_utility_code) 1.43 code.put_decref_clear(env.module_cname, py_object_type, nanny=False) 1.44 + code.putln('} else if (!PyErr_Occurred()) {') 1.45 + code.putln('PyErr_SetString(PyExc_ImportError, "init %s");' % env.qualified_name) 1.46 + code.putln('}') 1.47 code.put_label(code.return_label) 1.48 1.49 code.put_finish_refcount_context()