aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/getargs.c
diff options
context:
space:
mode:
authorFurkan Onder <furkanonder@protonmail.com>2023-10-23 12:54:46 +0300
committerGitHub <noreply@github.com>2023-10-23 12:54:46 +0300
commit32c37fe1ba708b8290cfa971e130bcfc29f1ead3 (patch)
treecb2ea772b12098a174426a058203f6683a14d8e2 /Python/getargs.c
parentc84b0390c053446b746b65ec82755918955e79e0 (diff)
downloadcpython-32c37fe1ba708b8290cfa971e130bcfc29f1ead3.tar.gz
cpython-32c37fe1ba708b8290cfa971e130bcfc29f1ead3.zip
gh-67565: Remove redundant C-contiguity checks (GH-105521)
Co-authored-by: Stefan Krah <skrah@bytereef.org>
Diffstat (limited to 'Python/getargs.c')
-rw-r--r--Python/getargs.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/Python/getargs.c b/Python/getargs.c
index 80d2540a694..5a12ca8def7 100644
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -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;
}