summaryrefslogtreecommitdiffstats
path: root/Modules/_codecsmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-02 23:21:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-02 23:21:08 (GMT)
commit4fdb68491e8b2d044c9173babf625bbb815c39d1 (patch)
tree652360cd0b400bb3077d6106bee5f02bbea30c61 /Modules/_codecsmodule.c
parentb0ef78535a94b6b368a8b9935525cb3162c670d4 (diff)
downloadcpython-4fdb68491e8b2d044c9173babf625bbb815c39d1.zip
cpython-4fdb68491e8b2d044c9173babf625bbb815c39d1.tar.gz
cpython-4fdb68491e8b2d044c9173babf625bbb815c39d1.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.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 2bd751a..52f3479 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -284,8 +284,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))
@@ -298,11 +296,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;
}
}
@@ -727,8 +730,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",
@@ -741,6 +742,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;
@@ -755,9 +757,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;
}
}