From: Amaury Forgeot d'Arc Date: Thu, 30 Oct 2008 23:03:32 +0000 (+0000) Subject: #3626: On cygwin, starting "python z" would not display any error message: X-Git-Tag: v3.0rc2~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd8059f0781d5af09b25ee5a0683c16cf5ff4d2a;p=python #3626: On cygwin, starting "python z" would not display any error message: printf("%ls") fails if the wide string is 1 char long :-( --- diff --git a/Misc/NEWS b/Misc/NEWS index b06e4b6ab0..6d61192fb5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,10 +15,13 @@ What's New in Python 3.0 beta 5 Core and Builtins ----------------- +- Issue #3626: On cygwin, starting python with a non-existent script name + would not display anything if the file name is only 1 character long. + - Issue #4176: Fixed a crash when pickling an object which ``__reduce__`` method does not return iterators for the 4th and 5th items. -- Issue 3723: Fixed initialization of subinterpreters. +- Issue #3723: Fixed initialization of subinterpreters. - Issue #4213: The file system encoding is now normalized by the codec subsystem, for example UTF-8 is turned into utf-8. diff --git a/Modules/main.c b/Modules/main.c index 5a84cc22bc..6fdc33aa59 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -564,8 +564,17 @@ Py_Main(int argc, wchar_t **argv) if (sts==-1 && filename!=NULL) { if ((fp = _wfopen(filename, L"r")) == NULL) { - fprintf(stderr, "%ls: can't open file '%ls': [Errno %d] %s\n", - argv[0], filename, errno, strerror(errno)); + char cfilename[PATH_MAX]; + size_t r = wcstombs(cfilename, filename, PATH_MAX); + if (r == PATH_MAX) + /* cfilename is not null-terminated; + * forcefully null-terminating it + * might break the shift state */ + strcpy(cfilename, ""); + if (r == ((size_t)-1)) + strcpy(cfilename, ""); + fprintf(stderr, "%ls: can't open file '%s': [Errno %d] %s\n", + argv[0], cfilename, errno, strerror(errno)); return 2; }