diff options
author | Barry Warsaw <barry@python.org> | 2010-11-02 21:03:09 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2010-11-02 21:03:09 (GMT) |
commit | fa6582752a19f38f8c666d36122c7fc450c2dcf5 (patch) | |
tree | f73e936743e00deddcff54c112dbcc3415599b89 /Modules/_json.c | |
parent | 921387ba0e5b41d563c7757858900187bd36609d (diff) | |
download | cpython-fa6582752a19f38f8c666d36122c7fc450c2dcf5.zip cpython-fa6582752a19f38f8c666d36122c7fc450c2dcf5.tar.gz cpython-fa6582752a19f38f8c666d36122c7fc450c2dcf5.tar.bz2 |
Issue 10038. Restore the Python 2.6 behavior that json.loads() always returns
unicode. Patch by Patch by Walter Dörwald.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r-- | Modules/_json.c | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index de7e171..12ddea2 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -440,7 +440,6 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s Py_ssize_t len = PyString_GET_SIZE(pystr); Py_ssize_t begin = end - 1; Py_ssize_t next; - int has_unicode = 0; char *buf = PyString_AS_STRING(pystr); PyObject *chunks = PyList_New(0); if (chunks == NULL) { @@ -463,9 +462,6 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s raise_errmsg("Invalid control character at", pystr, next); goto bail; } - else if (c > 0x7f) { - has_unicode = 1; - } } if (!(c == '"' || c == '\\')) { raise_errmsg("Unterminated string starting at", pystr, begin); @@ -477,15 +473,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s if (strchunk == NULL) { goto bail; } - if (has_unicode) { - chunk = PyUnicode_FromEncodedObject(strchunk, encoding, NULL); - Py_DECREF(strchunk); - if (chunk == NULL) { - goto bail; - } - } - else { - chunk = strchunk; + chunk = PyUnicode_FromEncodedObject(strchunk, encoding, NULL); + Py_DECREF(strchunk); + if (chunk == NULL) { + goto bail; } if (PyList_Append(chunks, chunk)) { Py_DECREF(chunk); @@ -593,21 +584,9 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s } #endif } - if (c > 0x7f) { - has_unicode = 1; - } - if (has_unicode) { - chunk = PyUnicode_FromUnicode(&c, 1); - if (chunk == NULL) { - goto bail; - } - } - else { - char c_char = Py_CHARMASK(c); - chunk = PyString_FromStringAndSize(&c_char, 1); - if (chunk == NULL) { - goto bail; - } + chunk = PyUnicode_FromUnicode(&c, 1); + if (chunk == NULL) { + goto bail; } if (PyList_Append(chunks, chunk)) { Py_DECREF(chunk); |