Byte Array Objects

typePyByteArrayObject

This subtype ofPyObject represents a Python bytearray object.

PyTypeObjectPyByteArray_Type
Part of theStable ABI.

This instance ofPyTypeObject represents the Python bytearray type;it is the same object asbytearray in the Python layer.

Type check macros

intPyByteArray_Check(PyObject*o)

Return true if the objecto is a bytearray object or an instance of asubtype of the bytearray type. This function always succeeds.

intPyByteArray_CheckExact(PyObject*o)

Return true if the objecto is a bytearray object, but not an instance of asubtype of the bytearray type. This function always succeeds.

Direct API functions

PyObject*PyByteArray_FromObject(PyObject*o)
Return value: New reference. Part of theStable ABI.

Return a new bytearray object from any object,o, that implements thebuffer protocol.

On failure, returnNULL with an exception set.

PyObject*PyByteArray_FromStringAndSize(constchar*string,Py_ssize_tlen)
Return value: New reference. Part of theStable ABI.

Create a new bytearray object fromstring and its length,len.

On failure, returnNULL with an exception set.

PyObject*PyByteArray_Concat(PyObject*a,PyObject*b)
Return value: New reference. Part of theStable ABI.

Concat bytearraysa andb and return a new bytearray with the result.

On failure, returnNULL with an exception set.

Py_ssize_tPyByteArray_Size(PyObject*bytearray)
Part of theStable ABI.

Return the size ofbytearray after checking for aNULL pointer.

char*PyByteArray_AsString(PyObject*bytearray)
Part of theStable ABI.

Return the contents ofbytearray as a char array after checking for aNULL pointer. The returned array always has an extranull byte appended.

intPyByteArray_Resize(PyObject*bytearray,Py_ssize_tlen)
Part of theStable ABI.

Resize the internal buffer ofbytearray tolen.

Macros

These macros trade safety for speed and they don’t check pointers.

char*PyByteArray_AS_STRING(PyObject*bytearray)

Similar toPyByteArray_AsString(), but without error checking.

Py_ssize_tPyByteArray_GET_SIZE(PyObject*bytearray)

Similar toPyByteArray_Size(), but without error checking.