blob: a60509176f1ddedb3dde38049c19dcd446152b0a [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
Ezio Melotti4b017bb2009-09-20 07:10:39 +000023Type check macros
24^^^^^^^^^^^^^^^^^
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000025
26.. cfunction:: int PyByteArray_Check(PyObject *o)
27
28 Return true if the object *o* is a bytearray object or an instance of a
29 subtype of the bytearray type.
30
31
32.. cfunction:: int PyByteArray_CheckExact(PyObject *o)
33
34 Return true if the object *o* is a bytearray object, but not an instance of a
35 subtype of the bytearray type.
36
37
Ezio Melotti4b017bb2009-09-20 07:10:39 +000038Direct API functions
39^^^^^^^^^^^^^^^^^^^^
40
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000041.. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o)
42
43 Return a new bytearray object from any object, *o*, that implements the
44 buffer protocol.
45
Georg Brandl457501b2008-05-29 07:18:17 +000046 .. XXX expand about the buffer protocol, at least somewhere
47
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000048
49.. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
50
Benjamin Peterson31694ae2008-05-30 20:44:39 +000051 Create a new bytearray object from *string* and its length, *len*. On
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000052 failure, *NULL* is returned.
53
54
Ezio Melotti4b017bb2009-09-20 07:10:39 +000055.. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
56
57 Concat bytearrays *a* and *b* and return a new bytearray with the result.
58
59
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000060.. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
61
62 Return the size of *bytearray* after checking for a *NULL* pointer.
63
64
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000065.. cfunction:: char* PyByteArray_AsString(PyObject *bytearray)
66
67 Return the contents of *bytearray* as a char array after checking for a
68 *NULL* pointer.
69
70
Ezio Melotti4b017bb2009-09-20 07:10:39 +000071.. cfunction:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000072
73 Resize the internal buffer of *bytearray* to *len*.
Ezio Melotti4b017bb2009-09-20 07:10:39 +000074
75Macros
76^^^^^^
77
78These macros trade safety for speed and they don't check pointers.
79
80.. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray)
81
82 Macro version of :cfunc:`PyByteArray_AsString`.
83
84
85.. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
86
87 Macro version of :cfunc:`PyByteArray_Size`.