| 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 |  | 
| Ezio Melotti | bb43a05 | 2009-09-20 07:19:57 +0000 | [diff] [blame^] | 21 | Type check macros | 
|  | 22 | ^^^^^^^^^^^^^^^^^ | 
| Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 23 |  | 
|  | 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 Melotti | bb43a05 | 2009-09-20 07:19:57 +0000 | [diff] [blame^] | 36 | Direct API functions | 
|  | 37 | ^^^^^^^^^^^^^^^^^^^^ | 
|  | 38 |  | 
| Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 39 | .. 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 Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame] | 44 | .. XXX expand about the buffer protocol, at least somewhere | 
|  | 45 |  | 
| Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 46 |  | 
|  | 47 | .. cfunction:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len) | 
|  | 48 |  | 
| Georg Brandl | f08a9dd | 2008-06-10 16:57:31 +0000 | [diff] [blame] | 49 | Create a new bytearray object from *string* and its length, *len*.  On | 
| Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 50 | failure, *NULL* is returned. | 
|  | 51 |  | 
|  | 52 |  | 
| Ezio Melotti | bb43a05 | 2009-09-20 07:19:57 +0000 | [diff] [blame^] | 53 | .. 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 Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 58 | .. cfunction:: Py_ssize_t PyByteArray_Size(PyObject *bytearray) | 
|  | 59 |  | 
|  | 60 | Return the size of *bytearray* after checking for a *NULL* pointer. | 
|  | 61 |  | 
|  | 62 |  | 
| Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 63 | .. 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 Melotti | bb43a05 | 2009-09-20 07:19:57 +0000 | [diff] [blame^] | 69 | .. cfunction:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) | 
| Benjamin Peterson | fbeb6b6 | 2008-05-26 16:04:49 +0000 | [diff] [blame] | 70 |  | 
|  | 71 | Resize the internal buffer of *bytearray* to *len*. | 
| Ezio Melotti | bb43a05 | 2009-09-20 07:19:57 +0000 | [diff] [blame^] | 72 |  | 
|  | 73 | Macros | 
|  | 74 | ^^^^^^ | 
|  | 75 |  | 
|  | 76 | These 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`. |