cpython: a9305102c892 (original) (raw)
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -518,6 +518,7 @@ Mark Hammond Harald Hanche-Olsen Manus Hand Milton L. Hankins +Richard Hansen Stephen Hansen Barry Hantman Lynda Hardman
--- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -376,6 +376,53 @@ test_broken_memoryview(PyObject* self) Py_RETURN_NONE; } +static PyObject +test_to_contiguous(PyObject self, PyObject *noargs) +{
- int data[9] = {0, -1, 1, -1, 2, -1, 3, -1, 4};
- int result[5];
- Py_ssize_t itemsize = sizeof(int);
- Py_ssize_t shape = 5;
- Py_ssize_t strides = 2 * itemsize;
- Py_buffer view = {
data,[](#l2.16)
NULL,[](#l2.17)
5 * itemsize,[](#l2.18)
itemsize,[](#l2.19)
1,[](#l2.20)
1,[](#l2.21)
NULL,[](#l2.22)
&shape,[](#l2.23)
&strides,[](#l2.24)
NULL,[](#l2.25)
{0, 0},[](#l2.26)
NULL[](#l2.27)
- };
- int i;
- PyBuffer_ToContiguous(result, &view, view.len, 'C');
- for (i = 0; i < 5; i++) {
if (result[i] != i) {[](#l2.33)
PyErr_SetString(TestError,[](#l2.34)
"test_to_contiguous: incorrect result");[](#l2.35)
return NULL;[](#l2.36)
}[](#l2.37)
- }
- PyBuffer_ToContiguous(result, &view, view.len, 'C');
- for (i = 0; i < 5; i++) {
if (result[i] != 4-i) {[](#l2.45)
PyErr_SetString(TestError,[](#l2.46)
"test_to_contiguous: incorrect result");[](#l2.47)
return NULL;[](#l2.48)
}[](#l2.49)
- }
+} /* Tests of PyLong_{As, From}{Unsigned,}Long(), and (#ifdef HAVE_LONG_LONG) PyLong_{As, From}{Unsigned,}LongLong(). @@ -1785,6 +1832,7 @@ static PyMethodDef TestMethods[] = { {"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_to_contiguous", (PyCFunction)test_to_contiguous, METH_NOARGS}, {"test_long_api", (PyCFunction)test_long_api, METH_NOARGS}, {"test_long_and_overflow", (PyCFunction)test_long_and_overflow, METH_NOARGS},
--- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -499,7 +499,7 @@ PyBuffer_ToContiguous(void buf, Py_buff / Otherwise a more elaborate scheme is needed */
- /* view->ndim <= 64 */ indices = (Py_ssize_t *)PyMem_Malloc(sizeof(Py_ssize_t)*(view->ndim)); if (indices == NULL) { PyErr_NoMemory();
@@ -521,10 +521,10 @@ PyBuffer_ToContiguous(void *buf, Py_buff */ elements = len / view->itemsize; while (elements--) {
addone(view->ndim, indices, view->shape);[](#l3.16) ptr = PyBuffer_GetPointer(view, indices);[](#l3.17) memcpy(dest, ptr, view->itemsize);[](#l3.18) dest += view->itemsize;[](#l3.19)