blob: 13ccd6b5028b6162b976c3d75bbc3bebc586518c [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
Jeroen Ruigrok van der Werven27d51f12009-04-25 20:43:30 +000012shortcomings of the protocol, and has been backported to Python 2.6. See
13: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
Jeroen Ruigrok van der Werven27d51f12009-04-25 20:43:30 +000020 interface. On success, returns ``0``, sets *buffer* to the memory location
21 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
22 :exc:`TypeError` on error.
Georg Brandlf6842722008-01-19 22:08:21 +000023
24 .. versionadded:: 1.6
25
26
27.. cfunction:: int PyObject_AsReadBuffer(PyObject *obj, const void **buffer, Py_ssize_t *buffer_len)
28
Jeroen Ruigrok van der Werven27d51f12009-04-25 20:43:30 +000029 Returns a pointer to a read-only memory location containing arbitrary data.
30 The *obj* argument must support the single-segment readable buffer
31 interface. On success, returns ``0``, sets *buffer* to the memory location
32 and *buffer_len* to the buffer length. Returns ``-1`` and sets a
33 :exc:`TypeError` on error.
Georg Brandlf6842722008-01-19 22:08:21 +000034
35 .. versionadded:: 1.6
36
37
38.. cfunction:: int PyObject_CheckReadBuffer(PyObject *o)
39
40 Returns ``1`` if *o* supports the single-segment readable buffer interface.
41 Otherwise returns ``0``.
42
43 .. versionadded:: 2.2
44
45
46.. cfunction:: int PyObject_AsWriteBuffer(PyObject *obj, void **buffer, Py_ssize_t *buffer_len)
47
48 Returns a pointer to a writeable memory location. The *obj* argument must
Jeroen Ruigrok van der Werven27d51f12009-04-25 20:43:30 +000049 support the single-segment, character buffer interface. On success,
50 returns ``0``, sets *buffer* to the memory location and *buffer_len* to the
51 buffer length. Returns ``-1`` and sets a :exc:`TypeError` on error.
Georg Brandlf6842722008-01-19 22:08:21 +000052
53 .. versionadded:: 1.6
54