mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
#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
This commit is contained in:
parent
8ed9a8069d
commit
374e220bcb
2 changed files with 10 additions and 4 deletions
|
@ -600,18 +600,21 @@ Py_Main(int argc, wchar_t **argv)
|
|||
}
|
||||
|
||||
if (sts==-1) {
|
||||
char cfilename[PATH_MAX];
|
||||
PyObject *filenameObj = NULL;
|
||||
char *p_cfilename = "<stdin>";
|
||||
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 = "<decoding error>";
|
||||
}
|
||||
sts = PyRun_AnyFileExFlags(
|
||||
fp,
|
||||
p_cfilename,
|
||||
filename != NULL, &cf) != 0;
|
||||
Py_XDECREF(filenameObj);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue