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; |
Georg Brandl | ab32fec | 2010-11-26 08:49:15 +0000 | [diff] [blame] | 19 | it is the same object as :class:`bytearray` in the Python layer. |
| 20 | |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 21 | |
Ezio Melotti | bef78d2 | 2009-09-20 07:22:00 +0000 | [diff] [blame] | 22 | Type check macros |
| 23 | ^^^^^^^^^^^^^^^^^ |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 24 | |
| 25 | .. cfunction:: int PyByteArray_Check(PyObject *o) |
| 26 | |
| 27 | Return true if the object *o* is a bytearray object or an instance of a |
| 28 | subtype of the bytearray type. |
| 29 | |
| 30 | |
| 31 | .. cfunction:: int PyByteArray_CheckExact(PyObject *o) |
| 32 | |
| 33 | Return true if the object *o* is a bytearray object, but not an instance of a |
| 34 | subtype of the bytearray type. |
| 35 | |
| 36 | |
Ezio Melotti | bef78d2 | 2009-09-20 07:22:00 +0000 | [diff] [blame] | 37 | Direct API functions |
| 38 | ^^^^^^^^^^^^^^^^^^^^ |
| 39 | |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 40 | .. cfunction:: PyObject* PyByteArray_FromObject(PyObject *o) |
| 41 | |
| 42 | Return a new bytearray object from any object, *o*, that implements the |
| 43 | buffer protocol. |
| 44 | |
Georg Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame] | 45 | .. XXX expand about the buffer protocol, at least somewhere |
| 46 | |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 47 | |
| 48 | .. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len) |
| 49 | |
Georg Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame] | 50 | Create a new bytearray object from *string* and its length, *len*. On |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 51 | failure, *NULL* is returned. |
| 52 | |
| 53 | |
Ezio Melotti | bef78d2 | 2009-09-20 07:22:00 +0000 | [diff] [blame] | 54 | .. cfunction:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b) |
| 55 | |
| 56 | Concat bytearrays *a* and *b* and return a new bytearray with the result. |
| 57 | |
| 58 | |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 59 | .. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray) |
| 60 | |
| 61 | Return the size of *bytearray* after checking for a *NULL* pointer. |
| 62 | |
| 63 | |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 64 | .. cfunction:: char* PyByteArray_AsString(PyObject *bytearray) |
| 65 | |
| 66 | Return the contents of *bytearray* as a char array after checking for a |
| 67 | *NULL* pointer. |
| 68 | |
| 69 | |
Ezio Melotti | bef78d2 | 2009-09-20 07:22:00 +0000 | [diff] [blame] | 70 | .. cfunction:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) |
Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 71 | |
| 72 | Resize the internal buffer of *bytearray* to *len*. |
Ezio Melotti | bef78d2 | 2009-09-20 07:22:00 +0000 | [diff] [blame] | 73 | |
| 74 | Macros |
| 75 | ^^^^^^ |
| 76 | |
| 77 | These macros trade safety for speed and they don't check pointers. |
| 78 | |
| 79 | .. cfunction:: char* PyByteArray_AS_STRING(PyObject *bytearray) |
| 80 | |
| 81 | Macro version of :cfunc:`PyByteArray_AsString`. |
| 82 | |
| 83 | |
| 84 | .. cfunction:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray) |
| 85 | |
| 86 | Macro version of :cfunc:`PyByteArray_Size`. |