diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-02 23:25:42 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-02-02 23:25:42 (GMT) |
commit | 3dd3e26680110b3eeadedc9c8457dfe1db2b913c (patch) | |
tree | 584a98eda6e93033ddaf313b95826e6e3cd887cb /Objects/exceptions.c | |
parent | 0b2a6dc42b9bf02408764133a8dfcd843bbd0e66 (diff) | |
parent | 4fdb68491e8b2d044c9173babf625bbb815c39d1 (diff) | |
download | cpython-3dd3e26680110b3eeadedc9c8457dfe1db2b913c.zip cpython-3dd3e26680110b3eeadedc9c8457dfe1db2b913c.tar.gz cpython-3dd3e26680110b3eeadedc9c8457dfe1db2b913c.tar.bz2 |
Issue #22896: Avoid to use PyObject_AsCharBuffer(), PyObject_AsReadBuffer()
and PyObject_AsWriteBuffer().
Diffstat (limited to 'Objects/exceptions.c')
-rw-r--r-- | Objects/exceptions.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 5532821..e09d384 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1922,8 +1922,6 @@ static int UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) { PyUnicodeErrorObject *ude; - const char *data; - Py_ssize_t size; if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1) return -1; @@ -1944,21 +1942,27 @@ UnicodeDecodeError_init(PyObject *self, PyObject *args, PyObject *kwds) return -1; } - if (!PyBytes_Check(ude->object)) { - if (PyObject_AsReadBuffer(ude->object, (const void **)&data, &size)) { - ude->encoding = ude->object = ude->reason = NULL; - return -1; - } - ude->object = PyBytes_FromStringAndSize(data, size); - } - else { - Py_INCREF(ude->object); - } - Py_INCREF(ude->encoding); + Py_INCREF(ude->object); Py_INCREF(ude->reason); + if (!PyBytes_Check(ude->object)) { + Py_buffer view; + if (PyObject_GetBuffer(ude->object, &view, PyBUF_SIMPLE) != 0) + goto error; + Py_CLEAR(ude->object); + ude->object = PyBytes_FromStringAndSize(view.buf, view.len); + PyBuffer_Release(&view); + if (!ude->object) + goto error; + } return 0; + +error: + Py_CLEAR(ude->encoding); + Py_CLEAR(ude->object); + Py_CLEAR(ude->reason); + return -1; } static PyObject * |