summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-07-28 00:40:58 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-07-28 00:40:58 (GMT)
commit8182b717dbedc5d864a2240e6ff9120ecb2607dc (patch)
tree74f636910d26b88fa889612cd19d7c88e221dc62 /Python/getargs.c
parent84befb00bd099306583ae643431b8f858dded415 (diff)
downloadcpython-8182b717dbedc5d864a2240e6ff9120ecb2607dc.zip
cpython-8182b717dbedc5d864a2240e6ff9120ecb2607dc.tar.gz
cpython-8182b717dbedc5d864a2240e6ff9120ecb2607dc.tar.bz2
Issue #8991: convertbuffer() rejects discontigious buffers
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 7b92948..e4bd50d 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1246,13 +1246,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
PyErr_Clear();
return converterr("read-write buffer", arg, msgbuf, bufsize);
}
+ if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C')) {
+ PyBuffer_Release((Py_buffer*)p);
+ return converterr("contiguous buffer", arg, msgbuf, bufsize);
+ }
if (addcleanup(p, freelist, cleanup_buffer)) {
return converterr(
"(cleanup problem)",
arg, msgbuf, bufsize);
}
- if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C'))
- return converterr("contiguous buffer", arg, msgbuf, bufsize);
break;
}
@@ -1274,41 +1276,26 @@ convertbuffer(PyObject *arg, void **p, char **errmsg)
*errmsg = NULL;
*p = NULL;
- if (pb == NULL ||
- pb->bf_getbuffer == NULL ||
- pb->bf_releasebuffer != NULL) {
- *errmsg = "bytes or read-only buffer";
+ if (pb != NULL && pb->bf_releasebuffer != NULL) {
+ *errmsg = "read-only pinned buffer";
return -1;
}
- if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) != 0) {
- *errmsg = "bytes or single-segment read-only buffer";
+ if (getbuffer(arg, &view, errmsg) < 0)
return -1;
- }
count = view.len;
*p = view.buf;
PyBuffer_Release(&view);
return count;
}
-/* XXX for 3.x, getbuffer and convertbuffer can probably
- be merged again. */
static int
getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
{
- PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer;
- if (pb == NULL) {
+ if (PyObject_GetBuffer(arg, view, PyBUF_SIMPLE) != 0) {
*errmsg = "bytes or buffer";
return -1;
}
- if (pb->bf_getbuffer == NULL) {
- *errmsg = "convertible to a buffer";
- return -1;
- }
- if (PyObject_GetBuffer(arg, view, 0) < 0) {
- *errmsg = "convertible to a buffer";
- return -1;
- }
if (!PyBuffer_IsContiguous(view, 'C')) {
PyBuffer_Release(view);
*errmsg = "contiguous buffer";