Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
Antoine Pitrou | a0b6873 | 2010-09-28 21:52:30 +0000 | [diff] [blame^] | 3 | Old buffer API |
| 4 | -------------- |
| 5 | |
| 6 | .. deprecated:: 3.0 |
| 7 | |
| 8 | These functions were part of the "old buffer protocol" API in Python 2. |
| 9 | In Python 3, these functions are still exposed for ease of porting code. |
| 10 | They act as a compatibility wrapper around the :ref:`new buffer API |
| 11 | <bufferobjects>`, but they don't give you control over the lifetime of |
| 12 | the resources acquired when a buffer is exported. |
| 13 | |
| 14 | Therefore, it is recommended that you call :cfunc:`PyObject_GetBuffer` |
| 15 | (or the ``y*`` or ``w*`` :ref:`format codes <arg-parsing>` with the |
| 16 | :cfunc:`PyArg_ParseTuple` family of functions) to get a buffer view over |
| 17 | an object, and :cfunc:`PyBuffer_Release` when the buffer view can be released. |
| 18 | |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 19 | |
| 20 | Buffer Protocol |
| 21 | =============== |
| 22 | |
| 23 | |
| 24 | .. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len) |
| 25 | |
Christian Heimes | c3f30c4 | 2008-02-22 16:37:40 +0000 | [diff] [blame] | 26 | 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] | 27 | 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] | 28 | interface. On success, returns ``0``, sets *buffer* to the memory location |
| 29 | and *buffer_len* to the buffer length. Returns ``-1`` and sets a |
| 30 | :exc:`TypeError` on error. |
| 31 | |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 32 | |
| 33 | .. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len) |
| 34 | |
Jeroen Ruigrok van der Werven | 47a7d70 | 2009-04-27 05:43:17 +0000 | [diff] [blame] | 35 | Returns a pointer to a read-only memory location containing arbitrary data. |
| 36 | The *obj* argument must support the single-segment readable buffer |
| 37 | interface. On success, returns ``0``, sets *buffer* to the memory location |
| 38 | and *buffer_len* to the buffer length. Returns ``-1`` and sets a |
| 39 | :exc:`TypeError` on error. |
| 40 | |
Georg Brandl | 54a3faa | 2008-01-20 09:30:57 +0000 | [diff] [blame] | 41 | |
| 42 | .. cfunction:: int PyObject_CheckReadBuffer(PyObject *o) |
| 43 | |
| 44 | Returns ``1`` if *o* supports the single-segment readable buffer interface. |
| 45 | Otherwise returns ``0``. |
| 46 | |
| 47 | |
| 48 | .. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len) |
| 49 | |
| 50 | 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] | 51 | support the single-segment, character buffer interface. On success, |
| 52 | returns ``0``, sets *buffer* to the memory location and *buffer_len* to the |
| 53 | buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error. |
| 54 | |