blob: 8b64e6c9e47c221dd0d371e7db735619934b4ee6 [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
3.. _bufferobjects:
4
Antoine Pitrou99a00a42010-09-28 23:04:04 +00005Buffer API
6----------
Georg Brandl54a3faa2008-01-20 09:30:57 +00007
8.. sectionauthor:: Greg Stein <gstein@lyra.org>
Benjamin Peterson9d0ced32008-09-16 02:24:31 +00009.. sectionauthor:: Benjamin Peterson
Georg Brandl54a3faa2008-01-20 09:30:57 +000010
11
12.. index::
Georg Brandl54a3faa2008-01-20 09:30:57 +000013 single: buffer interface
14
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000015Python objects implemented in C can export a "buffer interface." These
16functions can be used by an object to expose its data in a raw, byte-oriented
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000017format. Clients of the object can use the buffer interface to access the
18object data directly, without needing to copy it first.
Georg Brandl54a3faa2008-01-20 09:30:57 +000019
Antoine Pitrou99a00a42010-09-28 23:04:04 +000020Examples of objects that support the buffer interface are :class:`bytes`,
21:class:`bytearray` and :class:`array.array`. The bytes and bytearray objects
22exposes their bytes contents in the buffer interface's byte-oriented form.
23An :class:`array.array` can also expose its contents, but it should be noted
24that array elements may be multi-byte values.
Georg Brandl54a3faa2008-01-20 09:30:57 +000025
Antoine Pitrou99a00a42010-09-28 23:04:04 +000026An example consumer of the buffer interface is the :meth:`~io.BufferedIOBase.write`
27method of file objects: any object that can export a series of bytes through
28the buffer interface can be written to a file. While :meth:`write` only
29needs read-only access to the internal contents of the object passed to it,
30other methods such as :meth:`~io.BufferedIOBase.readinto` need write access
31to the contents of their argument. The buffer interface allows objects to
32selectively allow or reject exporting of read-write and read-only buffers.
33
34There are two ways for a consumer of the buffer interface to acquire a buffer
35over a target object:
36
37* call :cfunc:`PyObject_GetBuffer` with the right parameters;
38
39* call :cfunc:`PyArg_ParseTuple` (or one of its siblings) with one of the
40 ``y*``, ``w*`` or ``s*`` :ref:`format codes <arg-parsing>`.
41
42In both cases, :cfunc:`PyBuffer_Release` must be called when the buffer
43isn't needed anymore. Failure to do so could lead to various issues such as
44resource leaks.
45
Georg Brandl54a3faa2008-01-20 09:30:57 +000046
47.. index:: single: PyBufferProcs
48
Antoine Pitrou99a00a42010-09-28 23:04:04 +000049How the buffer interface is exposed by a type object is described in the
50section :ref:`buffer-structs`, under the description for :ctype:`PyBufferProcs`.
Georg Brandl54a3faa2008-01-20 09:30:57 +000051
Antoine Pitrou99a00a42010-09-28 23:04:04 +000052
53Buffer objects
54==============
55
56Buffer objects are useful as a way to expose the binary data from another
57object to the Python programmer. They can also be used as a zero-copy
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000058slicing mechanism. Using their ability to reference a block of memory, it is
59possible to expose any data to the Python programmer quite easily. The memory
Georg Brandl54a3faa2008-01-20 09:30:57 +000060could be a large, constant array in a C extension, it could be a raw block of
61memory for manipulation before passing to an operating system library, or it
62could be used to pass around structured data in its native, in-memory format.
63
Antoine Pitrou99a00a42010-09-28 23:04:04 +000064Contrary to most data types exposed by the Python interpreter, buffer objects
65are not :ctype:`PyObject` pointers but rather simple C structures. This
66allows them to be created and copied very simply. When a generic wrapper
67around a buffer object is needed, a :ref:`memoryview <memoryviewobjects>` object
68can be created.
69
Georg Brandl54a3faa2008-01-20 09:30:57 +000070
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000071.. ctype:: Py_buffer
Georg Brandl54a3faa2008-01-20 09:30:57 +000072
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000073 .. cmember:: void *buf
74
75 A pointer to the start of the memory for the object.
76
77 .. cmember:: Py_ssize_t len
Benjamin Petersonf2fa87b2008-09-17 22:59:21 +000078 :noindex:
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000079
80 The total length of the memory in bytes.
81
82 .. cmember:: int readonly
83
84 An indicator of whether the buffer is read only.
85
86 .. cmember:: const char *format
Benjamin Petersonf2fa87b2008-09-17 22:59:21 +000087 :noindex:
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000088
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +000089 A *NULL* terminated string in :mod:`struct` module style syntax giving
90 the contents of the elements available through the buffer. If this is
91 *NULL*, ``"B"`` (unsigned bytes) is assumed.
Benjamin Peterson9d0ced32008-09-16 02:24:31 +000092
93 .. cmember:: int ndim
94
95 The number of dimensions the memory represents as a multi-dimensional
96 array. If it is 0, :cdata:`strides` and :cdata:`suboffsets` must be
97 *NULL*.
98
99 .. cmember:: Py_ssize_t *shape
100
101 An array of :ctype:`Py_ssize_t`\s the length of :cdata:`ndim` giving the
102 shape of the memory as a multi-dimensional array. Note that
103 ``((*shape)[0] * ... * (*shape)[ndims-1])*itemsize`` should be equal to
104 :cdata:`len`.
105
106 .. cmember:: Py_ssize_t *strides
107
108 An array of :ctype:`Py_ssize_t`\s the length of :cdata:`ndim` giving the
109 number of bytes to skip to get to a new element in each dimension.
110
111 .. cmember:: Py_ssize_t *suboffsets
112
113 An array of :ctype:`Py_ssize_t`\s the length of :cdata:`ndim`. If these
114 suboffset numbers are greater than or equal to 0, then the value stored
115 along the indicated dimension is a pointer and the suboffset value
116 dictates how many bytes to add to the pointer after de-referencing. A
117 suboffset value that it negative indicates that no de-referencing should
118 occur (striding in a contiguous memory block).
119
120 Here is a function that returns a pointer to the element in an N-D array
Georg Brandlae2dbe22009-03-13 19:04:40 +0000121 pointed to by an N-dimensional index when there are both non-NULL strides
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000122 and suboffsets::
123
124 void *get_item_pointer(int ndim, void *buf, Py_ssize_t *strides,
125 Py_ssize_t *suboffsets, Py_ssize_t *indices) {
126 char *pointer = (char*)buf;
127 int i;
128 for (i = 0; i < ndim; i++) {
129 pointer += strides[i] * indices[i];
130 if (suboffsets[i] >=0 ) {
131 pointer = *((char**)pointer) + suboffsets[i];
Georg Brandl48310cd2009-01-03 21:18:54 +0000132 }
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000133 }
134 return (void*)pointer;
135 }
Georg Brandl54a3faa2008-01-20 09:30:57 +0000136
137
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000138 .. cmember:: Py_ssize_t itemsize
Georg Brandl54a3faa2008-01-20 09:30:57 +0000139
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000140 This is a storage for the itemsize (in bytes) of each element of the
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +0000141 shared memory. It is technically un-necessary as it can be obtained
142 using :cfunc:`PyBuffer_SizeFromFormat`, however an exporter may know
143 this information without parsing the format string and it is necessary
144 to know the itemsize for proper interpretation of striding. Therefore,
145 storing it is more convenient and faster.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000146
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000147 .. cmember:: void *internal
148
149 This is for use internally by the exporting object. For example, this
150 might be re-cast as an integer by the exporter and used to store flags
151 about whether or not the shape, strides, and suboffsets arrays must be
152 freed when the buffer is released. The consumer should never alter this
153 value.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000154
155
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000156Buffer related functions
157========================
Georg Brandl54a3faa2008-01-20 09:30:57 +0000158
159
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000160.. cfunction:: int PyObject_CheckBuffer(PyObject *obj)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000161
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000162 Return 1 if *obj* supports the buffer interface otherwise 0. When 1 is
163 returned, it doesn't guarantee that :cfunc:`PyObject_GetBuffer` will
164 succeed.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000165
166
Benjamin Petersonfa0d7032009-06-01 22:42:33 +0000167.. cfunction:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000168
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000169 Export a view over some internal data from the target object *obj*.
170 *obj* must not be NULL, and *view* must point to an existing
171 :ctype:`Py_buffer` structure allocated by the caller (most uses of
172 this function will simply declare a local variable of type
173 :ctype:`Py_buffer`). The *flags* argument is a bit field indicating
174 what kind of buffer is requested. The buffer interface allows
175 for complicated memory layout possibilities; however, some callers
176 won't want to handle all the complexity and instead request a simple
177 view of the target object (using :cmacro:`PyBUF_SIMPLE` for a read-only
178 view and :cmacro:`PyBUF_WRITABLE` for a read-write view).
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000179
180 Some exporters may not be able to share memory in every possible way and
181 may need to raise errors to signal to some consumers that something is
182 just not possible. These errors should be a :exc:`BufferError` unless
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +0000183 there is another error that is actually causing the problem. The
184 exporter can use flags information to simplify how much of the
185 :cdata:`Py_buffer` structure is filled in with non-default values and/or
186 raise an error if the object can't support a simpler view of its memory.
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000187
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000188 On success, 0 is returned and the *view* structure is filled with useful
189 values. On error, -1 is returned and an exception is raised; the *view*
190 is left in an undefined state.
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000191
192 The following table gives possible values to the *flags* arguments.
193
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000194 +------------------------------+---------------------------------------------------+
195 | Flag | Description |
196 +==============================+===================================================+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000197 | .. cmacro:: PyBUF_SIMPLE | This is the default flag. The returned buffer |
198 | | exposes a read-only memory area. The format of |
199 | | data is assumed to be raw unsigned bytes, without |
200 | | any particular structure. This is a "stand-alone"|
201 | | flag constant. It |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000202 | | never needs to be '|'d to the others. The exporter|
203 | | will raise an error if it cannot provide such a |
204 | | contiguous buffer of bytes. |
205 | | |
206 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000207 | .. cmacro:: PyBUF_WRITABLE | Like :cmacro:`PyBUF_SIMPLE`, but the returned |
208 | | buffer is writable. If the exporter doesn't |
209 | | support |
210 | | writable buffers, an error is raised. |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000211 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000212 | .. cmacro:: PyBUF_STRIDES | This implies :cmacro:`PyBUF_ND`. The returned |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000213 | | buffer must provide strides information (i.e. the |
214 | | strides cannot be NULL). This would be used when |
215 | | the consumer can handle strided, discontiguous |
216 | | arrays. Handling strides automatically assumes |
217 | | you can handle shape. The exporter can raise an |
218 | | error if a strided representation of the data is |
219 | | not possible (i.e. without the suboffsets). |
220 | | |
221 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000222 | .. cmacro:: PyBUF_ND | The returned buffer must provide shape |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000223 | | information. The memory will be assumed C-style |
224 | | contiguous (last dimension varies the |
225 | | fastest). The exporter may raise an error if it |
226 | | cannot provide this kind of contiguous buffer. If |
227 | | this is not given then shape will be *NULL*. |
228 | | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000229 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000230 |.. cmacro:: PyBUF_C_CONTIGUOUS| These flags indicate that the contiguity returned |
231 | PyBUF_F_CONTIGUOUS| buffer must be respectively, C-contiguous (last |
232 | PyBUF_ANY_CONTIGUOUS| dimension varies the fastest), Fortran contiguous |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000233 | | (first dimension varies the fastest) or either |
234 | | one. All of these flags imply |
235 | | :cmacro:`PyBUF_STRIDES` and guarantee that the |
236 | | strides buffer info structure will be filled in |
237 | | correctly. |
238 | | |
239 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000240 | .. cmacro:: PyBUF_INDIRECT | This flag indicates the returned buffer must have |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000241 | | suboffsets information (which can be NULL if no |
242 | | suboffsets are needed). This can be used when |
243 | | the consumer can handle indirect array |
244 | | referencing implied by these suboffsets. This |
245 | | implies :cmacro:`PyBUF_STRIDES`. |
246 | | |
247 | | |
248 | | |
249 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000250 | .. cmacro:: PyBUF_FORMAT | The returned buffer must have true format |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000251 | | information if this flag is provided. This would |
252 | | be used when the consumer is going to be checking |
253 | | for what 'kind' of data is actually stored. An |
254 | | exporter should always be able to provide this |
255 | | information if requested. If format is not |
256 | | explicitly requested then the format must be |
257 | | returned as *NULL* (which means ``'B'``, or |
258 | | unsigned bytes) |
259 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000260 | .. cmacro:: PyBUF_STRIDED | This is equivalent to ``(PyBUF_STRIDES | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000261 | | PyBUF_WRITABLE)``. |
262 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000263 | .. cmacro:: PyBUF_STRIDED_RO | This is equivalent to ``(PyBUF_STRIDES)``. |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000264 | | |
265 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000266 | .. cmacro:: PyBUF_RECORDS | This is equivalent to ``(PyBUF_STRIDES | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000267 | | PyBUF_FORMAT | PyBUF_WRITABLE)``. |
268 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000269 | .. cmacro:: PyBUF_RECORDS_RO | This is equivalent to ``(PyBUF_STRIDES | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000270 | | PyBUF_FORMAT)``. |
271 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000272 | .. cmacro:: PyBUF_FULL | This is equivalent to ``(PyBUF_INDIRECT | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000273 | | PyBUF_FORMAT | PyBUF_WRITABLE)``. |
274 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000275 | .. cmacro:: PyBUF_FULL_RO | This is equivalent to ``(PyBUF_INDIRECT | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000276 | | PyBUF_FORMAT)``. |
277 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000278 | .. cmacro:: PyBUF_CONTIG | This is equivalent to ``(PyBUF_ND | |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000279 | | PyBUF_WRITABLE)``. |
280 +------------------------------+---------------------------------------------------+
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000281 | .. cmacro:: PyBUF_CONTIG_RO | This is equivalent to ``(PyBUF_ND)``. |
Benjamin Petersonc1f44af2008-11-20 22:38:20 +0000282 | | |
283 +------------------------------+---------------------------------------------------+
Georg Brandl54a3faa2008-01-20 09:30:57 +0000284
285
Brian Curtin1fbd36b2010-06-08 22:27:07 +0000286.. cfunction:: void PyBuffer_Release(Py_buffer *view)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000287
Brian Curtin1fbd36b2010-06-08 22:27:07 +0000288 Release the buffer *view*. This should be called when the buffer is no
289 longer being used as it may free memory from it.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000290
291
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000292.. cfunction:: Py_ssize_t PyBuffer_SizeFromFormat(const char *)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000293
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000294 Return the implied :cdata:`~Py_buffer.itemsize` from the struct-stype
295 :cdata:`~Py_buffer.format`.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000296
297
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000298.. cfunction:: int PyObject_CopyToObject(PyObject *obj, void *buf, Py_ssize_t len, char fortran)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000299
Jeroen Ruigrok van der Wervenbd875522009-04-26 21:06:15 +0000300 Copy *len* bytes of data pointed to by the contiguous chunk of memory
301 pointed to by *buf* into the buffer exported by obj. The buffer must of
302 course be writable. Return 0 on success and return -1 and raise an error
303 on failure. If the object does not have a writable buffer, then an error
304 is raised. If *fortran* is ``'F'``, then if the object is
305 multi-dimensional, then the data will be copied into the array in
306 Fortran-style (first dimension varies the fastest). If *fortran* is
307 ``'C'``, then the data will be copied into the array in C-style (last
308 dimension varies the fastest). If *fortran* is ``'A'``, then it does not
309 matter and the copy will be made in whatever way is more efficient.
Georg Brandl54a3faa2008-01-20 09:30:57 +0000310
311
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000312.. cfunction:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran)
Georg Brandl54a3faa2008-01-20 09:30:57 +0000313
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000314 Return 1 if the memory defined by the *view* is C-style (*fortran* is
315 ``'C'``) or Fortran-style (*fortran* is ``'F'``) contiguous or either one
316 (*fortran* is ``'A'``). Return 0 otherwise.
317
318
319.. cfunction:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran)
320
321 Fill the *strides* array with byte-strides of a contiguous (C-style if
322 *fortran* is ``'C'`` or Fortran-style if *fortran* is ``'F'`` array of the
323 given shape with the given number of bytes per element.
324
325
Georg Brandl8668c222009-12-28 08:00:47 +0000326.. cfunction:: int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int infoflags)
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000327
328 Fill in a buffer-info structure, *view*, correctly for an exporter that can
329 only share a contiguous chunk of memory of "unsigned bytes" of the given
330 length. Return 0 on success and -1 (with raising an error) on error.
331
332
Benjamin Peterson0f46ffd2009-08-26 07:35:45 +0000333.. index::
334 object: memoryview
335
Antoine Pitrou99a00a42010-09-28 23:04:04 +0000336.. _memoryviewobjects:
Benjamin Peterson0f46ffd2009-08-26 07:35:45 +0000337
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000338MemoryView objects
339==================
340
Antoine Pitrou826903e2010-09-28 15:29:16 +0000341A :class:`memoryview` object exposes the C level buffer interface as a
342Python object which can then be passed around like any other object.
Benjamin Peterson0f46ffd2009-08-26 07:35:45 +0000343
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000344
Antoine Pitrou826903e2010-09-28 15:29:16 +0000345.. cfunction:: PyObject *PyMemoryView_FromObject(PyObject *obj)
Benjamin Peterson9d0ced32008-09-16 02:24:31 +0000346
Antoine Pitrou826903e2010-09-28 15:29:16 +0000347 Create a memoryview object from an object that defines the buffer interface.
Benjamin Peterson0f46ffd2009-08-26 07:35:45 +0000348
349
Antoine Pitrou826903e2010-09-28 15:29:16 +0000350.. cfunction:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view)
Benjamin Peterson0f46ffd2009-08-26 07:35:45 +0000351
Antoine Pitrou826903e2010-09-28 15:29:16 +0000352 Create a memoryview object wrapping the given buffer-info structure *view*.
353 The memoryview object then owns the buffer, which means you shouldn't
354 try to release it yourself: it will be released on deallocation of the
355 memoryview object.
356
357
358.. cfunction:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order)
359
360 Create a memoryview object to a contiguous chunk of memory (in either
361 'C' or 'F'ortran *order*) from an object that defines the buffer
Benjamin Peterson0f46ffd2009-08-26 07:35:45 +0000362 interface. If memory is contiguous, the memoryview object points to the
363 original memory. Otherwise copy is made and the memoryview points to a
364 new bytes object.
Antoine Pitrou826903e2010-09-28 15:29:16 +0000365
366
367.. cfunction:: int PyMemoryView_Check(PyObject *obj)
368
369 Return true if the object *obj* is a memoryview object. It is not
370 currently allowed to create subclasses of :class:`memoryview`.
371
372
373.. cfunction:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj)
374
375 Return a pointer to the buffer-info structure wrapped by the given
376 object. The object **must** be a memoryview instance; this macro doesn't
377 check its type, you must do it yourself or you will risk crashes.