Home | History | Annotate | Download | only in c-api
      1 .. highlightlang:: c
      2 
      3 .. _bytearrayobjects:
      4 
      5 Byte Array Objects
      6 ------------------
      7 
      8 .. index:: object: bytearray
      9 
     10 .. versionadded:: 2.6
     11 
     12 
     13 .. c:type:: PyByteArrayObject
     14 
     15    This subtype of :c:type:`PyObject` represents a Python bytearray object.
     16 
     17 
     18 .. c:var:: PyTypeObject PyByteArray_Type
     19 
     20    This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
     21    it is the same object as ``bytearray`` in the Python layer.
     22 
     23 Type check macros
     24 ^^^^^^^^^^^^^^^^^
     25 
     26 .. c:function:: int PyByteArray_Check(PyObject *o)
     27 
     28    Return true if the object *o* is a bytearray object or an instance of a
     29    subtype of the bytearray type.
     30 
     31 
     32 .. c:function:: int PyByteArray_CheckExact(PyObject *o)
     33 
     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 
     38 Direct API functions
     39 ^^^^^^^^^^^^^^^^^^^^
     40 
     41 .. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
     42 
     43    Return a new bytearray object from any object, *o*, that implements the
     44    buffer protocol.
     45 
     46    .. XXX expand about the buffer protocol, at least somewhere
     47 
     48 
     49 .. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
     50 
     51    Create a new bytearray object from *string* and its length, *len*.  On
     52    failure, *NULL* is returned.
     53 
     54 
     55 .. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
     56 
     57    Concat bytearrays *a* and *b* and return a new bytearray with the result.
     58 
     59 
     60 .. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
     61 
     62    Return the size of *bytearray* after checking for a *NULL* pointer.
     63 
     64 
     65 .. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
     66 
     67    Return the contents of *bytearray* as a char array after checking for a
     68    *NULL* pointer.
     69 
     70 
     71 .. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
     72 
     73    Resize the internal buffer of *bytearray* to *len*.
     74 
     75 Macros
     76 ^^^^^^
     77 
     78 These macros trade safety for speed and they don't check pointers.
     79 
     80 .. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
     81 
     82    Macro version of :c:func:`PyByteArray_AsString`.
     83 
     84 
     85 .. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
     86 
     87    Macro version of :c:func:`PyByteArray_Size`.
     88