Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1ca0b1

Browse files
committed
Issue 1342: Python could not start if installed in a directory
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.
1 parent c354c2e commit f1ca0b1

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's new in Python 3.0b1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #1342: On windows, Python could not start when installed in a
16+
directory with non-ascii characters.
17+
1518
- Implement PEP 3121: new module initialization and finalization API.
1619

1720
- Removed the already-defunct ``-t`` option.

Python/import.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,19 +1364,26 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
13641364
if (!v)
13651365
return NULL;
13661366
if (PyUnicode_Check(v)) {
1367-
v = _PyUnicode_AsDefaultEncodedString(v, NULL);
1367+
v = PyUnicode_AsEncodedString(v,
1368+
Py_FileSystemDefaultEncoding, NULL);
13681369
if (v == NULL)
13691370
return NULL;
13701371
}
1371-
if (!PyBytes_Check(v))
1372+
else if (!PyBytes_Check(v))
13721373
continue;
1374+
else
1375+
Py_INCREF(v);
1376+
13731377
base = PyBytes_AS_STRING(v);
13741378
size = PyBytes_GET_SIZE(v);
13751379
len = size;
13761380
if (len + 2 + namelen + MAXSUFFIXSIZE >= buflen) {
1381+
Py_DECREF(v);
13771382
continue; /* Too long */
13781383
}
13791384
strcpy(buf, base);
1385+
Py_DECREF(v);
1386+
13801387
if (strlen(buf) != len) {
13811388
continue; /* v contains '\0' */
13821389
}
@@ -3155,8 +3162,8 @@ NullImporter_init(NullImporter *self, PyObject *args, PyObject *kwds)
31553162
if (!_PyArg_NoKeywords("NullImporter()", kwds))
31563163
return -1;
31573164

3158-
if (!PyArg_ParseTuple(args, "s:NullImporter",
3159-
&path))
3165+
if (!PyArg_ParseTuple(args, "es:NullImporter",
3166+
Py_FileSystemDefaultEncoding, &path))
31603167
return -1;
31613168

31623169
pathlen = strlen(path);

Python/pythonrun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ initstdio(void)
695695
PyObject *std = NULL;
696696
int status = 0, fd;
697697
PyObject * encoding_attr;
698-
char *encoding, *errors;
698+
char *encoding = NULL, *errors;
699699

700700
/* Hack to avoid a nasty recursion issue when Python is invoked
701701
in verbose mode: pre-import the Latin-1 and UTF-8 codecs */

0 commit comments

Comments
 (0)