@@ -44,7 +44,7 @@ the elements exposed by an :class:`array.array` can be multi-byte values.
44
44
45
45
An example consumer of the buffer interface is the :meth: `~io.BufferedIOBase.write `
46
46
method of file objects: any object that can export a series of bytes through
47
- the buffer interface can be written to a file. While :meth: `write ` only
47
+ the buffer interface can be written to a file. While :meth: `! write ` only
48
48
needs read-only access to the internal contents of the object passed to it,
49
49
other methods such as :meth: `~io.BufferedIOBase.readinto ` need write access
50
50
to the contents of their argument. The buffer interface allows objects to
@@ -102,7 +102,9 @@ a buffer, see :c:func:`PyObject_GetBuffer`.
102
102
.. c :member :: PyObject *obj
103
103
104
104
A new reference to the exporting object. The reference is owned by
105
- the consumer and automatically decremented and set to ``NULL `` by
105
+ the consumer and automatically released
106
+ (i.e. reference count decremented)
107
+ and set to ``NULL `` by
106
108
:c:func: `PyBuffer_Release `. The field is the equivalent of the return
107
109
value of any standard C-API function.
108
110
@@ -159,10 +161,7 @@ a buffer, see :c:func:`PyObject_GetBuffer`.
159
161
If it is ``0 ``, :c:member: `~Py_buffer.buf ` points to a single item representing
160
162
a scalar. In this case, :c:member: `~Py_buffer.shape `, :c:member: `~Py_buffer.strides `
161
163
and :c:member: `~Py_buffer.suboffsets ` MUST be ``NULL ``.
162
-
163
- The macro :c:macro: `PyBUF_MAX_NDIM ` limits the maximum number of dimensions
164
- to 64. Exporters MUST respect this limit, consumers of multi-dimensional
165
- buffers SHOULD be able to handle up to :c:macro: `PyBUF_MAX_NDIM ` dimensions.
164
+ The maximum number of dimensions is given by :c:macro: `PyBUF_MAX_NDIM `.
166
165
167
166
.. c :member :: Py_ssize_t *shape
168
167
@@ -215,6 +214,17 @@ a buffer, see :c:func:`PyObject_GetBuffer`.
215
214
freed when the buffer is released. The consumer MUST NOT alter this
216
215
value.
217
216
217
+
218
+ Constants:
219
+
220
+ .. c :macro :: PyBUF_MAX_NDIM
221
+
222
+ The maximum number of dimensions the memory represents.
223
+ Exporters MUST respect this limit, consumers of multi-dimensional
224
+ buffers SHOULD be able to handle up to :c:macro: `!PyBUF_MAX_NDIM ` dimensions.
225
+ Currently set to 64.
226
+
227
+
218
228
.. _buffer-request-types :
219
229
220
230
Buffer request types
@@ -225,7 +235,7 @@ object via :c:func:`PyObject_GetBuffer`. Since the complexity of the logical
225
235
structure of the memory can vary drastically, the consumer uses the *flags *
226
236
argument to specify the exact buffer type it can handle.
227
237
228
- All :c:data : `Py_buffer ` fields are unambiguously defined by the request
238
+ All :c:type : `Py_buffer ` fields are unambiguously defined by the request
229
239
type.
230
240
231
241
request-independent fields
@@ -438,7 +448,7 @@ Buffer-related functions
438
448
439
449
Send a request to *exporter * to fill in *view * as specified by *flags *.
440
450
If the exporter cannot provide a buffer of the exact type, it MUST raise
441
- :c:data: ` PyExc_BufferError `, set ``view->obj `` to ``NULL `` and
451
+ :exc: ` BufferError `, set ``view->obj `` to ``NULL `` and
442
452
return ``-1 ``.
443
453
444
454
On success, fill in *view *, set ``view->obj `` to a new reference
@@ -454,7 +464,8 @@ Buffer-related functions
454
464
455
465
.. c:function:: void PyBuffer_Release(Py_buffer *view)
456
466
457
- Release the buffer *view * and decrement the reference count for
467
+ Release the buffer *view * and release the :term: `strong reference `
468
+ (i.e. decrement the reference count) to the view's supporting object,
458
469
``view->obj``. This function MUST be called when the buffer
459
470
is no longer being used, otherwise reference leaks may occur.
460
471
@@ -464,7 +475,7 @@ Buffer-related functions
464
475
465
476
.. c:function:: Py_ssize_t PyBuffer_SizeFromFormat(const char *format)
466
477
467
- Return the implied :c:data : `~Py_buffer.itemsize ` from :c:data : `~Py_buffer.format `.
478
+ Return the implied :c:member : `~Py_buffer.itemsize ` from :c:member : `~Py_buffer.format `.
468
479
On error, raise an exception and return -1.
469
480
470
481
.. versionadded :: 3.9
@@ -499,7 +510,7 @@ Buffer-related functions
499
510
This function fails if *len* != *src->len*.
500
511
501
512
502
- .. c:function:: int PyObject_CopyData(Py_buffer *dest, Py_buffer *src)
513
+ .. c:function:: int PyObject_CopyData(PyObject *dest, PyObject *src)
503
514
504
515
Copy data from *src * to *dest * buffer. Can convert between C-style and
505
516
or Fortran-style buffers.
@@ -524,7 +535,7 @@ Buffer-related functions
524
535
and :c:macro: `PyBUF_WRITABLE ` is set in *flags *.
525
536
526
537
On success, set ``view->obj `` to a new reference to *exporter * and
527
- return 0. Otherwise, raise :c:data: ` PyExc_BufferError `, set
538
+ return 0. Otherwise, raise :exc: ` BufferError `, set
528
539
``view->obj `` to ``NULL `` and return ``-1 ``;
529
540
530
541
If this function is used as part of a :ref: `getbufferproc <buffer-structs >`,
0 commit comments