#6881 - fixed wrong return type; improved the formatting
[python.git] / Doc / c-api / bytearray.rst
bloba60509176f1ddedb3dde38049c19dcd446152b0a
1 .. highlightlang:: c
3 .. _bytearrayobjects:
5 Byte Array Objects
6 ------------------
8 .. index:: object: bytearray
10 .. versionadded:: 2.6
13 .. ctype:: PyByteArrayObject
15    This subtype of :ctype:`PyObject` represents a Python bytearray object.
18 .. cvar:: PyTypeObject PyByteArray_Type
20    This instance of :ctype:`PyTypeObject` represents the Python bytearray type;
21    it is the same object as ``bytearray`` in the Python layer.
23 Type check macros
24 ^^^^^^^^^^^^^^^^^
26 .. cfunction:: int PyByteArray_Check(PyObject *o)
28    Return true if the object *o* is a bytearray object or an instance of a
29    subtype of the bytearray type.
32 .. cfunction:: int PyByteArray_CheckExact(PyObject *o)
34    Return true if the object *o* is a bytearray object, but not an instance of a
35    subtype of the bytearray type.
38 Direct API functions
39 ^^^^^^^^^^^^^^^^^^^^
41 .. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o)
43    Return a new bytearray object from any object, *o*, that implements the
44    buffer protocol.
46    .. XXX expand about the buffer protocol, at least somewhere
49 .. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
51    Create a new bytearray object from *string* and its length, *len*.  On
52    failure, *NULL* is returned.
55 .. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
57    Concat bytearrays *a* and *b* and return a new bytearray with the result.
60 .. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
62    Return the size of *bytearray* after checking for a *NULL* pointer.
65 .. cfunction:: char* PyByteArray_AsString(PyObject *bytearray)
67    Return the contents of *bytearray* as a char array after checking for a
68    *NULL* pointer.
71 .. cfunction:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
73    Resize the internal buffer of *bytearray* to *len*.
75 Macros
76 ^^^^^^
78 These macros trade safety for speed and they don't check pointers.
80 .. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray)
82    Macro version of :cfunc:`PyByteArray_AsString`.
85 .. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
87    Macro version of :cfunc:`PyByteArray_Size`.