blob: 61b29ff5d6e490011f1c2adb7e5345d18a5ee95b [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
Georg Brandl60203b42010-10-06 10:11:56 +000011.. c:type:: PyByteArrayObject
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000012
Georg Brandl60203b42010-10-06 10:11:56 +000013 This subtype of :c:type:`PyObject` represents a Python bytearray object.
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000014
15
Georg Brandl60203b42010-10-06 10:11:56 +000016.. c:var:: PyTypeObject PyByteArray_Type
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000017
Georg Brandl60203b42010-10-06 10:11:56 +000018 This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000019 it is the same object as ``bytearray`` in the Python layer.
20
Ezio Melottibb43a052009-09-20 07:19:57 +000021Type check macros
22^^^^^^^^^^^^^^^^^
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000023
Georg Brandl60203b42010-10-06 10:11:56 +000024.. c:function:: int PyByteArray_Check(PyObject *o)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000025
26 Return true if the object *o* is a bytearray object or an instance of a
27 subtype of the bytearray type.
28
29
Georg Brandl60203b42010-10-06 10:11:56 +000030.. c:function:: int PyByteArray_CheckExact(PyObject *o)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000031
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
Ezio Melottibb43a052009-09-20 07:19:57 +000036Direct API functions
37^^^^^^^^^^^^^^^^^^^^
38
Georg Brandl60203b42010-10-06 10:11:56 +000039.. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000040
41 Return a new bytearray object from any object, *o*, that implements the
42 buffer protocol.
43
Georg Brandlf08a9dd2008-06-10 16:57:31 +000044 .. XXX expand about the buffer protocol, at least somewhere
45
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000046
Georg Brandl60203b42010-10-06 10:11:56 +000047.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000048
Georg Brandlf08a9dd2008-06-10 16:57:31 +000049 Create a new bytearray object from *string* and its length, *len*. On
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000050 failure, *NULL* is returned.
51
52
Georg Brandl60203b42010-10-06 10:11:56 +000053.. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
Ezio Melottibb43a052009-09-20 07:19:57 +000054
55 Concat bytearrays *a* and *b* and return a new bytearray with the result.
56
57
Georg Brandl60203b42010-10-06 10:11:56 +000058.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000059
60 Return the size of *bytearray* after checking for a *NULL* pointer.
61
62
Georg Brandl60203b42010-10-06 10:11:56 +000063.. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000064
65 Return the contents of *bytearray* as a char array after checking for a
66 *NULL* pointer.
67
68
Georg Brandl60203b42010-10-06 10:11:56 +000069.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000070
71 Resize the internal buffer of *bytearray* to *len*.
Ezio Melottibb43a052009-09-20 07:19:57 +000072
73Macros
74^^^^^^
75
76These macros trade safety for speed and they don't check pointers.
77
Georg Brandl60203b42010-10-06 10:11:56 +000078.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
Ezio Melottibb43a052009-09-20 07:19:57 +000079
Georg Brandl60203b42010-10-06 10:11:56 +000080 Macro version of :c:func:`PyByteArray_AsString`.
Ezio Melottibb43a052009-09-20 07:19:57 +000081
82
Georg Brandl60203b42010-10-06 10:11:56 +000083.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
Ezio Melottibb43a052009-09-20 07:19:57 +000084
Georg Brandl60203b42010-10-06 10:11:56 +000085 Macro version of :c:func:`PyByteArray_Size`.