summaryrefslogtreecommitdiffstats
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-06-06 20:27:51 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-06-06 20:27:51 (GMT)
commit5cb6239f00e1d298be8e6198d945e05d9feaa9c7 (patch)
tree73c29f5da8b445364d6492ba780643047f0c4d2d /Python/getargs.c
parent7047eb73349c7e41ee21ff21d678b4910e5b8ea6 (diff)
downloadcpython-5cb6239f00e1d298be8e6198d945e05d9feaa9c7.zip
cpython-5cb6239f00e1d298be8e6198d945e05d9feaa9c7.tar.gz
cpython-5cb6239f00e1d298be8e6198d945e05d9feaa9c7.tar.bz2
Simplify getbuffer(): convertbuffer() fails anyway if bf_getbuffer is NULL
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 4f7bf7a..1806bf8 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -1410,7 +1410,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
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 @@ convertbuffer(PyObject *arg, void **p, char **errmsg)
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;
}