blob: 0973aad19b073b3f10c6a0892a972df7c5611586 [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
Christian Heimesc3f30c42008-02-22 16:37:40 +000011 Returns a pointer to a read-only memory location usable as character-based
Georg Brandl54a3faa2008-01-20 09:30:57 +000012 input. The *obj* argument must support the single-segment character buffer
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000013 interface. On success, returns ``0``, sets *buffer* to the memory location
14 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
15 :exc:`TypeError` on error.
16
Georg Brandl54a3faa2008-01-20 09:30:57 +000017
18.. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
19
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000020 Returns a pointer to a read-only memory location containing arbitrary data.
21 The *obj* argument must support the single-segment readable buffer
22 interface. On success, returns ``0``, sets *buffer* to the memory location
23 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
24 :exc:`TypeError` on error.
25
Georg Brandl54a3faa2008-01-20 09:30:57 +000026
27.. cfunction:: int PyObject_CheckReadBuffer(PyObject *o)
28
29 Returns ``1`` if *o* supports the single-segment readable buffer interface.
30 Otherwise returns ``0``.
31
32
33.. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
34
35 Returns a pointer to a writable memory location. The *obj* argument must
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000036 support the single-segment, character buffer interface. On success,
37 returns ``0``, sets *buffer* to the memory location and *buffer_len* to the
38 buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
39