mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
- Issue #10181: New memoryview implementation fixes multiple ownership
and lifetime issues of dynamically allocated Py_buffer members (#9990) as well as crashes (#8305, #7433). Many new features have been added (See whatsnew/3.3), and the documentation has been updated extensively. The ndarray test object from _testbuffer.c implements all aspects of PEP-3118, so further development towards the complete implementation of the PEP can proceed in a test-driven manner. Thanks to Nick Coghlan, Antoine Pitrou and Pauli Virtanen for review and many ideas. - Issue #12834: Fix incorrect results of memoryview.tobytes() for non-contiguous arrays. - Issue #5231: Introduce memoryview.cast() method that allows changing format and shape without making a copy of the underlying memory.
This commit is contained in:
parent
5a3d04623b
commit
9a2d99e28a
24 changed files with 10011 additions and 1171 deletions
|
@ -275,95 +275,6 @@ test_lazy_hash_inheritance(PyObject* self)
|
|||
}
|
||||
|
||||
|
||||
/* Issue #7385: Check that memoryview() does not crash
|
||||
* when bf_getbuffer returns an error
|
||||
*/
|
||||
|
||||
static int
|
||||
broken_buffer_getbuffer(PyObject *self, Py_buffer *view, int flags)
|
||||
{
|
||||
PyErr_SetString(
|
||||
TestError,
|
||||
"test_broken_memoryview: expected error in bf_getbuffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyBufferProcs memoryviewtester_as_buffer = {
|
||||
(getbufferproc)broken_buffer_getbuffer, /* bf_getbuffer */
|
||||
0, /* bf_releasebuffer */
|
||||
};
|
||||
|
||||
static PyTypeObject _MemoryViewTester_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"memoryviewtester", /* Name of this type */
|
||||
sizeof(PyObject), /* Basic object size */
|
||||
0, /* Item size for varobject */
|
||||
(destructor)PyObject_Del, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
0, /* tp_getattr */
|
||||
0, /* tp_setattr */
|
||||
0, /* tp_compare */
|
||||
0, /* tp_repr */
|
||||
0, /* tp_as_number */
|
||||
0, /* tp_as_sequence */
|
||||
0, /* tp_as_mapping */
|
||||
0, /* tp_hash */
|
||||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
&memoryviewtester_as_buffer, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PyType_GenericNew, /* tp_new */
|
||||
};
|
||||
|
||||
static PyObject*
|
||||
test_broken_memoryview(PyObject* self)
|
||||
{
|
||||
PyObject *obj = PyObject_New(PyObject, &_MemoryViewTester_Type);
|
||||
PyObject *res;
|
||||
|
||||
if (obj == NULL) {
|
||||
PyErr_Clear();
|
||||
PyErr_SetString(
|
||||
TestError,
|
||||
"test_broken_memoryview: failed to create object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
res = PyMemoryView_FromObject(obj);
|
||||
if (res || !PyErr_Occurred()){
|
||||
PyErr_SetString(
|
||||
TestError,
|
||||
"test_broken_memoryview: memoryview() didn't raise an Exception");
|
||||
Py_XDECREF(res);
|
||||
Py_DECREF(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
Py_DECREF(obj);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
/* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG)
|
||||
PyLong_{As, From}{Unsigned,}LongLong().
|
||||
|
||||
|
@ -2421,7 +2332,6 @@ static PyMethodDef TestMethods[] = {
|
|||
{"test_list_api", (PyCFunction)test_list_api, METH_NOARGS},
|
||||
{"test_dict_iteration", (PyCFunction)test_dict_iteration,METH_NOARGS},
|
||||
{"test_lazy_hash_inheritance", (PyCFunction)test_lazy_hash_inheritance,METH_NOARGS},
|
||||
{"test_broken_memoryview", (PyCFunction)test_broken_memoryview,METH_NOARGS},
|
||||
{"test_long_api", (PyCFunction)test_long_api, METH_NOARGS},
|
||||
{"test_long_and_overflow", (PyCFunction)test_long_and_overflow,
|
||||
METH_NOARGS},
|
||||
|
@ -2684,7 +2594,6 @@ PyInit__testcapi(void)
|
|||
return NULL;
|
||||
|
||||
Py_TYPE(&_HashInheritanceTester_Type)=&PyType_Type;
|
||||
Py_TYPE(&_MemoryViewTester_Type)=&PyType_Type;
|
||||
|
||||
Py_TYPE(&test_structmembersType)=&PyType_Type;
|
||||
Py_INCREF(&test_structmembersType);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue