Об’єкти байтового масиву¶
-
PyTypeObject PyByteArray_Type¶
- Part of the Stable ABI.
Цей екземпляр
PyTypeObjectпредставляє тип Python bytearray; це той самий об’єкт, що йbytearrayна рівні Python.
Макроси перевірки типу¶
Прямі функції API¶
-
PyObject *PyByteArray_FromObject(PyObject *o)¶
- Return value: New reference. Part of the Stable ABI. Thread safety: Safe for concurrent use on the same object.
Повертає новий об’єкт bytearray з будь-якого об’єкта, o, який реалізує протокол буфера.
On failure, return
NULLwith an exception set.Примітка
If the object implements the buffer protocol, then the buffer must not be mutated while the bytearray object is being created.
-
PyObject *PyByteArray_FromStringAndSize(const char *string, Py_ssize_t len)¶
- Return value: New reference. Part of the Stable ABI. Thread safety: Atomic.
Create a new bytearray object from string and its length, len.
On failure, return
NULLwith an exception set.
-
PyObject *PyByteArray_Concat(PyObject *a, PyObject *b)¶
- Return value: New reference. Part of the Stable ABI. Thread safety: Safe for concurrent use on the same object.
Об’єднайте масиви байтів a і b та поверніть новий масив байтів із результатом.
On failure, return
NULLwith an exception set.Примітка
If the object implements the buffer protocol, then the buffer must not be mutated while the bytearray object is being created.
-
Py_ssize_t PyByteArray_Size(PyObject *bytearray)¶
- Part of the Stable ABI. Thread safety: Atomic.
Повертає розмір bytearray після перевірки вказівника
NULL.
-
char *PyByteArray_AsString(PyObject *bytearray)¶
- Part of the Stable ABI. Thread safety: Safe to call from multiple threads with external synchronization only.
Повертає вміст bytearray як масив char після перевірки вказівника
NULL. Повернений масив завжди має додатковий нульовий байт.Примітка
It is not thread-safe to mutate the bytearray object while using the returned char array.
-
int PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)¶
- Part of the Stable ABI.
Resize the internal buffer of bytearray to len. Failure is a
-1return with an exception set.Змінено в версії 3.14: A negative len will now result in an exception being set and -1 returned.
Макроси¶
Ці макроси замінюють безпеку на швидкість, і вони не перевіряють покажчики.
-
char *PyByteArray_AS_STRING(PyObject *bytearray)¶
- Thread safety: Safe to call from multiple threads with external synchronization only.
Similar to
PyByteArray_AsString(), but without error checking.Примітка
It is not thread-safe to mutate the bytearray object while using the returned char array.
-
Py_ssize_t PyByteArray_GET_SIZE(PyObject *bytearray)¶
- Thread safety: Atomic.
Similar to
PyByteArray_Size(), but without error checking.