• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. highlight:: c
2
3.. _bytearrayobjects:
4
5Byte Array Objects
6------------------
7
8.. index:: 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   .. XXX expand about the buffer protocol, at least somewhere
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*.  On
51   failure, ``NULL`` is returned.
52
53
54.. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
55
56   Concat bytearrays *a* and *b* and return a new bytearray with the result.
57
58
59.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
60
61   Return the size of *bytearray* after checking for a ``NULL`` pointer.
62
63
64.. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
65
66   Return the contents of *bytearray* as a char array after checking for a
67   ``NULL`` pointer.  The returned array always has an extra
68   null byte appended.
69
70
71.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
72
73   Resize the internal buffer of *bytearray* to *len*.
74
75Macros
76^^^^^^
77
78These macros trade safety for speed and they don't check pointers.
79
80.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
81
82   Macro version of :c:func:`PyByteArray_AsString`.
83
84
85.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
86
87   Macro version of :c:func:`PyByteArray_Size`.
88