]> granicus.if.org Git - python/commitdiff
Issue #8991: convertbuffer() rejects discontigious buffers
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 28 Jul 2010 00:40:58 +0000 (00:40 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 28 Jul 2010 00:40:58 +0000 (00:40 +0000)
Misc/NEWS
Python/getargs.c

index 9fa5e60914b97e31c91d4b57ec5414e6be39f30b..81ec74e044ffa74dd9ea39fa86d69db3393b25ad 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 3.2 Alpha 1?
 Core and Builtins
 -----------------
 
+- Issue #8991: convertbuffer() rejects discontigious buffers.
+
 - Issue #7616: Fix copying of overlapping memoryview slices with the Intel
   compiler.
 
index 7b929481d25ef03ec1d9e3fe4d320af051cf98d9..e4bd50d7b349a7b2d96b8d292ac54f53aef1722f 100644 (file)
@@ -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";