blob: 728d38343f4a0ea2d959bcc6b2bdafaec1e4eed8 [file] [log] [blame]
Georg Brandl54a3faa2008-01-20 09:30:57 +00001.. highlightlang:: c
2
Antoine Pitroudebf4db2010-09-28 23:41:31 +00003Old Buffer Protocol
4-------------------
Antoine Pitrou6db43fd2010-09-28 21:53:46 +00005
6.. deprecated:: 3.0
7
8These functions were part of the "old buffer protocol" API in Python 2.
Antoine Pitroudebf4db2010-09-28 23:41:31 +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 Pitrou6db43fd2010-09-28 21:53:46 +000014
15Therefore, it is recommended that you call :cfunc:`PyObject_GetBuffer`
16(or the ``y*`` or ``w*`` :ref:`format codes <arg-parsing>` with the
17:cfunc:`PyArg_ParseTuple` family of functions) to get a buffer view over
18an object, and :cfunc:`PyBuffer_Release` when the buffer view can be released.
19
Georg Brandl54a3faa2008-01-20 09:30:57 +000020
Georg Brandl54a3faa2008-01-20 09:30:57 +000021.. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
22
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
30.. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
31
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
39.. cfunction:: int PyObject_CheckReadBuffer(PyObject *o)
40
41 Returns ``1`` if *o* supports the single-segment readable buffer interface.
42 Otherwise returns ``0``.
43
44
45.. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
46
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