blob: e816c3d402e7d8cd8af89d96758cfd94c705bd47 [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
17 .. versionchanged:: 2.5
18 This function used an :ctype:`int *` type for *buffer_len*. This might
19 require changes in your code for properly supporting 64-bit systems.
Georg Brandl54a3faa2008-01-20 09:30:57 +000020
21
22.. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
23
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000024 Returns a pointer to a read-only memory location containing arbitrary data.
25 The *obj* argument must support the single-segment readable buffer
26 interface. On success, returns ``0``, sets *buffer* to the memory location
27 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
28 :exc:`TypeError` on error.
29
30 .. versionchanged:: 2.5
31 This function used an :ctype:`int *` type for *buffer_len*. This might
32 require changes in your code for properly supporting 64-bit systems.
Georg Brandl54a3faa2008-01-20 09:30:57 +000033
34
35.. cfunction:: int PyObject_CheckReadBuffer(PyObject *o)
36
37 Returns ``1`` if *o* supports the single-segment readable buffer interface.
38 Otherwise returns ``0``.
39
40
41.. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
42
43 Returns a pointer to a writable memory location. The *obj* argument must
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000044 support the single-segment, character buffer interface. On success,
45 returns ``0``, sets *buffer* to the memory location and *buffer_len* to the
46 buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
47
48 .. versionchanged:: 2.5
49 This function used an :ctype:`int *` type for *buffer_len*. This might
50 require changes in your code for properly supporting 64-bit systems.
51