blob: 2ce0d974222d2f236a38327d38ad46ea8e79b5d1 [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
3.. _abstract-buffer:
4
5Buffer Protocol
6===============
7
8
9.. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
10
11 Returns a pointer to a read-only memory location useable as character- based
12 input. The *obj* argument must support the single-segment character buffer
13 interface. On success, returns ``0``, sets *buffer* to the memory location and
14 *buffer_len* to the buffer length. Returns ``-1`` and sets a :exc:`TypeError`
15 on error.
16
17
18.. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
19
20 Returns a pointer to a read-only memory location containing arbitrary data. The
21 *obj* argument must support the single-segment readable buffer interface. On
22 success, returns ``0``, sets *buffer* to the memory location and *buffer_len* to
23 the buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
24
25
26.. cfunction:: int PyObject_CheckReadBuffer(PyObject *o)
27
28 Returns ``1`` if *o* supports the single-segment readable buffer interface.
29 Otherwise returns ``0``.
30
31
32.. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
33
34 Returns a pointer to a writable memory location. The *obj* argument must
35 support the single-segment, character buffer interface. On success, returns
36 ``0``, sets *buffer* to the memory location and *buffer_len* to the buffer
37 length. Returns ``-1`` and sets a :exc:`TypeError` on error.