diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 11:16:30 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-01-26 11:16:30 (GMT) |
commit | 47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81 (patch) | |
tree | b3e5115125360618a02a9615a643cbebe4aa7e75 /Modules/_json.c | |
parent | 4e5d9eac2ca03debecbb9c6ed873303d04ead06a (diff) | |
download | cpython-47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81.zip cpython-47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81.tar.gz cpython-47efb4a5dc9cdf3f59362beb9a04c5c6bdd09f81.tar.bz2 |
Issue #19361: JSON decoder now raises JSONDecodeError instead of ValueError.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r-- | Modules/_json.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/Modules/_json.c b/Modules/_json.c index 9430990..0bf475e 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -312,23 +312,22 @@ escape_unicode(PyObject *pystr) static void raise_errmsg(char *msg, PyObject *s, Py_ssize_t end) { - /* Use the Python function json.decoder.errmsg to raise a nice - looking ValueError exception */ - static PyObject *errmsg_fn = NULL; - PyObject *pymsg; - if (errmsg_fn == NULL) { + /* Use JSONDecodeError exception to raise a nice looking ValueError subclass */ + static PyObject *JSONDecodeError = NULL; + PyObject *exc; + if (JSONDecodeError == NULL) { PyObject *decoder = PyImport_ImportModule("json.decoder"); if (decoder == NULL) return; - errmsg_fn = PyObject_GetAttrString(decoder, "errmsg"); + JSONDecodeError = PyObject_GetAttrString(decoder, "JSONDecodeError"); Py_DECREF(decoder); - if (errmsg_fn == NULL) + if (JSONDecodeError == NULL) return; } - pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end); - if (pymsg) { - PyErr_SetObject(PyExc_ValueError, pymsg); - Py_DECREF(pymsg); + exc = PyObject_CallFunction(JSONDecodeError, "(zOn)", msg, s, end); + if (exc) { + PyErr_SetObject(JSONDecodeError, exc); + Py_DECREF(exc); } } |