From: Amaury Forgeot d'Arc Date: Thu, 1 Jan 2009 23:07:21 +0000 (+0000) Subject: Merged revisions 68143 via svnmerge from X-Git-Tag: v3.0.1~209 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63176a3efe4553bc440c5107a1a47351e3e0d513;p=thirdparty%2FPython%2Fcpython.git Merged revisions 68143 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r68143 | amaury.forgeotdarc | 2009-01-02 00:05:36 +0100 (ven., 02 janv. 2009) | 7 lines #4747: on Windows, starting a module with a non-ascii filename would print a useless "SyntaxError: None" when the script contains a "# coding:" declaration. The Python API expects char* to be utf-8 encoded. wcstombs should be avoided here. Reviewed by Benjamin. Will backport to 3.0 ........ --- diff --git a/Misc/NEWS b/Misc/NEWS index 7c8a79377791..dd6c445ac61f 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,9 @@ What's New in Python 3.0.1? Core and Builtins ----------------- +- Issue #4747: When the terminal does not use utf-8, executing a script with + non-ascii characters in its name could fail with a "SyntaxError: None" error. + - Issue #4701: PyObject_Hash now implicitly calls PyType_Ready on types where the tp_hash and tp_dict slots are both NULL. diff --git a/Modules/main.c b/Modules/main.c index 78913eec00e1..3025d096c7ed 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -600,18 +600,21 @@ Py_Main(int argc, wchar_t **argv) } if (sts==-1) { - char cfilename[PATH_MAX]; + PyObject *filenameObj = NULL; char *p_cfilename = ""; if (filename) { - size_t r = wcstombs(cfilename, filename, PATH_MAX); - p_cfilename = cfilename; - if (r == (size_t)-1 || r >= PATH_MAX) + filenameObj = PyUnicode_FromWideChar( + filename, wcslen(filename)); + if (filenameObj != NULL) + p_cfilename = _PyUnicode_AsString(filenameObj); + else p_cfilename = ""; } sts = PyRun_AnyFileExFlags( fp, p_cfilename, filename != NULL, &cf) != 0; + Py_XDECREF(filenameObj); } }