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 |
| 12 | shortcomings of the protocol, and has been backported to Python 2.6. |
| 13 | See :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 |
| 20 | interface. On success, returns ``0``, sets *buffer* to the memory location and |
| 21 | *buffer_len* to the buffer length. Returns ``-1`` and sets a :exc:`TypeError` |
| 22 | on error. |
| 23 | |
| 24 | .. versionadded:: 1.6 |
| 25 | |
| 26 | |
| 27 | .. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) |
| 28 | |
| 29 | Returns a pointer to a read-only memory location containing arbitrary data. The |
| 30 | *obj* argument must support the single-segment readable buffer interface. On |
| 31 | success, returns ``0``, sets *buffer* to the memory location and *buffer_len* to |
| 32 | the buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error. |
| 33 | |
| 34 | .. versionadded:: 1.6 |
| 35 | |
| 36 | |
| 37 | .. cfunction:: int PyObject_CheckReadBuffer(PyObject *o) |
| 38 | |
| 39 | Returns ``1`` if *o* supports the single-segment readable buffer interface. |
| 40 | Otherwise returns ``0``. |
| 41 | |
| 42 | .. versionadded:: 2.2 |
| 43 | |
| 44 | |
| 45 | .. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len) |
| 46 | |
| 47 | Returns a pointer to a writeable memory location. The *obj* argument must |
| 48 | support the single-segment, character buffer interface. On success, returns |
| 49 | ``0``, sets *buffer* to the memory location and *buffer_len* to the buffer |
| 50 | length. Returns ``-1`` and sets a :exc:`TypeError` on error. |
| 51 | |
| 52 | .. versionadded:: 1.6 |
| 53 | |