summaryrefslogtreecommitdiff
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2015-02-03 21:43:23 +0100
committerStefan Krah <skrah@bytereef.org>2015-02-03 21:43:23 +0100
commit650c1e818d7bbb5d51501051fca773b3b8ea6bf3 (patch)
tree5fdc035e52a060552f90293c04f8df9537e86def /Modules/_testcapimodule.c
parent38c30e6c8e34241a1ea226fdd4ff74be6a8ee846 (diff)
downloadcpython-git-650c1e818d7bbb5d51501051fca773b3b8ea6bf3.tar.gz
Issue #14203: Remove obsolete support for view==NULL in bytesiobuf_getbuffer()
and array_buffer_getbuf().
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 3cbe00cd96..a4930fbc8f 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -2518,21 +2518,26 @@ test_from_contiguous(PyObject* self, PyObject *noargs)
Py_RETURN_NONE;
}
-
+
+extern PyTypeObject _PyBytesIOBuffer_Type;
+
static PyObject *
test_pep3118_obsolete_write_locks(PyObject* self, PyObject *noargs)
{
+ PyTypeObject *type = &_PyBytesIOBuffer_Type;
PyObject *b;
char *dummy[1];
int ret, match;
+ /* PyBuffer_FillInfo() */
ret = PyBuffer_FillInfo(NULL, NULL, dummy, 1, 0, PyBUF_SIMPLE);
match = PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_BufferError);
PyErr_Clear();
if (ret != -1 || match == 0)
goto error;
- b = PyByteArray_FromStringAndSize("", 0);
+ /* bytesiobuf_getbuffer() */
+ b = type->tp_alloc(type, 0);
if (b == NULL) {
return NULL;
}
@@ -2552,6 +2557,18 @@ error:
return NULL;
}
+/* This tests functions that historically supported write locks. It is
+ wrong to call getbuffer() with view==NULL and a compliant getbufferproc
+ is entitled to segfault in that case. */
+static PyObject *
+getbuffer_with_null_view(PyObject* self, PyObject *obj)
+{
+ if (PyObject_GetBuffer(obj, NULL, PyBUF_SIMPLE) < 0)
+ return NULL;
+
+ Py_RETURN_NONE;
+}
+
/* Test that the fatal error from not having a current thread doesn't
cause an infinite loop. Run via Lib/test/test_capi.py */
static PyObject *
@@ -3213,6 +3230,7 @@ static PyMethodDef TestMethods[] = {
{"test_capsule", (PyCFunction)test_capsule, METH_NOARGS},
{"test_from_contiguous", (PyCFunction)test_from_contiguous, METH_NOARGS},
{"test_pep3118_obsolete_write_locks", (PyCFunction)test_pep3118_obsolete_write_locks, METH_NOARGS},
+ {"getbuffer_with_null_view", getbuffer_with_null_view, METH_O},
{"getargs_tuple", getargs_tuple, METH_VARARGS},
{"getargs_keywords", (PyCFunction)getargs_keywords,
METH_VARARGS|METH_KEYWORDS},