summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2010-03-22 16:07:38 (GMT)
committerFlorent Xicluna <florent.xicluna@gmail.com>2010-03-22 16:07:38 (GMT)
commit9e7a4c9738cffe785156b46c02148b890530ef14 (patch)
treec4fd377ac46cd710311ad1a5d2a74323a4927e1e /Modules
parentc9d1a7845ba18466ee048666239c6b969c9acd33 (diff)
downloadcpython-9e7a4c9738cffe785156b46c02148b890530ef14.zip
cpython-9e7a4c9738cffe785156b46c02148b890530ef14.tar.gz
cpython-9e7a4c9738cffe785156b46c02148b890530ef14.tar.bz2
Issue #7703: ctypes supports both buffer() and memoryview(). The former is deprecated.
Complement of r79288.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index 4d2302d..d1b436d 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -1076,22 +1076,31 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
{
char *ptr;
Py_ssize_t size;
+ Py_buffer view = { 0 };
if (PyBuffer_Check(value)) {
size = Py_TYPE(value)->tp_as_buffer->bf_getreadbuffer(value, 0, (void *)&ptr);
if (size < 0)
- return -1;
- } else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) {
- return -1;
+ goto fail;
+ } else {
+ if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
+ goto fail;
+ size = view.len;
+ ptr = view.buf;
}
if (size > self->b_size) {
PyErr_SetString(PyExc_ValueError,
"string too long");
- return -1;
+ goto fail;
}
memcpy(self->b_ptr, ptr, size);
+ PyBuffer_Release(&view);
return 0;
+ fail:
+
+ PyBuffer_Release(&view);
+ return -1;
}
static PyObject *