mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Simplify getbuffer(): convertbuffer() fails anyway if bf_getbuffer is NULL
This commit is contained in:
parent
7047eb7334
commit
5cb6239f00
1 changed files with 12 additions and 20 deletions
|
|
@ -1410,7 +1410,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
convertbuffer(PyObject *arg, void **p, char **errmsg)
|
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_ssize_t count;
|
||||||
Py_buffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
|
|
@ -1438,31 +1438,23 @@ convertbuffer(PyObject *arg, void **p, char **errmsg)
|
||||||
static int
|
static int
|
||||||
getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
|
getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
|
||||||
{
|
{
|
||||||
void *buf;
|
PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer;
|
||||||
Py_ssize_t count;
|
|
||||||
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
|
||||||
if (pb == NULL) {
|
if (pb == NULL) {
|
||||||
*errmsg = "bytes or buffer";
|
*errmsg = "bytes or buffer";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (pb->bf_getbuffer) {
|
if (pb->bf_getbuffer == NULL) {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
count = convertbuffer(arg, &buf, errmsg);
|
|
||||||
if (count < 0) {
|
|
||||||
*errmsg = "convertible to a buffer";
|
*errmsg = "convertible to a buffer";
|
||||||
return count;
|
return -1;
|
||||||
|
}
|
||||||
|
if (PyObject_GetBuffer(arg, view, 0) < 0) {
|
||||||
|
*errmsg = "convertible to a buffer";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!PyBuffer_IsContiguous(view, 'C')) {
|
||||||
|
*errmsg = "contiguous buffer";
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
PyBuffer_FillInfo(view, NULL, buf, count, 1, 0);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue