summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2009-01-01 23:05:36 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2009-01-01 23:05:36 (GMT)
commit374e220bcb1ee71053c18c0b4e409cfa69881722 (patch)
tree309b2a2e6616578448100fc086551ce418bb4bb1 /Modules/main.c
parent8ed9a8069dbef331d6097dcd2895f7cbf012897e (diff)
downloadcpython-374e220bcb1ee71053c18c0b4e409cfa69881722.zip
cpython-374e220bcb1ee71053c18c0b4e409cfa69881722.tar.gz
cpython-374e220bcb1ee71053c18c0b4e409cfa69881722.tar.bz2
#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
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 78913ee..3025d09 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 = "<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);
}
}