[Python-3000-checkins] r59058 - python/branches/py3k/Modules/main.c

guido.van.rossum python-3000-checkins at python.org
Mon Nov 19 19:36:42 CET 2007


Author: guido.van.rossum
Date: Mon Nov 19 19:36:41 2007
New Revision: 59058

Modified:
   python/branches/py3k/Modules/main.c
Log:
Make test_cmd_line_scripts pass by using a unicode string instead of
a bytes string to hold argv0 in RunMainFromImporter().
Also changed the code lay-out a bit to be more readable (for me :-),
and print any unexpected errors rather than suppressing them.


Modified: python/branches/py3k/Modules/main.c
==============================================================================
--- python/branches/py3k/Modules/main.c	(original)
+++ python/branches/py3k/Modules/main.c	Mon Nov 19 19:36:41 2007
@@ -187,28 +187,31 @@
 {
 	PyObject *argv0 = NULL, *importer = NULL;
 
-	if (
-		(argv0 = PyString_FromString(filename)) && 
-		(importer = PyImport_GetImporter(argv0)) &&
-		(importer->ob_type != &PyNullImporter_Type))
+	if ((argv0 = PyUnicode_DecodeFSDefault(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);
-	return -1;
+	Py_XDECREF(argv0);
+	Py_XDECREF(importer);
+        if (PyErr_Occurred()) {
+		PyErr_Print();
+		return 1;
+        }
+	else {
+		return -1;
+	}
 }
 
 
@@ -590,4 +593,3 @@
 #ifdef __cplusplus
 }
 #endif
-


More information about the Python-3000-checkins mailing list