]> granicus.if.org Git - python/commitdiff
Issue 1342: Python could not start if installed in a directory
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Wed, 11 Jun 2008 17:40:47 +0000 (17:40 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Wed, 11 Jun 2008 17:40:47 +0000 (17:40 +0000)
with non-ascii characters.

This is the simple fix, which uses the FileSystemEncoding.
Replacing all the char* with unicode strings is a major rewrite,
and needs more thinking.

Misc/NEWS
Python/import.c
Python/pythonrun.c

index 4c8d368ea4294ab4fb0a3767a5a1617dc9d7ad1d..40e06f0b05dfc5429a465eb880d4c04cba252a89 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's new in Python 3.0b1?
 Core and Builtins
 -----------------
 
+- Issue #1342: On windows, Python could not start when installed in a
+  directory with non-ascii characters.
+
 - Implement PEP 3121: new module initialization and finalization API.
 
 - Removed the already-defunct ``-t`` option.
index dadae2e9c72dcfbb5b4434c4fe97e19bb24979ae..14cda6e2728ce6d98ebc2cc707227b91a3d64741 100644 (file)
@@ -1364,19 +1364,26 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
                if (!v)
                        return NULL;
                if (PyUnicode_Check(v)) {
-                       v = _PyUnicode_AsDefaultEncodedString(v, NULL);
+                       v = PyUnicode_AsEncodedString(v, 
+                           Py_FileSystemDefaultEncoding, NULL);
                        if (v == NULL)
                                return NULL;
                }
-               if (!PyBytes_Check(v))
+               else if (!PyBytes_Check(v))
                        continue;
+               else
+                       Py_INCREF(v);
+
                base = PyBytes_AS_STRING(v);
                size = PyBytes_GET_SIZE(v);
                len = size;
                if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
+                       Py_DECREF(v);
                        continue; /* Too long */
                }
                strcpy(buf, base);
+               Py_DECREF(v);
+
                if (strlen(buf) != len) {
                        continue; /* v contains '\0' */
                }
@@ -3155,8 +3162,8 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
        if (!_PyArg_NoKeywords("NullImporter()", kwds))
                return -1;
 
-       if (!PyArg_ParseTuple(args, "s:NullImporter",
-                             &path))
+       if (!PyArg_ParseTuple(args, "es:NullImporter",
+                             Py_FileSystemDefaultEncoding, &path))
                return -1;
 
        pathlen = strlen(path);
index 3df5793e5f236eea8310d0365a1aa34d15b2af70..ae5856a13acf865a47d8b4a7a7c6ecc1ce23790f 100644 (file)
@@ -695,7 +695,7 @@ initstdio(void)
        PyObject *std = NULL;
        int status = 0, fd;
        PyObject * encoding_attr;
-       char *encoding, *errors;
+       char *encoding = NULL, *errors;
 
        /* Hack to avoid a nasty recursion issue when Python is invoked
           in verbose mode: pre-import the Latin-1 and UTF-8 codecs */