From 8868ff82298d3f3150690e05613cb7dd7af9b3e4 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 21 Apr 2009 19:43:22 -0700 Subject: [PATCH] more complete embedded mode (trac 291) --- Cython/Compiler/ModuleNode.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 8a6364fc..4b20b83b 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2459,16 +2459,22 @@ static __Pyx_RefnannyAPIStruct *__Pyx_Refnanny = NULL; main_method = UtilityCode( impl = """ int main(int argc, char** argv) { - int r; + int r = 0; + PyObject* m = NULL; Py_Initialize(); PySys_SetArgv(argc, argv); #if PY_MAJOR_VERSION < 3 init%(module_name)s(); #else - PyInit_%(module_name)s(name); + m = PyInit_%(module_name)s(name); #endif - r = PyErr_Occurred() != NULL; + if (PyErr_Occurred() != NULL) { + r = 1; + PyErr_Print(); /* This exits with the right code if SystemExit. */ + if (Py_FlushLine()); PyErr_Clear(); + } + Py_XDECREF(m); Py_Finalize(); return r; } -""") \ No newline at end of file +""") -- 2.26.2