summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/buffer.rst
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-06 10:11:56 (GMT)
committerGeorg Brandl <georg@python.org>2010-10-06 10:11:56 (GMT)
commit60203b41b03d03361754d264543d5fbe6259eb25 (patch)
tree005d0d6be6437244ae360ebc0d65fa7b149a8093 /Doc/c-api/buffer.rst
parent64a41edb039afee683d69bd6f72e3709ff11bd93 (diff)
downloadcpython-60203b41b03d03361754d264543d5fbe6259eb25.zip
cpython-60203b41b03d03361754d264543d5fbe6259eb25.tar.gz
cpython-60203b41b03d03361754d264543d5fbe6259eb25.tar.bz2
Migrate to Sphinx 1.0 C language constructs.
Diffstat (limited to 'Doc/c-api/buffer.rst')
-rw-r--r--Doc/c-api/buffer.rst114
1 files changed, 57 insertions, 57 deletions
diff --git a/Doc/c-api/buffer.rst b/Doc/c-api/buffer.rst
index 56bb897..64e8360 100644
--- a/Doc/c-api/buffer.rst
+++ b/Doc/c-api/buffer.rst
@@ -34,12 +34,12 @@ selectively allow or reject exporting of read-write and read-only buffers.
There are two ways for a consumer of the buffer interface to acquire a buffer
over a target object:
-* call :cfunc:`PyObject_GetBuffer` with the right parameters;
+* call :c:func:`PyObject_GetBuffer` with the right parameters;
-* call :cfunc:`PyArg_ParseTuple` (or one of its siblings) with one of the
+* call :c:func:`PyArg_ParseTuple` (or one of its siblings) with one of the
``y*``, ``w*`` or ``s*`` :ref:`format codes <arg-parsing>`.
-In both cases, :cfunc:`PyBuffer_Release` must be called when the buffer
+In both cases, :c:func:`PyBuffer_Release` must be called when the buffer
isn't needed anymore. Failure to do so could lead to various issues such as
resource leaks.
@@ -47,7 +47,7 @@ resource leaks.
.. index:: single: PyBufferProcs
How the buffer interface is exposed by a type object is described in the
-section :ref:`buffer-structs`, under the description for :ctype:`PyBufferProcs`.
+section :ref:`buffer-structs`, under the description for :c:type:`PyBufferProcs`.
The buffer structure
@@ -63,55 +63,55 @@ operating system library, or it could be used to pass around structured data
in its native, in-memory format.
Contrary to most data types exposed by the Python interpreter, buffers
-are not :ctype:`PyObject` pointers but rather simple C structures. This
+are not :c:type:`PyObject` pointers but rather simple C structures. This
allows them to be created and copied very simply. When a generic wrapper
around a buffer is needed, a :ref:`memoryview <memoryview-objects>` object
can be created.
-.. ctype:: Py_buffer
+.. c:type:: Py_buffer
- .. cmember:: void *buf
+ .. c:member:: void *buf
A pointer to the start of the memory for the object.
- .. cmember:: Py_ssize_t len
+ .. c:member:: Py_ssize_t len
:noindex:
The total length of the memory in bytes.
- .. cmember:: int readonly
+ .. c:member:: int readonly
An indicator of whether the buffer is read only.
- .. cmember:: const char *format
+ .. c:member:: const char *format
:noindex:
A *NULL* terminated string in :mod:`struct` module style syntax giving
the contents of the elements available through the buffer. If this is
*NULL*, ``"B"`` (unsigned bytes) is assumed.
- .. cmember:: int ndim
+ .. c:member:: int ndim
The number of dimensions the memory represents as a multi-dimensional
- array. If it is 0, :cdata:`strides` and :cdata:`suboffsets` must be
+ array. If it is 0, :c:data:`strides` and :c:data:`suboffsets` must be
*NULL*.
- .. cmember:: Py_ssize_t *shape
+ .. c:member:: Py_ssize_t *shape
- An array of :ctype:`Py_ssize_t`\s the length of :cdata:`ndim` giving the
+ An array of :c:type:`Py_ssize_t`\s the length of :c:data:`ndim` giving the
shape of the memory as a multi-dimensional array. Note that
``((*shape)[0] * ... * (*shape)[ndims-1])*itemsize`` should be equal to
- :cdata:`len`.
+ :c:data:`len`.
- .. cmember:: Py_ssize_t *strides
+ .. c:member:: Py_ssize_t *strides
- An array of :ctype:`Py_ssize_t`\s the length of :cdata:`ndim` giving the
+ An array of :c:type:`Py_ssize_t`\s the length of :c:data:`ndim` giving the
number of bytes to skip to get to a new element in each dimension.
- .. cmember:: Py_ssize_t *suboffsets
+ .. c:member:: Py_ssize_t *suboffsets
- An array of :ctype:`Py_ssize_t`\s the length of :cdata:`ndim`. If these
+ An array of :c:type:`Py_ssize_t`\s the length of :c:data:`ndim`. If these
suboffset numbers are greater than or equal to 0, then the value stored
along the indicated dimension is a pointer and the suboffset value
dictates how many bytes to add to the pointer after de-referencing. A
@@ -136,16 +136,16 @@ can be created.
}
- .. cmember:: Py_ssize_t itemsize
+ .. c:member:: Py_ssize_t itemsize
This is a storage for the itemsize (in bytes) of each element of the
shared memory. It is technically un-necessary as it can be obtained
- using :cfunc:`PyBuffer_SizeFromFormat`, however an exporter may know
+ using :c:func:`PyBuffer_SizeFromFormat`, however an exporter may know
this information without parsing the format string and it is necessary
to know the itemsize for proper interpretation of striding. Therefore,
storing it is more convenient and faster.
- .. cmember:: void *internal
+ .. c:member:: void *internal
This is for use internally by the exporting object. For example, this
might be re-cast as an integer by the exporter and used to store flags
@@ -158,32 +158,32 @@ Buffer-related functions
========================
-.. cfunction:: int PyObject_CheckBuffer(PyObject *obj)
+.. c:function:: int PyObject_CheckBuffer(PyObject *obj)
Return 1 if *obj* supports the buffer interface otherwise 0. When 1 is
- returned, it doesn't guarantee that :cfunc:`PyObject_GetBuffer` will
+ returned, it doesn't guarantee that :c:func:`PyObject_GetBuffer` will
succeed.
-.. cfunction:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
+.. c:function:: int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
Export a view over some internal data from the target object *obj*.
*obj* must not be NULL, and *view* must point to an existing
- :ctype:`Py_buffer` structure allocated by the caller (most uses of
+ :c:type:`Py_buffer` structure allocated by the caller (most uses of
this function will simply declare a local variable of type
- :ctype:`Py_buffer`). The *flags* argument is a bit field indicating
+ :c:type:`Py_buffer`). The *flags* argument is a bit field indicating
what kind of buffer is requested. The buffer interface allows
for complicated memory layout possibilities; however, some callers
won't want to handle all the complexity and instead request a simple
- view of the target object (using :cmacro:`PyBUF_SIMPLE` for a read-only
- view and :cmacro:`PyBUF_WRITABLE` for a read-write view).
+ view of the target object (using :c:macro:`PyBUF_SIMPLE` for a read-only
+ view and :c:macro:`PyBUF_WRITABLE` for a read-write view).
Some exporters may not be able to share memory in every possible way and
may need to raise errors to signal to some consumers that something is
just not possible. These errors should be a :exc:`BufferError` unless
there is another error that is actually causing the problem. The
exporter can use flags information to simplify how much of the
- :cdata:`Py_buffer` structure is filled in with non-default values and/or
+ :c:data:`Py_buffer` structure is filled in with non-default values and/or
raise an error if the object can't support a simpler view of its memory.
On success, 0 is returned and the *view* structure is filled with useful
@@ -192,7 +192,7 @@ Buffer-related functions
The following are the possible values to the *flags* arguments.
- .. cmacro:: PyBUF_SIMPLE
+ .. c:macro:: PyBUF_SIMPLE
This is the default flag. The returned buffer exposes a read-only
memory area. The format of data is assumed to be raw unsigned bytes,
@@ -200,45 +200,45 @@ Buffer-related functions
constant. It never needs to be '|'d to the others. The exporter will
raise an error if it cannot provide such a contiguous buffer of bytes.
- .. cmacro:: PyBUF_WRITABLE
+ .. c:macro:: PyBUF_WRITABLE
- Like :cmacro:`PyBUF_SIMPLE`, but the returned buffer is writable. If
+ Like :c:macro:`PyBUF_SIMPLE`, but the returned buffer is writable. If
the exporter doesn't support writable buffers, an error is raised.
- .. cmacro:: PyBUF_STRIDES
+ .. c:macro:: PyBUF_STRIDES
- This implies :cmacro:`PyBUF_ND`. The returned buffer must provide
+ This implies :c:macro:`PyBUF_ND`. The returned buffer must provide
strides information (i.e. the strides cannot be NULL). This would be
used when the consumer can handle strided, discontiguous arrays.
Handling strides automatically assumes you can handle shape. The
exporter can raise an error if a strided representation of the data is
not possible (i.e. without the suboffsets).
- .. cmacro:: PyBUF_ND
+ .. c:macro:: PyBUF_ND
The returned buffer must provide shape information. The memory will be
assumed C-style contiguous (last dimension varies the fastest). The
exporter may raise an error if it cannot provide this kind of
contiguous buffer. If this is not given then shape will be *NULL*.
- .. cmacro:: PyBUF_C_CONTIGUOUS
+ .. c:macro:: PyBUF_C_CONTIGUOUS
PyBUF_F_CONTIGUOUS
PyBUF_ANY_CONTIGUOUS
These flags indicate that the contiguity returned buffer must be
respectively, C-contiguous (last dimension varies the fastest), Fortran
contiguous (first dimension varies the fastest) or either one. All of
- these flags imply :cmacro:`PyBUF_STRIDES` and guarantee that the
+ these flags imply :c:macro:`PyBUF_STRIDES` and guarantee that the
strides buffer info structure will be filled in correctly.
- .. cmacro:: PyBUF_INDIRECT
+ .. c:macro:: PyBUF_INDIRECT
This flag indicates the returned buffer must have suboffsets
information (which can be NULL if no suboffsets are needed). This can
be used when the consumer can handle indirect array referencing implied
- by these suboffsets. This implies :cmacro:`PyBUF_STRIDES`.
+ by these suboffsets. This implies :c:macro:`PyBUF_STRIDES`.
- .. cmacro:: PyBUF_FORMAT
+ .. c:macro:: PyBUF_FORMAT
The returned buffer must have true format information if this flag is
provided. This would be used when the consumer is going to be checking
@@ -247,54 +247,54 @@ Buffer-related functions
explicitly requested then the format must be returned as *NULL* (which
means ``'B'``, or unsigned bytes).
- .. cmacro:: PyBUF_STRIDED
+ .. c:macro:: PyBUF_STRIDED
This is equivalent to ``(PyBUF_STRIDES | PyBUF_WRITABLE)``.
- .. cmacro:: PyBUF_STRIDED_RO
+ .. c:macro:: PyBUF_STRIDED_RO
This is equivalent to ``(PyBUF_STRIDES)``.
- .. cmacro:: PyBUF_RECORDS
+ .. c:macro:: PyBUF_RECORDS
This is equivalent to ``(PyBUF_STRIDES | PyBUF_FORMAT |
PyBUF_WRITABLE)``.
- .. cmacro:: PyBUF_RECORDS_RO
+ .. c:macro:: PyBUF_RECORDS_RO
This is equivalent to ``(PyBUF_STRIDES | PyBUF_FORMAT)``.
- .. cmacro:: PyBUF_FULL
+ .. c:macro:: PyBUF_FULL
This is equivalent to ``(PyBUF_INDIRECT | PyBUF_FORMAT |
PyBUF_WRITABLE)``.
- .. cmacro:: PyBUF_FULL_RO
+ .. c:macro:: PyBUF_FULL_RO
This is equivalent to ``(PyBUF_INDIRECT | PyBUF_FORMAT)``.
- .. cmacro:: PyBUF_CONTIG
+ .. c:macro:: PyBUF_CONTIG
This is equivalent to ``(PyBUF_ND | PyBUF_WRITABLE)``.
- .. cmacro:: PyBUF_CONTIG_RO
+ .. c:macro:: PyBUF_CONTIG_RO
This is equivalent to ``(PyBUF_ND)``.
-.. cfunction:: void PyBuffer_Release(Py_buffer *view)
+.. c:function:: void PyBuffer_Release(Py_buffer *view)
Release the buffer *view*. This should be called when the buffer is no
longer being used as it may free memory from it.
-.. cfunction:: Py_ssize_t PyBuffer_SizeFromFormat(const char *)
+.. c:function:: Py_ssize_t PyBuffer_SizeFromFormat(const char *)
- Return the implied :cdata:`~Py_buffer.itemsize` from the struct-stype
- :cdata:`~Py_buffer.format`.
+ Return the implied :c:data:`~Py_buffer.itemsize` from the struct-stype
+ :c:data:`~Py_buffer.format`.
-.. cfunction:: int PyObject_CopyToObject(PyObject *obj, void *buf, Py_ssize_t len, char fortran)
+.. c:function:: int PyObject_CopyToObject(PyObject *obj, void *buf, Py_ssize_t len, char fortran)
Copy *len* bytes of data pointed to by the contiguous chunk of memory
pointed to by *buf* into the buffer exported by obj. The buffer must of
@@ -308,21 +308,21 @@ Buffer-related functions
matter and the copy will be made in whatever way is more efficient.
-.. cfunction:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran)
+.. c:function:: int PyBuffer_IsContiguous(Py_buffer *view, char fortran)
Return 1 if the memory defined by the *view* is C-style (*fortran* is
``'C'``) or Fortran-style (*fortran* is ``'F'``) contiguous or either one
(*fortran* is ``'A'``). Return 0 otherwise.
-.. cfunction:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran)
+.. c:function:: void PyBuffer_FillContiguousStrides(int ndim, Py_ssize_t *shape, Py_ssize_t *strides, Py_ssize_t itemsize, char fortran)
Fill the *strides* array with byte-strides of a contiguous (C-style if
*fortran* is ``'C'`` or Fortran-style if *fortran* is ``'F'`` array of the
given shape with the given number of bytes per element.
-.. cfunction:: int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int infoflags)
+.. c:function:: int PyBuffer_FillInfo(Py_buffer *view, PyObject *obj, void *buf, Py_ssize_t len, int readonly, int infoflags)
Fill in a buffer-info structure, *view*, correctly for an exporter that can
only share a contiguous chunk of memory of "unsigned bytes" of the given