blob: af5b5e358ab579949000a1ee6a9103b65476283b [file] [log] [blame]
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +00001.. highlightlang:: c
2
3.. _bytearrayobjects:
4
5Byte Array Objects
6------------------
7
8.. index:: object: bytearray
9
Georg Brandl457501b2008-05-29 07:18:17 +000010.. versionadded:: 2.6
11
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000012
13.. ctype:: PyByteArrayObject
14
Georg Brandl457501b2008-05-29 07:18:17 +000015 This subtype of :ctype:`PyObject` represents a Python bytearray object.
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000016
17
18.. cvar:: PyTypeObject PyByteArray_Type
19
20 This instance of :ctype:`PyTypeObject` represents the Python bytearray type;
21 it is the same object as ``bytearray`` in the Python layer.
22
23
24.. cfunction:: int PyByteArray_Check(PyObject *o)
25
26 Return true if the object *o* is a bytearray object or an instance of a
27 subtype of the bytearray type.
28
29
30.. cfunction:: int PyByteArray_CheckExact(PyObject *o)
31
32 Return true if the object *o* is a bytearray object, but not an instance of a
33 subtype of the bytearray type.
34
35
36.. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o)
37
38 Return a new bytearray object from any object, *o*, that implements the
39 buffer protocol.
40
Georg Brandl457501b2008-05-29 07:18:17 +000041 .. XXX expand about the buffer protocol, at least somewhere
42
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000043
44.. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
45
Benjamin Peterson31694ae2008-05-30 20:44:39 +000046 Create a new bytearray object from *string* and its length, *len*. On
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000047 failure, *NULL* is returned.
48
49
50.. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
51
52 Return the size of *bytearray* after checking for a *NULL* pointer.
53
54
55.. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
56
57 Macro version of :cfunc:`PyByteArray_Size` that doesn't do pointer checking.
58
59
60.. cfunction:: char* PyByteArray_AsString(PyObject *bytearray)
61
62 Return the contents of *bytearray* as a char array after checking for a
63 *NULL* pointer.
64
65
66.. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray)
67
68 Macro version of :cfunc:`PyByteArray_AsString` that doesn't check pointers.
69
70
71.. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
72
73 Concat bytearrays *a* and *b* and return a new bytearray with the result.
74
75
76.. cfunction:: PyObject* PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
77
78 Resize the internal buffer of *bytearray* to *len*.