more complete embedded mode (trac 291)
authorRobert Bradshaw <robertwb@math.washington.edu>
Wed, 22 Apr 2009 02:43:22 +0000 (19:43 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Wed, 22 Apr 2009 02:43:22 +0000 (19:43 -0700)
Cython/Compiler/ModuleNode.py

index 8a6364fc34e2473088a43f87e9244ce8b739e0d2..4b20b83b2224f083084457bffc185cbe193ed8f3 100644 (file)
@@ -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
+""")