@@ -1213,18 +1213,29 @@ Buffer Object Structures
12131213 int (PyObject *exporter, Py_buffer *view, int flags);
12141214
12151215 Handle a request to *exporter * to fill in *view * as specified by *flags *.
1216- A standard implementation of this function will take these steps:
1216+ Except for point (3), an implementation of this function MUST take these
1217+ steps:
12171218
1218- - Check if the request can be met. If not, raise :c:data: `PyExc_BufferError `,
1219- set :c:data: `view->obj ` to *NULL * and return -1.
1219+ (1) Check if the request can be met. If not, raise :c:data: `PyExc_BufferError `,
1220+ set :c:data: `view->obj ` to *NULL * and return -1.
12201221
1221- - Fill in the requested fields.
1222+ (2) Fill in the requested fields.
12221223
1223- - Increment an internal counter for the number of exports.
1224+ (3) Increment an internal counter for the number of exports.
12241225
1225- - Set :c:data: `view->obj ` to *exporter * and increment :c:data: `view->obj `.
1226+ (4) Set :c:data: `view->obj ` to *exporter * and increment :c:data: `view->obj `.
12261227
1227- - Return 0.
1228+ (5) Return 0.
1229+
1230+ If *exporter * is part of a chain or tree of buffer providers, two main
1231+ schemes can be used:
1232+
1233+ * Re-export: Each member of the tree acts as the exporting object and
1234+ sets :c:data: `view->obj ` to a new reference to itself.
1235+
1236+ * Redirect: The buffer request is redirected to the root object of the
1237+ tree. Here, :c:data: `view->obj ` will be a new reference to the root
1238+ object.
12281239
12291240 The individual fields of *view * are described in section
12301241 :ref: `Buffer structure <buffer-structure >`, the rules how an exporter
@@ -1233,8 +1244,9 @@ Buffer Object Structures
12331244
12341245 All memory pointed to in the :c:type: `Py_buffer ` structure belongs to
12351246 the exporter and must remain valid until there are no consumers left.
1236- :c:member: `~Py_buffer.shape `, :c:member: `~Py_buffer.strides `,
1237- :c:member: `~Py_buffer.suboffsets ` and :c:member: `~Py_buffer.internal `
1247+ :c:member: `~Py_buffer.format `, :c:member: `~Py_buffer.shape `,
1248+ :c:member: `~Py_buffer.strides `, :c:member: `~Py_buffer.suboffsets `
1249+ and :c:member: `~Py_buffer.internal `
12381250 are read-only for the consumer.
12391251
12401252 :c:func: `PyBuffer_FillInfo ` provides an easy way of exposing a simple
@@ -1250,21 +1262,23 @@ Buffer Object Structures
12501262 void (PyObject *exporter, Py_buffer *view);
12511263
12521264 Handle a request to release the resources of the buffer. If no resources
1253- need to be released, this field may be *NULL *. A standard implementation
1254- of this function will take these steps:
1265+ need to be released, :c:member: `PyBufferProcs.bf_releasebuffer ` may be
1266+ *NULL *. Otherwise, a standard implementation of this function will take
1267+ these optional steps:
12551268
1256- - Decrement an internal counter for the number of exports.
1269+ (1) Decrement an internal counter for the number of exports.
12571270
1258- - If the counter is 0, free all memory associated with *view *.
1271+ (2) If the counter is 0, free all memory associated with *view *.
12591272
12601273 The exporter MUST use the :c:member: `~Py_buffer.internal ` field to keep
1261- track of buffer-specific resources (if present) . This field is guaranteed
1262- to remain constant, while a consumer MAY pass a copy of the original buffer
1263- as the *view * argument.
1274+ track of buffer-specific resources. This field is guaranteed to remain
1275+ constant, while a consumer MAY pass a copy of the original buffer as the
1276+ *view * argument.
12641277
12651278
12661279 This function MUST NOT decrement :c:data: `view->obj `, since that is
1267- done automatically in :c:func: `PyBuffer_Release `.
1280+ done automatically in :c:func: `PyBuffer_Release ` (this scheme is
1281+ useful for breaking reference cycles).
12681282
12691283
12701284 :c:func: `PyBuffer_Release ` is the interface for the consumer that
0 commit comments