Issue #14203: Remove obsolete support for view==NULL in bytesiobuf_getbuffer()

and array_buffer_getbuf().
This commit is contained in:
Stefan Krah 2015-02-03 21:43:23 +01:00
parent 38c30e6c8e
commit 650c1e818d
6 changed files with 48 additions and 17 deletions

View file

@ -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},