From 2cb860f2c9421cb7a3af21b838a1cc6826760daa Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Fri, 25 Feb 2011 13:00:00 -0300 Subject: [PATCH] fixes and cleanups in __Pyx_main() --- Cython/Compiler/ModuleNode.py | 40 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index b26c6e9c..72d1074b 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2664,8 +2664,6 @@ int %(wmain_method)s(int argc, wchar_t **argv) { #else static int __Pyx_main(int argc, wchar_t **argv) { #endif - int r = 0; - PyObject* m = NULL; /* 754 requires that FP exceptions run in "no stop" mode by default, * and until C vendors implement C99's ways to control FP exceptions, * Python requires non-stop mode. Alas, some platforms enable FP @@ -2677,29 +2675,29 @@ static int __Pyx_main(int argc, wchar_t **argv) { m = fpgetmask(); fpsetmask(m & ~FP_X_OFL); #endif - if (argc) { + if (argc && argv) Py_SetProgramName(argv[0]); - } Py_Initialize(); - if (argc) { - PySys_SetArgv(argc, argv); + PySys_SetArgv(argc, argv); + { /* init module '%(module_name)s' as '__main__' */ + PyObject* m = NULL; + %(module_is_main)s = 1; + #if PY_MAJOR_VERSION < 3 + init%(module_name)s(); + #else + m = PyInit_%(module_name)s(); + #endif + if (PyErr_Occurred()) { + PyErr_Print(); /* This exits with the right code if SystemExit. */ + #if PY_MAJOR_VERSION < 3 + if (Py_FlushLine()) PyErr_Clear(); + #endif + return 1; + } + Py_XDECREF(m); } - %(module_is_main)s = 1; -#if PY_MAJOR_VERSION < 3 - init%(module_name)s(); -#else - m = PyInit_%(module_name)s(); -#endif - if (PyErr_Occurred() != NULL) { - r = 1; - PyErr_Print(); /* This exits with the right code if SystemExit. */ -#if PY_MAJOR_VERSION < 3 - if (Py_FlushLine()) PyErr_Clear(); -#endif - } - Py_XDECREF(m); Py_Finalize(); - return r; + return 0; } -- 2.26.2