diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-15 12:04:23 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-10-15 12:04:23 (GMT) |
commit | f3170ccef8809e4a3f82fe9f82dc7a4a486c28c1 (patch) | |
tree | b96ab0a2584f511758bad3e4ccac6c4e3ed43954 /Objects | |
parent | 6a4aff10f0f1c34f488d5d0f932eea1fb3483dbf (diff) | |
download | cpython-f3170ccef8809e4a3f82fe9f82dc7a4a486c28c1.zip cpython-f3170ccef8809e4a3f82fe9f82dc7a4a486c28c1.tar.gz cpython-f3170ccef8809e4a3f82fe9f82dc7a4a486c28c1.tar.bz2 |
Use locale encoding if Py_FileSystemDefaultEncoding is not set
* PyUnicode_EncodeFSDefault(), PyUnicode_DecodeFSDefaultAndSize() and
PyUnicode_DecodeFSDefault() use the locale encoding instead of UTF-8 if
Py_FileSystemDefaultEncoding is NULL
* redecode_filenames() functions and _Py_code_object_list (issue #9630)
are no more needed: remove them
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/codeobject.c | 13 | ||||
-rw-r--r-- | Objects/object.c | 4 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 40 |
3 files changed, 32 insertions, 25 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 470bf56..e24fc8d 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -5,8 +5,6 @@ #define NAME_CHARS \ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz" -PyObject *_Py_code_object_list = NULL; - /* all_name_chars(s): true iff all chars in s are valid NAME_CHARS */ static int @@ -111,17 +109,6 @@ PyCode_New(int argcount, int kwonlyargcount, co->co_lnotab = lnotab; co->co_zombieframe = NULL; co->co_weakreflist = NULL; - - if (_Py_code_object_list != NULL) { - int err; - PyObject *ref = PyWeakref_NewRef((PyObject*)co, NULL); - if (ref == NULL) - goto error; - err = PyList_Append(_Py_code_object_list, ref); - Py_DECREF(ref); - if (err) - goto error; - } } return co; diff --git a/Objects/object.c b/Objects/object.c index e322e53..ff3363f 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -1604,10 +1604,6 @@ _Py_ReadyTypes(void) if (PyType_Ready(&PyCode_Type) < 0) Py_FatalError("Can't initialize code type"); - _Py_code_object_list = PyList_New(0); - if (_Py_code_object_list == NULL) - Py_FatalError("Can't initialize code type"); - if (PyType_Ready(&PyFrame_Type) < 0) Py_FatalError("Can't initialize frame type"); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a18eeef..98427e3 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1597,11 +1597,22 @@ PyObject *PyUnicode_EncodeFSDefault(PyObject *unicode) "surrogateescape"); } else { - /* if you change the default encoding, update also - PyUnicode_DecodeFSDefaultAndSize() and redecode_filenames() */ - return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode), - PyUnicode_GET_SIZE(unicode), - "surrogateescape"); + /* locale encoding with surrogateescape */ + wchar_t *wchar; + char *bytes; + PyObject *bytes_obj; + + wchar = PyUnicode_AsWideCharString(unicode, NULL); + if (wchar == NULL) + return NULL; + bytes = _Py_wchar2char(wchar); + PyMem_Free(wchar); + if (bytes == NULL) + return NULL; + + bytes_obj = PyBytes_FromString(bytes); + PyMem_Free(bytes); + return bytes_obj; } } @@ -1769,9 +1780,22 @@ PyUnicode_DecodeFSDefaultAndSize(const char *s, Py_ssize_t size) "surrogateescape"); } else { - /* if you change the default encoding, update also - PyUnicode_EncodeFSDefault() and redecode_filenames() */ - return PyUnicode_DecodeUTF8(s, size, "surrogateescape"); + /* locale encoding with surrogateescape */ + wchar_t *wchar; + PyObject *unicode; + + if (s[size] != '\0' || size != strlen(s)) { + PyErr_SetString(PyExc_TypeError, "embedded NUL character"); + return NULL; + } + + wchar = _Py_char2wchar(s); + if (wchar == NULL) + return NULL; + + unicode = PyUnicode_FromWideChar(wchar, -1); + PyMem_Free(wchar); + return unicode; } } |