Debian Codegraph @

Doc/c-api/bytearray.rst

raw
1 .. highlight:: c
2
3 .. _bytearrayobjects:
4
5 Byte 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
22 Type 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
37 Direct 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 On failure, return ``NULL`` with an exception set.
46
47
48 .. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
49
50 Create a new bytearray object from *string* and its length, *len*.
51
52 On failure, return ``NULL`` with an exception set.
53
54
55 .. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
56
57 Concat bytearrays *a* and *b* and return a new bytearray with the result.
58
59 On failure, return ``NULL`` with an exception set.
60
61
62 .. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
63
64 Return the size of *bytearray* after checking for a ``NULL`` pointer.
65
66
67 .. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
68
69 Return the contents of *bytearray* as a char array after checking for a
70 ``NULL`` pointer. The returned array always has an extra
71 null byte appended.
72
73
74 .. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
75
76 Resize the internal buffer of *bytearray* to *len*.
77
78 Macros
79 ^^^^^^
80
81 These macros trade safety for speed and they don't check pointers.
82
83 .. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
84
85 Similar to :c:func:`PyByteArray_AsString`, but without error checking.
86
87
88 .. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
89
90 Similar to :c:func:`PyByteArray_Size`, but without error checking.