1.. highlight:: c
2
3.. _bytearrayobjects:
4
5Byte Array Objects
6------------------
7
8.. index:: pair: object; bytearray
9
10
11.. c:type:: PyByteArrayObject
12
13   This subtype of :c:type:`PyObject` represents a Python bytearray object.
14
15
16.. c:var:: PyTypeObject PyByteArray_Type
17
18   This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
19   it is the same object as :class:`bytearray` in the Python layer.
20
21
22Type check macros
23^^^^^^^^^^^^^^^^^
24
25.. c:function:: int PyByteArray_Check(PyObject *o)
26
27   Return true if the object *o* is a bytearray object or an instance of a
28   subtype of the bytearray type.  This function always succeeds.
29
30
31.. c:function:: int PyByteArray_CheckExact(PyObject *o)
32
33   Return true if the object *o* is a bytearray object, but not an instance of a
34   subtype of the bytearray type.  This function always succeeds.
35
36
37Direct API functions
38^^^^^^^^^^^^^^^^^^^^
39
40.. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
41
42   Return a new bytearray object from any object, *o*, that implements the
43   :ref:`buffer protocol <bufferobjects>`.
44
45
46.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
47
48   Create a new bytearray object from *string* and its length, *len*.  On
49   failure, ``NULL`` is returned.
50
51
52.. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
53
54   Concat bytearrays *a* and *b* and return a new bytearray with the result.
55
56
57.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
58
59   Return the size of *bytearray* after checking for a ``NULL`` pointer.
60
61
62.. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
63
64   Return the contents of *bytearray* as a char array after checking for a
65   ``NULL`` pointer.  The returned array always has an extra
66   null byte appended.
67
68
69.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
70
71   Resize the internal buffer of *bytearray* to *len*.
72
73Macros
74^^^^^^
75
76These macros trade safety for speed and they don't check pointers.
77
78.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
79
80   Similar to :c:func:`PyByteArray_AsString`, but without error checking.
81
82
83.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
84
85   Similar to :c:func:`PyByteArray_Size`, but without error checking.
86