Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 1 | .. highlightlang:: c |
| 2 | |
| 3 | .. _bytearrayobjects: |
| 4 | |
| 5 | Byte Array Objects |
| 6 | ------------------ |
| 7 | |
| 8 | .. index:: object: bytearray |
| 9 | |
| 10 | |
| 11 | .. ctype:: PyByteArrayObject |
| 12 | |
Georg Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame^] | 13 | This subtype of :ctype:`PyObject` represents a Python bytearray object. |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 14 | |
| 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 | |
| 21 | |
| 22 | .. cfunction:: int PyByteArray_Check(PyObject *o) |
| 23 | |
| 24 | Return true if the object *o* is a bytearray object or an instance of a |
| 25 | subtype of the bytearray type. |
| 26 | |
| 27 | |
| 28 | .. cfunction:: int PyByteArray_CheckExact(PyObject *o) |
| 29 | |
| 30 | Return true if the object *o* is a bytearray object, but not an instance of a |
| 31 | subtype of the bytearray type. |
| 32 | |
| 33 | |
| 34 | .. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o) |
| 35 | |
| 36 | Return a new bytearray object from any object, *o*, that implements the |
| 37 | buffer protocol. |
| 38 | |
Georg Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame^] | 39 | .. XXX expand about the buffer protocol, at least somewhere |
| 40 | |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 41 | |
| 42 | .. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len) |
| 43 | |
Georg Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame^] | 44 | Create a new bytearray object from *string* and its length, *len*. On |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 45 | failure, *NULL* is returned. |
| 46 | |
| 47 | |
| 48 | .. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray) |
| 49 | |
| 50 | Return the size of *bytearray* after checking for a *NULL* pointer. |
| 51 | |
| 52 | |
| 53 | .. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray) |
| 54 | |
| 55 | Macro version of :cfunc:`PyByteArray_Size` that doesn't do pointer checking. |
| 56 | |
| 57 | |
| 58 | .. cfunction:: char* PyByteArray_AsString(PyObject *bytearray) |
| 59 | |
| 60 | Return the contents of *bytearray* as a char array after checking for a |
| 61 | *NULL* pointer. |
| 62 | |
| 63 | |
| 64 | .. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray) |
| 65 | |
| 66 | Macro version of :cfunc:`PyByteArray_AsString` that doesn't check pointers. |
| 67 | |
| 68 | |
| 69 | .. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b) |
| 70 | |
| 71 | Concat bytearrays *a* and *b* and return a new bytearray with the result. |
| 72 | |
| 73 | |
| 74 | .. cfunction:: PyObject* PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) |
| 75 | |
| 76 | Resize the internal buffer of *bytearray* to *len*. |