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 | |
| 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 Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 20 | |
| 21 | |
| 22 | .. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) |
| 23 | |
Jeroen Ruigrok van der Werven | 47a7d70 | 2009-04-27 05:43:17 +0000 | [diff] [blame^] | 24 | 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 Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 33 | |
| 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 Werven | 47a7d70 | 2009-04-27 05:43:17 +0000 | [diff] [blame^] | 44 | 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 | |