blob: 5e11d8a57174df69cf29283604daddb1140611c3 [file] [log] [blame]
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +00001.. highlightlang:: c
2
3.. _bytearrayobjects:
4
5Byte Array Objects
6------------------
7
8.. index:: object: bytearray
9
10
11.. ctype:: PyByteArrayObject
12
Georg Brandlf08a9dd2008-06-10 16:57:31 +000013 This subtype of :ctype:`PyObject` represents a Python bytearray object.
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000014
15
16.. cvar:: PyTypeObject PyByteArray_Type
17
18 This instance of :ctype:`PyTypeObject` represents the Python bytearray type;
Georg Brandlab32fec2010-11-26 08:49:15 +000019 it is the same object as :class:`bytearray` in the Python layer.
20
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000021
Ezio Melottibef78d22009-09-20 07:22:00 +000022Type check macros
23^^^^^^^^^^^^^^^^^
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000024
25.. cfunction:: 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.
29
30
31.. cfunction:: 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.
35
36
Ezio Melottibef78d22009-09-20 07:22:00 +000037Direct API functions
38^^^^^^^^^^^^^^^^^^^^
39
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000040.. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o)
41
42 Return a new bytearray object from any object, *o*, that implements the
43 buffer protocol.
44
Georg Brandlf08a9dd2008-06-10 16:57:31 +000045 .. XXX expand about the buffer protocol, at least somewhere
46
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000047
48.. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
49
Georg Brandlf08a9dd2008-06-10 16:57:31 +000050 Create a new bytearray object from *string* and its length, *len*. On
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000051 failure, *NULL* is returned.
52
53
Ezio Melottibef78d22009-09-20 07:22:00 +000054.. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
55
56 Concat bytearrays *a* and *b* and return a new bytearray with the result.
57
58
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000059.. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
60
61 Return the size of *bytearray* after checking for a *NULL* pointer.
62
63
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000064.. cfunction:: char* PyByteArray_AsString(PyObject *bytearray)
65
66 Return the contents of *bytearray* as a char array after checking for a
67 *NULL* pointer.
68
69
Ezio Melottibef78d22009-09-20 07:22:00 +000070.. cfunction:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000071
72 Resize the internal buffer of *bytearray* to *len*.
Ezio Melottibef78d22009-09-20 07:22:00 +000073
74Macros
75^^^^^^
76
77These macros trade safety for speed and they don't check pointers.
78
79.. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray)
80
81 Macro version of :cfunc:`PyByteArray_AsString`.
82
83
84.. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
85
86 Macro version of :cfunc:`PyByteArray_Size`.