[Python-checkins] r81792 - python/branches/py3k/Python/getargs.c

victor.stinner python-checkins at python.org
Sun Jun 6 22:27:51 CEST 2010


Author: victor.stinner
Date: Sun Jun  6 22:27:51 2010
New Revision: 81792

Log:
Simplify getbuffer(): convertbuffer() fails anyway if bf_getbuffer is NULL


Modified:
   python/branches/py3k/Python/getargs.c

Modified: python/branches/py3k/Python/getargs.c
==============================================================================
--- python/branches/py3k/Python/getargs.c	(original)
+++ python/branches/py3k/Python/getargs.c	Sun Jun  6 22:27:51 2010
@@ -1410,7 +1410,7 @@
 static Py_ssize_t
 convertbuffer(PyObject *arg, void **p, char **errmsg)
 {
-    PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
+    PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer;
     Py_ssize_t count;
     Py_buffer view;
 
@@ -1438,31 +1438,23 @@
 static int
 getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
 {
-    void *buf;
-    Py_ssize_t count;
-    PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
+    PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer;
     if (pb == NULL) {
         *errmsg = "bytes or buffer";
         return -1;
     }
-    if (pb->bf_getbuffer) {
-        if (PyObject_GetBuffer(arg, view, 0) < 0) {
-            *errmsg = "convertible to a buffer";
-            return -1;
-        }
-        if (!PyBuffer_IsContiguous(view, 'C')) {
-            *errmsg = "contiguous buffer";
-            return -1;
-        }
-        return 0;
+    if (pb->bf_getbuffer == NULL) {
+        *errmsg = "convertible to a buffer";
+        return -1;
     }
-
-    count = convertbuffer(arg, &buf, errmsg);
-    if (count < 0) {
+    if (PyObject_GetBuffer(arg, view, 0) < 0) {
         *errmsg = "convertible to a buffer";
-        return count;
+        return -1;
+    }
+    if (!PyBuffer_IsContiguous(view, 'C')) {
+        *errmsg = "contiguous buffer";
+        return -1;
     }
-    PyBuffer_FillInfo(view, NULL, buf, count, 1, 0);
     return 0;
 }
 


More information about the Python-checkins mailing list