gh-67565: Remove redundant C-contiguity checks (GH-105521)

Co-authored-by: Stefan Krah <skrah@bytereef.org>
This commit is contained in:
Furkan Onder 2023-10-23 12:54:46 +03:00 committed by GitHub
parent c84b0390c0
commit 32c37fe1ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 36 additions and 464 deletions

View file

@ -1187,17 +1187,15 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
arg, msgbuf, bufsize);
format++;
/* Caller is interested in Py_buffer, and the object
supports it directly. */
/* Caller is interested in Py_buffer, and the object supports it
directly. The request implicitly asks for PyBUF_SIMPLE, so the
result is C-contiguous with format 'B'. */
if (PyObject_GetBuffer(arg, (Py_buffer*)p, PyBUF_WRITABLE) < 0) {
PyErr_Clear();
return converterr("read-write bytes-like object",
arg, msgbuf, bufsize);
}
if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C')) {
PyBuffer_Release((Py_buffer*)p);
return converterr("contiguous buffer", arg, msgbuf, bufsize);
}
assert(PyBuffer_IsContiguous((Py_buffer *)p, 'C'));
if (addcleanup(p, freelist, cleanup_buffer)) {
return converterr(
"(cleanup problem)",
@ -1242,15 +1240,12 @@ convertbuffer(PyObject *arg, const void **p, const char **errmsg)
static int
getbuffer(PyObject *arg, Py_buffer *view, const char **errmsg)
{
/* PyBUF_SIMPLE implies C-contiguous */
if (PyObject_GetBuffer(arg, view, PyBUF_SIMPLE) != 0) {
*errmsg = "bytes-like object";
return -1;
}
if (!PyBuffer_IsContiguous(view, 'C')) {
PyBuffer_Release(view);
*errmsg = "contiguous buffer";
return -1;
}
assert(PyBuffer_IsContiguous(view, 'C'));
return 0;
}