blob: e7f4fde00256db7bb993a406927d00a0f0f49a2a [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
Antoine Pitrouf7ba2fa2010-09-28 23:39:41 +00003Old Buffer Protocol
4-------------------
Antoine Pitroua0b68732010-09-28 21:52:30 +00005
6.. deprecated:: 3.0
7
8These functions were part of the "old buffer protocol" API in Python 2.
Antoine Pitrouf7ba2fa2010-09-28 23:39:41 +00009In Python 3, this protocol doesn't exist anymore but the functions are still
10exposed to ease porting 2.x code. They act as a compatibility wrapper
11around the :ref:`new buffer protocol <bufferobjects>`, but they don't give
12you control over the lifetime of the resources acquired when a buffer is
13exported.
Antoine Pitroua0b68732010-09-28 21:52:30 +000014
Georg Brandl60203b42010-10-06 10:11:56 +000015Therefore, it is recommended that you call :c:func:`PyObject_GetBuffer`
Antoine Pitroua0b68732010-09-28 21:52:30 +000016(or the ``y*`` or ``w*`` :ref:`format codes <arg-parsing>` with the
Georg Brandl60203b42010-10-06 10:11:56 +000017:c:func:`PyArg_ParseTuple` family of functions) to get a buffer view over
18an object, and :c:func:`PyBuffer_Release` when the buffer view can be released.
Antoine Pitroua0b68732010-09-28 21:52:30 +000019
Georg Brandl54a3faa2008-01-20 09:30:57 +000020
Georg Brandl60203b42010-10-06 10:11:56 +000021.. c:function:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
Georg Brandl54a3faa2008-01-20 09:30:57 +000022
Christian Heimesc3f30c42008-02-22 16:37:40 +000023 Returns a pointer to a read-only memory location usable as character-based
Georg Brandl54a3faa2008-01-20 09:30:57 +000024 input. The *obj* argument must support the single-segment character buffer
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000025 interface. On success, returns ``0``, sets *buffer* to the memory location
26 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
27 :exc:`TypeError` on error.
28
Georg Brandl54a3faa2008-01-20 09:30:57 +000029
Georg Brandl60203b42010-10-06 10:11:56 +000030.. c:function:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
Georg Brandl54a3faa2008-01-20 09:30:57 +000031
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000032 Returns a pointer to a read-only memory location containing arbitrary data.
33 The *obj* argument must support the single-segment readable buffer
34 interface. On success, returns ``0``, sets *buffer* to the memory location
35 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
36 :exc:`TypeError` on error.
37
Georg Brandl54a3faa2008-01-20 09:30:57 +000038
Georg Brandl60203b42010-10-06 10:11:56 +000039.. c:function:: int PyObject_CheckReadBuffer(PyObject *o)
Georg Brandl54a3faa2008-01-20 09:30:57 +000040
41 Returns ``1`` if *o* supports the single-segment readable buffer interface.
42 Otherwise returns ``0``.
43
44
Georg Brandl60203b42010-10-06 10:11:56 +000045.. c:function:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
Georg Brandl54a3faa2008-01-20 09:30:57 +000046
47 Returns a pointer to a writable memory location. The *obj* argument must
Jeroen Ruigrok van der Werven47a7d702009-04-27 05:43:17 +000048 support the single-segment, character buffer interface. On success,
49 returns ``0``, sets *buffer* to the memory location and *buffer_len* to the
50 buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
51