blob: 4bc545961b904d65d7fc8a397d4eff6e21cda9ca [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;
19 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
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
Ezio Melottibb43a052009-09-20 07:19:57 +000036Direct API functions
37^^^^^^^^^^^^^^^^^^^^
38
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000039.. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o)
40
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
47.. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
48
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
Ezio Melottibb43a052009-09-20 07:19:57 +000053.. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
54
55 Concat bytearrays *a* and *b* and return a new bytearray with the result.
56
57
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000058.. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
59
60 Return the size of *bytearray* after checking for a *NULL* pointer.
61
62
Benjamin Petersonfbeb6b62008-05-26 16:04:49 +000063.. cfunction:: char* PyByteArray_AsString(PyObject *bytearray)
64
65 Return the contents of *bytearray* as a char array after checking for a
66 *NULL* pointer.
67
68
Ezio Melottibb43a052009-09-20 07:19:57 +000069.. cfunction:: 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
78.. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray)
79
80 Macro version of :cfunc:`PyByteArray_AsString`.
81
82
83.. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
84
85 Macro version of :cfunc:`PyByteArray_Size`.