diff options
author | Guido van Rossum <guido@python.org> | 2007-11-19 18:36:41 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-11-19 18:36:41 (GMT) |
commit | 74c29c71b1c9a68030e6b3fda6af54ca52b2c6c3 (patch) | |
tree | b38f155cc4f100297bf6d556e2b7c827279b9059 /Modules/main.c | |
parent | 82f013bb58f4a4a76ddc0a8407f620a6f0aac022 (diff) | |
download | cpython-74c29c71b1c9a68030e6b3fda6af54ca52b2c6c3.zip cpython-74c29c71b1c9a68030e6b3fda6af54ca52b2c6c3.tar.gz cpython-74c29c71b1c9a68030e6b3fda6af54ca52b2c6c3.tar.bz2 |
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.
Diffstat (limited to 'Modules/main.c')
-rw-r--r-- | Modules/main.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/Modules/main.c b/Modules/main.c index 6964337..a8cbbfe 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -187,28 +187,31 @@ 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 = 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 @@ Py_GetArgcArgv(int *argc, char ***argv) #ifdef __cplusplus } #endif - |