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 | |
| 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. |