Christian Heimes added the comment:

The patch fixes parts of the problem. At least Python doesn't crash any
more when run from a directory with non ASCII chars. It just fails with
an import error in initstdio().

Added file: http://bugs.python.org/file8633/py3k_more_win_fsencoding.patch

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1342>
__________________________________
Index: Include/unicodeobject.h
===================================================================
--- Include/unicodeobject.h	(revision 58687)
+++ Include/unicodeobject.h	(working copy)
@@ -155,6 +155,7 @@
 # define PyUnicode_DecodeCharmap PyUnicodeUCS2_DecodeCharmap
 # define PyUnicode_DecodeLatin1 PyUnicodeUCS2_DecodeLatin1
 # define PyUnicode_DecodeFSDefault PyUnicodeUCS2_DecodeFSDefault
+# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS2_DecodeFSDefaultAndSize
 # define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS2_DecodeRawUnicodeEscape
 # define PyUnicode_DecodeUTF32 PyUnicodeUCS2_DecodeUTF32
 # define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS2_DecodeUTF32Stateful
@@ -247,6 +248,7 @@
 # define PyUnicode_DecodeCharmap PyUnicodeUCS4_DecodeCharmap
 # define PyUnicode_DecodeLatin1 PyUnicodeUCS4_DecodeLatin1
 # define PyUnicode_DecodeFSDefault PyUnicodeUCS4_DecodeFSDefault
+# define PyUnicode_DecodeFSDefaultAndSize PyUnicodeUCS4_DecodeFSDefaultAndSize
 # define PyUnicode_DecodeRawUnicodeEscape PyUnicodeUCS4_DecodeRawUnicodeEscape
 # define PyUnicode_DecodeUTF32 PyUnicodeUCS4_DecodeUTF32
 # define PyUnicode_DecodeUTF32Stateful PyUnicodeUCS4_DecodeUTF32Stateful
@@ -657,6 +659,12 @@
     const char *s               /* encoded string */
     );
 
+PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
+    const char *s,               /* encoded string */
+    Py_ssize_t size              /* size */
+    );
+
+
 /* Return a char* holding the UTF-8 encoded value of the
    Unicode object.
 
Index: Objects/unicodeobject.c
===================================================================
--- Objects/unicodeobject.c	(revision 58687)
+++ Objects/unicodeobject.c	(working copy)
@@ -1263,10 +1263,14 @@
 }
 
 PyObject*
-PyUnicode_DecodeFSDefault(const char *s)
-{
+PyUnicode_DecodeFSDefault(const char *s) {
     Py_ssize_t size = (Py_ssize_t)strlen(s);
+    return PyUnicode_DecodeFSDefaultAndSize(s, size);
+}
 
+PyObject*
+PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size)
+{
     /* During the early bootstrapping process, Py_FileSystemDefaultEncoding
        can be undefined. If it is case, decode using UTF-8. The following assumes
        that Py_FileSystemDefaultEncoding is set to a built-in encoding during the
@@ -1274,11 +1278,11 @@
     */
     if (Py_FileSystemDefaultEncoding) {
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
-        if (strcmp(Py_FileSystemDefaultEncoding, "mbcs")) {
+        if (strcmp(Py_FileSystemDefaultEncoding, "mbcs") == 0) {
             return PyUnicode_DecodeMBCS(s, size, "replace");
         }
 #elif defined(__APPLE__)
-        if (strcmp(Py_FileSystemDefaultEncoding, "utf-8")) {
+        if (strcmp(Py_FileSystemDefaultEncoding, "utf-8") == 0) {
             return PyUnicode_DecodeUTF8(s, size, "replace");
         }
 #endif
Index: Python/sysmodule.c
===================================================================
--- Python/sysmodule.c	(revision 58687)
+++ Python/sysmodule.c	(working copy)
@@ -1081,11 +1081,11 @@
 	SET_SYS_FROM_STRING("platform",
 			    PyUnicode_FromString(Py_GetPlatform()));
 	SET_SYS_FROM_STRING("executable",
-			    PyUnicode_FromString(Py_GetProgramFullPath()));
+			    PyUnicode_DecodeFSDefault(Py_GetProgramFullPath()));
 	SET_SYS_FROM_STRING("prefix",
-			    PyUnicode_FromString(Py_GetPrefix()));
+			    PyUnicode_DecodeFSDefault(Py_GetPrefix()));
 	SET_SYS_FROM_STRING("exec_prefix",
-		   	    PyUnicode_FromString(Py_GetExecPrefix()));
+		   	    PyUnicode_DecodeFSDefault(Py_GetExecPrefix()));
 	SET_SYS_FROM_STRING("maxint",
 			    PyInt_FromLong(PyInt_GetMax()));
 	SET_SYS_FROM_STRING("maxsize",
@@ -1150,7 +1150,7 @@
 		p = strchr(path, delim);
 		if (p == NULL)
 			p = strchr(path, '\0'); /* End of string */
-		w = PyUnicode_FromStringAndSize(path, (Py_ssize_t) (p - path));
+		w = PyUnicode_DecodeFSDefaultAndSize(path, (Py_ssize_t) (p - path));
 		if (w == NULL) {
 			Py_DECREF(v);
 			return NULL;
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to