Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _abstract-buffer: |
| 4 | |
Antoine Pitrou | 789be0c | 2009-04-02 21:18:34 +0000 | [diff] [blame] | 5 | |
| 6 | Old Buffer Protocol |
| 7 | =================== |
| 8 | |
| 9 | This section describes the legacy buffer protocol, which has been introduced |
| 10 | in Python 1.6. It is still supported but deprecated in the Python 2.x series. |
| 11 | Python 3.0 introduces a new buffer protocol which fixes weaknesses and |
Jeroen Ruigrok van der Werven | 27d51f1 | 2009-04-25 20:43:30 +0000 | [diff] [blame] | 12 | shortcomings of the protocol, and has been backported to Python 2.6. See |
| 13 | :ref:`bufferobjects` for more information. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | .. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) |
| 17 | |
Georg Brandl | 907a720 | 2008-02-22 12:31:45 +0000 | [diff] [blame] | 18 | Returns a pointer to a read-only memory location usable as character-based |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 19 | input. The *obj* argument must support the single-segment character buffer |
Jeroen Ruigrok van der Werven | 27d51f1 | 2009-04-25 20:43:30 +0000 | [diff] [blame] | 20 | interface. On success, returns ``0``, sets *buffer* to the memory location |
| 21 | and *buffer_len* to the buffer length. Returns ``-1`` and sets a |
| 22 | :exc:`TypeError` on error. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 23 | |
| 24 | .. versionadded:: 1.6 |
| 25 | |
Jeroen Ruigrok van der Werven | 9594c2c | 2009-04-25 20:44:58 +0000 | [diff] [blame] | 26 | .. versionchanged:: 2.5 |
| 27 | This function used an :ctype:`int *` type for *buffer_len*. This might |
| 28 | require changes in your code for properly supporting 64-bit systems. |
| 29 | |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 30 | |
| 31 | .. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) |
| 32 | |
Jeroen Ruigrok van der Werven | 27d51f1 | 2009-04-25 20:43:30 +0000 | [diff] [blame] | 33 | Returns a pointer to a read-only memory location containing arbitrary data. |
| 34 | The *obj* argument must support the single-segment readable buffer |
| 35 | interface. On success, returns ``0``, sets *buffer* to the memory location |
| 36 | and *buffer_len* to the buffer length. Returns ``-1`` and sets a |
| 37 | :exc:`TypeError` on error. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 38 | |
| 39 | .. versionadded:: 1.6 |
| 40 | |
Jeroen Ruigrok van der Werven | 9594c2c | 2009-04-25 20:44:58 +0000 | [diff] [blame] | 41 | .. versionchanged:: 2.5 |
| 42 | This function used an :ctype:`int *` type for *buffer_len*. This might |
| 43 | require changes in your code for properly supporting 64-bit systems. |
| 44 | |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 45 | |
| 46 | .. cfunction:: int PyObject_CheckReadBuffer(PyObject *o) |
| 47 | |
| 48 | Returns ``1`` if *o* supports the single-segment readable buffer interface. |
| 49 | Otherwise returns ``0``. |
| 50 | |
| 51 | .. versionadded:: 2.2 |
| 52 | |
| 53 | |
| 54 | .. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len) |
| 55 | |
| 56 | Returns a pointer to a writeable memory location. The *obj* argument must |
Jeroen Ruigrok van der Werven | 27d51f1 | 2009-04-25 20:43:30 +0000 | [diff] [blame] | 57 | support the single-segment, character buffer interface. On success, |
| 58 | returns ``0``, sets *buffer* to the memory location and *buffer_len* to the |
| 59 | buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error. |
Georg Brandl | f684272 | 2008-01-19 22:08:21 +0000 | [diff] [blame] | 60 | |
| 61 | .. versionadded:: 1.6 |
| 62 | |
Jeroen Ruigrok van der Werven | 9594c2c | 2009-04-25 20:44:58 +0000 | [diff] [blame] | 63 | .. versionchanged:: 2.5 |
| 64 | This function used an :ctype:`int *` type for *buffer_len*. This might |
| 65 | require changes in your code for properly supporting 64-bit systems. |
| 66 | |