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 /Modules/_codecsmodule.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 'Modules/_codecsmodule.c')
-rw-r--r-- | Modules/_codecsmodule.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index f25297a..bf408af 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -288,8 +288,6 @@ unicode_internal_decode(PyObject *self, { PyObject *obj; const char *errors = NULL; - const char *data; - Py_ssize_t size; if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode", &obj, &errors)) @@ -302,11 +300,16 @@ unicode_internal_decode(PyObject *self, return codec_tuple(obj, PyUnicode_GET_LENGTH(obj)); } else { - if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) + Py_buffer view; + PyObject *result; + if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) return NULL; - return codec_tuple(_PyUnicode_DecodeUnicodeInternal(data, size, errors), - size); + result = codec_tuple( + _PyUnicode_DecodeUnicodeInternal(view.buf, view.len, errors), + view.len); + PyBuffer_Release(&view); + return result; } } @@ -731,8 +734,6 @@ unicode_internal_encode(PyObject *self, { PyObject *obj; const char *errors = NULL; - const char *data; - Py_ssize_t len, size; if (PyErr_WarnEx(PyExc_DeprecationWarning, "unicode_internal codec has been deprecated", @@ -745,6 +746,7 @@ unicode_internal_encode(PyObject *self, if (PyUnicode_Check(obj)) { Py_UNICODE *u; + Py_ssize_t len, size; if (PyUnicode_READY(obj) < 0) return NULL; @@ -759,9 +761,13 @@ unicode_internal_encode(PyObject *self, PyUnicode_GET_LENGTH(obj)); } else { - if (PyObject_AsReadBuffer(obj, (const void **)&data, &size)) + Py_buffer view; + PyObject *result; + if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) return NULL; - return codec_tuple(PyBytes_FromStringAndSize(data, size), size); + result = codec_tuple(PyBytes_FromStringAndSize(view.buf, view.len), view.len); + PyBuffer_Release(&view); + return result; } } |