From 704fde7d4ea21653b3ece81db04386cd97ab12f2 Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Fri, 15 Aug 2025 21:51:45 -0300 Subject: [PATCH 1/4] Update PyBuffer_FromContiguous definition: rename 'fort' parameter to 'order' to match its declaration. Update function comment to reflect new variable name as well. --- Include/pybuffer.h | 10 +++++----- Objects/abstract.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Include/pybuffer.h b/Include/pybuffer.h index ca1c6058d9052c..bd025372826265 100644 --- a/Include/pybuffer.h +++ b/Include/pybuffer.h @@ -67,20 +67,20 @@ PyAPI_FUNC(int) PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, error (i.e. the object does not have a buffer interface or it is not working). - If fort is 'F', then if the object is multi-dimensional, + If order is 'F', then if the object is multi-dimensional, then the data will be copied into the array in Fortran-style (first dimension varies the fastest). If - fort is 'C', then the data will be copied into the array - in C-style (last dimension varies the fastest). If fort + order is 'C', then the data will be copied into the array + in C-style (last dimension varies the fastest). If order is 'A', then it does not matter and the copy will be made in whatever way is more efficient. */ PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src); /* Copy the data from the src buffer to the buffer of destination. */ -PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort); +PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char order); /*Fill the strides array with byte-strides of a contiguous - (Fortran-style if fort is 'F' or C-style otherwise) + (Fortran-style if order is 'F' or C-style otherwise) array of the given shape with the given number of bytes per element. */ PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, diff --git a/Objects/abstract.c b/Objects/abstract.c index 8adad8407d04d4..a6383875b2b1a1 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -616,7 +616,7 @@ PyBuffer_SizeFromFormat(const char *format) } int -PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, char fort) +PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, char order) { int k; void (*addone)(int, Py_ssize_t *, const Py_ssize_t *); @@ -628,7 +628,7 @@ PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, len = view->len; } - if (PyBuffer_IsContiguous(view, fort)) { + if (PyBuffer_IsContiguous(view, order)) { /* simplest copy is all that is needed */ memcpy(view->buf, buf, len); return 0; @@ -646,7 +646,7 @@ PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, indices[k] = 0; } - if (fort == 'F') { + if (order == 'F') { addone = _Py_add_one_to_index_F; } else { From a892331b537fcfc65364d5e8ec3607ce7544577b Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Sat, 16 Aug 2025 13:20:47 -0300 Subject: [PATCH 2/4] Update documentation to reflect change to PyBuffer_FromContiguous --- Doc/c-api/buffer.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/buffer.rst b/Doc/c-api/buffer.rst index d3081894eadaf5..26ebd178ef4cae 100644 --- a/Doc/c-api/buffer.rst +++ b/Doc/c-api/buffer.rst @@ -501,10 +501,10 @@ Buffer-related functions *indices* must point to an array of ``view->ndim`` indices. -.. c:function:: int PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, char fort) +.. c:function:: int PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, char order) Copy contiguous *len* bytes from *buf* to *view*. - *fort* can be ``'C'`` or ``'F'`` (for C-style or Fortran-style ordering). + *order* can be ``'C'`` or ``'F'`` (for C-style or Fortran-style ordering). ``0`` is returned on success, ``-1`` on error. From 9173bf33e52dd70c7961bc13c65e85b0309a46bb Mon Sep 17 00:00:00 2001 From: Carlos Sousa Date: Mon, 18 Aug 2025 19:16:31 -0300 Subject: [PATCH 3/4] gh-137696: update PyBuffer_FillContiguousStrides, rename fort parameter to order --- Include/pybuffer.h | 2 +- Objects/abstract.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/pybuffer.h b/Include/pybuffer.h index bd025372826265..6371b9b483777b 100644 --- a/Include/pybuffer.h +++ b/Include/pybuffer.h @@ -87,7 +87,7 @@ PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims, Py_ssize_t *shape, Py_ssize_t *strides, int itemsize, - char fort); + char order); /* Fills in a buffer-info structure correctly for an exporter that can only share a contiguous chunk of memory of diff --git a/Objects/abstract.c b/Objects/abstract.c index a6383875b2b1a1..9afa42cdd4eb2d 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -741,13 +741,13 @@ int PyObject_CopyData(PyObject *dest, PyObject *src) void PyBuffer_FillContiguousStrides(int nd, Py_ssize_t *shape, Py_ssize_t *strides, int itemsize, - char fort) + char order) { int k; Py_ssize_t sd; sd = itemsize; - if (fort == 'F') { + if (order == 'F') { for (k=0; k Date: Mon, 18 Aug 2025 19:32:01 -0300 Subject: [PATCH 4/4] gh-137696: update PyBuffer_FromContiguous documentation to include case when order is 'A' --- Doc/c-api/buffer.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/buffer.rst b/Doc/c-api/buffer.rst index 26ebd178ef4cae..fae5b6240f2000 100644 --- a/Doc/c-api/buffer.rst +++ b/Doc/c-api/buffer.rst @@ -504,7 +504,11 @@ Buffer-related functions .. c:function:: int PyBuffer_FromContiguous(const Py_buffer *view, const void *buf, Py_ssize_t len, char order) Copy contiguous *len* bytes from *buf* to *view*. - *order* can be ``'C'`` or ``'F'`` (for C-style or Fortran-style ordering). + + If *order* is ``'C'``, the data is copied in C-style order. + If *order* is ``'F'``, the data is copied in Fortran-style order. + If *order* is ``'A'``, either style may be used, whichever is more efficient. + ``0`` is returned on success, ``-1`` on error.