2019-05-17 06:55:34 -03:00
|
|
|
.. highlight:: c
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
.. _bytearrayobjects:
|
|
|
|
|
|
|
|
Byte Array Objects
|
|
|
|
------------------
|
|
|
|
|
2023-05-04 07:04:41 -03:00
|
|
|
.. index:: pair: object; bytearray
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:type:: PyByteArrayObject
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
This subtype of :c:type:`PyObject` represents a Python bytearray object.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:var:: PyTypeObject PyByteArray_Type
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
This instance of :c:type:`PyTypeObject` represents the Python bytearray type;
|
2010-10-17 07:59:41 -03:00
|
|
|
it is the same object as :class:`bytearray` in the Python layer.
|
|
|
|
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2009-09-20 04:19:57 -03:00
|
|
|
Type check macros
|
|
|
|
^^^^^^^^^^^^^^^^^
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: int PyByteArray_Check(PyObject *o)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
Return true if the object *o* is a bytearray object or an instance of a
|
2021-01-06 07:38:26 -04:00
|
|
|
subtype of the bytearray type. This function always succeeds.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: int PyByteArray_CheckExact(PyObject *o)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
Return true if the object *o* is a bytearray object, but not an instance of a
|
2021-01-06 07:38:26 -04:00
|
|
|
subtype of the bytearray type. This function always succeeds.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2009-09-20 04:19:57 -03:00
|
|
|
Direct API functions
|
|
|
|
^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyByteArray_FromObject(PyObject *o)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
Return a new bytearray object from any object, *o*, that implements the
|
2013-05-04 12:06:34 -03:00
|
|
|
:ref:`buffer protocol <bufferobjects>`.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2024-08-03 18:55:47 -03:00
|
|
|
On failure, return ``NULL`` with an exception set.
|
|
|
|
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2024-08-03 18:55:47 -03:00
|
|
|
Create a new bytearray object from *string* and its length, *len*.
|
|
|
|
|
|
|
|
On failure, return ``NULL`` with an exception set.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2009-09-20 04:19:57 -03:00
|
|
|
Concat bytearrays *a* and *b* and return a new bytearray with the result.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2024-08-03 18:55:47 -03:00
|
|
|
On failure, return ``NULL`` with an exception set.
|
|
|
|
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: Py_ssize_t PyByteArray_Size(PyObject *bytearray)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2019-10-30 07:03:20 -03:00
|
|
|
Return the size of *bytearray* after checking for a ``NULL`` pointer.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: char* PyByteArray_AsString(PyObject *bytearray)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
Return the contents of *bytearray* as a char array after checking for a
|
2019-10-30 07:03:20 -03:00
|
|
|
``NULL`` pointer. The returned array always has an extra
|
2015-05-13 21:31:53 -03:00
|
|
|
null byte appended.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2009-09-20 04:19:57 -03:00
|
|
|
Resize the internal buffer of *bytearray* to *len*.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2009-09-20 04:19:57 -03:00
|
|
|
Macros
|
|
|
|
^^^^^^
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2009-09-20 04:19:57 -03:00
|
|
|
These macros trade safety for speed and they don't check pointers.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: char* PyByteArray_AS_STRING(PyObject *bytearray)
|
2008-05-26 13:04:49 -03:00
|
|
|
|
2022-05-03 15:14:58 -03:00
|
|
|
Similar to :c:func:`PyByteArray_AsString`, but without error checking.
|
2008-05-26 13:04:49 -03:00
|
|
|
|
|
|
|
|
2010-10-06 07:11:56 -03:00
|
|
|
.. c:function:: Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)
|
2009-09-20 04:19:57 -03:00
|
|
|
|
2022-05-03 15:14:58 -03:00
|
|
|
Similar to :c:func:`PyByteArray_Size`, but without error checking.
|