Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7ba2fa

Browse files
committed
Buffers are not sequence objects (!). Put them in the abstract objects layers
instead.
1 parent 99a00a4 commit f7ba2fa

4 files changed

Lines changed: 22 additions & 24 deletions

File tree

Doc/c-api/abstract.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ but whose items have not been set to some non-\ ``NULL`` value yet.
2222
sequence.rst
2323
mapping.rst
2424
iter.rst
25+
buffer.rst
2526
objbuffer.rst

Doc/c-api/buffer.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
.. _bufferobjects:
44

5-
Buffer API
6-
----------
5+
Buffer Protocol
6+
---------------
77

88
.. sectionauthor:: Greg Stein <[email protected]>
99
.. sectionauthor:: Benjamin Peterson
@@ -50,21 +50,22 @@ How the buffer interface is exposed by a type object is described in the
5050
section :ref:`buffer-structs`, under the description for :ctype:`PyBufferProcs`.
5151

5252

53-
Buffer objects
54-
==============
53+
The buffer structure
54+
====================
5555

56-
Buffer objects are useful as a way to expose the binary data from another
57-
object to the Python programmer. They can also be used as a zero-copy
58-
slicing mechanism. Using their ability to reference a block of memory, it is
59-
possible to expose any data to the Python programmer quite easily. The memory
60-
could be a large, constant array in a C extension, it could be a raw block of
61-
memory for manipulation before passing to an operating system library, or it
62-
could be used to pass around structured data in its native, in-memory format.
56+
Buffer structures (or simply "buffers") are useful as a way to expose the
57+
binary data from another object to the Python programmer. They can also be
58+
used as a zero-copy slicing mechanism. Using their ability to reference a
59+
block of memory, it is possible to expose any data to the Python programmer
60+
quite easily. The memory could be a large, constant array in a C extension,
61+
it could be a raw block of memory for manipulation before passing to an
62+
operating system library, or it could be used to pass around structured data
63+
in its native, in-memory format.
6364

64-
Contrary to most data types exposed by the Python interpreter, buffer objects
65+
Contrary to most data types exposed by the Python interpreter, buffers
6566
are not :ctype:`PyObject` pointers but rather simple C structures. This
6667
allows them to be created and copied very simply. When a generic wrapper
67-
around a buffer object is needed, a :ref:`memoryview <memoryviewobjects>` object
68+
around a buffer is needed, a :ref:`memoryview <memoryviewobjects>` object
6869
can be created.
6970

7071

Doc/c-api/concrete.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ intrinsic to the Python language.
6868
bytes.rst
6969
bytearray.rst
7070
unicode.rst
71-
buffer.rst
7271
tuple.rst
7372
list.rst
7473

Doc/c-api/objbuffer.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
.. highlightlang:: c
22

3-
Old buffer API
4-
--------------
3+
Old Buffer Protocol
4+
-------------------
55

66
.. deprecated:: 3.0
77

88
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.
9+
In Python 3, this protocol doesn't exist anymore but the functions are still
10+
exposed to ease porting 2.x code. They act as a compatibility wrapper
11+
around the :ref:`new buffer protocol <bufferobjects>`, but they don't give
12+
you control over the lifetime of the resources acquired when a buffer is
13+
exported.
1314

1415
Therefore, it is recommended that you call :cfunc:`PyObject_GetBuffer`
1516
(or the ``y*`` or ``w*`` :ref:`format codes <arg-parsing>` with the
1617
:cfunc:`PyArg_ParseTuple` family of functions) to get a buffer view over
1718
an object, and :cfunc:`PyBuffer_Release` when the buffer view can be released.
1819

1920

20-
Buffer Protocol
21-
===============
22-
23-
2421
.. cfunction:: int PyObject_AsCharBuffer(PyObject *obj, const char **buffer, Py_ssize_t *buffer_len)
2522

2623
Returns a pointer to a read-only memory location usable as character-based

0 commit comments

Comments
 (0)