1 # Legacy Python 2 buffer interface.
3 # These functions are no longer available in Python 3, use the new
4 # buffer interface instead.
6 cdef extern from "Python.h":
9 # This constant may be passed as the size parameter to
10 # PyBuffer_FromObject() or PyBuffer_FromReadWriteObject(). It
11 # indicates that the new PyBufferObject should refer to base object
12 # from the specified offset to the end of its exported
13 # buffer. Using this enables the caller to avoid querying the base
14 # object for its length.
16 bint PyBuffer_Check(object p)
17 # Return true if the argument has type PyBuffer_Type.
19 object PyBuffer_FromObject(object base, Py_ssize_t offset, Py_ssize_t size)
20 # Return value: New reference.
22 # Return a new read-only buffer object. This raises TypeError if
23 # base doesn't support the read-only buffer protocol or doesn't
24 # provide exactly one buffer segment, or it raises ValueError if
25 # offset is less than zero. The buffer will hold a reference to the
26 # base object, and the buffer's contents will refer to the base
27 # object's buffer interface, starting as position offset and
28 # extending for size bytes. If size is Py_END_OF_BUFFER, then the
29 # new buffer's contents extend to the length of the base object's
30 # exported buffer data.
32 object PyBuffer_FromReadWriteObject(object base, Py_ssize_t offset, Py_ssize_t size)
33 # Return value: New reference.
35 # Return a new writable buffer object. Parameters and exceptions
36 # are similar to those for PyBuffer_FromObject(). If the base
37 # object does not export the writeable buffer protocol, then
38 # TypeError is raised.
40 object PyBuffer_FromMemory(void *ptr, Py_ssize_t size)
41 # Return value: New reference.
43 # Return a new read-only buffer object that reads from a specified
44 # location in memory, with a specified size. The caller is
45 # responsible for ensuring that the memory buffer, passed in as
46 # ptr, is not deallocated while the returned buffer object
47 # exists. Raises ValueError if size is less than zero. Note that
48 # Py_END_OF_BUFFER may not be passed for the size parameter;
49 # ValueError will be raised in that case.
51 object PyBuffer_FromReadWriteMemory(void *ptr, Py_ssize_t size)
52 # Return value: New reference.
54 # Similar to PyBuffer_FromMemory(), but the returned buffer is
57 object PyBuffer_New(Py_ssize_t size)
58 # Return value: New reference.
60 # Return a new writable buffer object that maintains its own memory
61 # buffer of size bytes. ValueError is returned if size is not zero
62 # or positive. Note that the memory buffer (as returned by
63 # PyObject_AsWriteBuffer()) is not specifically aligned.