Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _abstract-buffer: |
| 4 | |
| 5 | Buffer Protocol |
| 6 | =============== |
| 7 | |
| 8 | |
| 9 | .. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) |
| 10 | |
Christian Heimes | c3f30c4 | 2008-02-22 16:37:40 +0000 | [diff] [blame] | 11 | Returns a pointer to a read-only memory location usable as character-based |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 12 | input. The *obj* argument must support the single-segment character buffer |
Jeroen Ruigrok van der Werven | 47a7d70 | 2009-04-27 05:43:17 +0000 | [diff] [blame] | 13 | 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 Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 17 | |
| 18 | .. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) |
| 19 | |
Jeroen Ruigrok van der Werven | 47a7d70 | 2009-04-27 05:43:17 +0000 | [diff] [blame] | 20 | 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 Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 26 | |
| 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 Werven | 47a7d70 | 2009-04-27 05:43:17 +0000 | [diff] [blame] | 36 | 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 | |