diff Modules/main.c @ 43929:7ab49064d430 legacy-trunk

Backport some main.c cleanup from the py3k branch
author Nick Coghlan <ncoghlan@gmail.com>
date Tue, 20 Nov 2007 14:55:57 +0000
parents 4cec0c6392c1
children 599f22a349a2
line wrap: on
line diff
--- a/Modules/main.c	Tue Nov 20 03:21:02 2007 +0000
+++ b/Modules/main.c	Tue Nov 20 14:55:57 2007 +0000
@@ -181,27 +181,28 @@
 {
 	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;
 }