[Python-checkins] r68144 - in python/branches/release30-maint: Misc/NEWS Modules/main.c

amaury.forgeotdarc python-checkins at python.org
Fri Jan 2 00:07:21 CET 2009


Author: amaury.forgeotdarc
Date: Fri Jan  2 00:07:21 2009
New Revision: 68144

Log:
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
........


Modified:
   python/branches/release30-maint/   (props changed)
   python/branches/release30-maint/Misc/NEWS
   python/branches/release30-maint/Modules/main.c

Modified: python/branches/release30-maint/Misc/NEWS
==============================================================================
--- python/branches/release30-maint/Misc/NEWS	(original)
+++ python/branches/release30-maint/Misc/NEWS	Fri Jan  2 00:07:21 2009
@@ -12,6 +12,9 @@
 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.
 

Modified: python/branches/release30-maint/Modules/main.c
==============================================================================
--- python/branches/release30-maint/Modules/main.c	(original)
+++ python/branches/release30-maint/Modules/main.c	Fri Jan  2 00:07:21 2009
@@ -600,18 +600,21 @@
 		}
 
 		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);
 		}
 		
 	}


More information about the Python-checkins mailing list