diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2007-11-20 14:55:57 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2007-11-20 14:55:57 (GMT) |
commit | 8c4592a77ae6b71a4bab8d40bbdcea72a6378cb4 (patch) | |
tree | 65a5dc5a55d88b6d4b297a9763c2ab82080690bf /Modules | |
parent | 547867e13a00d4373555e4c2ad4185195f4f4af9 (diff) | |
download | cpython-8c4592a77ae6b71a4bab8d40bbdcea72a6378cb4.zip cpython-8c4592a77ae6b71a4bab8d40bbdcea72a6378cb4.tar.gz cpython-8c4592a77ae6b71a4bab8d40bbdcea72a6378cb4.tar.bz2 |
Backport some main.c cleanup from the py3k branch
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/main.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/Modules/main.c b/Modules/main.c index 4b06acb..26f8780 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -181,27 +181,28 @@ static int RunMainFromImporter(char *filename) { PyObject *argv0 = NULL, *importer = NULL; - if ( - (argv0 = PyString_FromString(filename)) && - (importer = PyImport_GetImporter(argv0)) && - (importer->ob_type != &PyNullImporter_Type)) + if ((argv0 = PyString_FromString(filename)) && + (importer = PyImport_GetImporter(argv0)) && + (importer->ob_type != &PyNullImporter_Type)) { /* argv0 is usable as an import source, so put it in sys.path[0] and import __main__ */ PyObject *sys_path = NULL; - if ( - (sys_path = PySys_GetObject("path")) && - !PyList_SetItem(sys_path, 0, argv0) - ) { + if ((sys_path = PySys_GetObject("path")) && + !PyList_SetItem(sys_path, 0, argv0)) + { Py_INCREF(argv0); - Py_CLEAR(importer); + Py_DECREF(importer); sys_path = NULL; return RunModule("__main__", 0) != 0; } } - PyErr_Clear(); - Py_CLEAR(argv0); - Py_CLEAR(importer); + Py_XDECREF(argv0); + Py_XDECREF(importer); + if (PyErr_Occurred()) { + PyErr_Print(); + return 1; + } return -1; } |