blob: ba6e38fd802453eef911c5fdf6ca72afa2a9d157 [file] [log] [blame]
Georg Brandlf6842722008-01-19 22:08:21 +00001.. highlightlang:: c
2
3.. _abstract-buffer:
4
Antoine Pitrou789be0c2009-04-02 21:18:34 +00005
6Old Buffer Protocol
7===================
8
9This section describes the legacy buffer protocol, which has been introduced
10in Python 1.6. It is still supported but deprecated in the Python 2.x series.
11Python 3.0 introduces a new buffer protocol which fixes weaknesses and
12shortcomings of the protocol, and has been backported to Python 2.6.
13See :ref:`bufferobjects` for more information.
Georg Brandlf6842722008-01-19 22:08:21 +000014
15
16.. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
17
Georg Brandl907a7202008-02-22 12:31:45 +000018 Returns a pointer to a read-only memory location usable as character-based
Georg Brandlf6842722008-01-19 22:08:21 +000019 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