blob: 858c8db1c8a9f5064ad78d1caff65e63e80549ff [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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010013.. c:type:: PyByteArrayObject
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000014
Sandro Tosi98ed08f2012-01-14 16:42:02 +010015 This subtype of :c:type:`PyObject` represents a Python bytearray object.
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000016
17
Sandro Tosi98ed08f2012-01-14 16:42:02 +010018.. c:var:: PyTypeObject PyByteArray_Type
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000019
Sandro Tosi98ed08f2012-01-14 16:42:02 +010020 This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000021 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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010026.. c:function:: int PyByteArray_Check(PyObject *o)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000027
28 Return true if the object *o* is a bytearray object or an instance of a
29 subtype of the bytearray type.
30
31
Sandro Tosi98ed08f2012-01-14 16:42:02 +010032.. c:function:: int PyByteArray_CheckExact(PyObject *o)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000033
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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010041.. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000042
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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010049.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000050
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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010055.. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
Ezio Melotti4b017bb2009-09-20 07:10:39 +000056
57 Concat bytearrays *a* and *b* and return a new bytearray with the result.
58
59
Sandro Tosi98ed08f2012-01-14 16:42:02 +010060.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000061
62 Return the size of *bytearray* after checking for a *NULL* pointer.
63
64
Sandro Tosi98ed08f2012-01-14 16:42:02 +010065.. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
Benjamin Peterson2b4b5ac2008-05-26 15:54:26 +000066
67 Return the contents of *bytearray* as a char array after checking for a
68 *NULL* pointer.
69
70
Sandro Tosi98ed08f2012-01-14 16:42:02 +010071.. c:function:: 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
Sandro Tosi98ed08f2012-01-14 16:42:02 +010080.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
Ezio Melotti4b017bb2009-09-20 07:10:39 +000081
Sandro Tosi98ed08f2012-01-14 16:42:02 +010082 Macro version of :c:func:`PyByteArray_AsString`.
Ezio Melotti4b017bb2009-09-20 07:10:39 +000083
84
Sandro Tosi98ed08f2012-01-14 16:42:02 +010085.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
Ezio Melotti4b017bb2009-09-20 07:10:39 +000086
Sandro Tosi98ed08f2012-01-14 16:42:02 +010087 Macro version of :c:func:`PyByteArray_Size`.