]> granicus.if.org Git - python/commitdiff
#4747: on Windows, starting a module with a non-ascii filename would print a useless...
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 1 Jan 2009 23:05:36 +0000 (23:05 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 1 Jan 2009 23:05:36 +0000 (23:05 +0000)
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

Misc/NEWS
Modules/main.c

index 419a2c227ea337732468f7a88f41240fa22a9bda..dcc63772488b99fefc6f2b00f1f2a1cb61de7b1a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.1 alpha 0
 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 #4797: IOError.filename was not set when _fileio.FileIO failed to open
   file with `bytes' filename on Windows.
 
index 78913eec00e14e76acfa5416e310088d7f5d3520..3025d096c7ed190c48d393779502becb9831ee52 100644 (file)
@@ -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);
                }
                
        }