bytearray オブジェクト

type PyByteArrayObject

この PyObject のサブタイプは Python の bytearray オブジェクトを表します。

PyTypeObject PyByteArray_Type
次に属します: Stable ABI.

この PyTypeObject のインスタンスは、 Python bytearray 型を示します。 Python レイヤでの bytearray と同じオブジェクトです。

型チェックマクロ

int PyByteArray_Check(PyObject *o)

オブジェクト o が bytearray オブジェクトか bytearray 型のサブタイプのインスタンスである場合に真を返します。この関数は常に成功します。

int PyByteArray_CheckExact(PyObject *o)

オブジェクト o が bytearray オブジェクトだが bytearray 型のサブタイプのインスタンスでない場合に真を返します。この関数は常に成功します。

ダイレクト API 関数

PyObject *PyByteArray_FromObject(PyObject *o)
戻り値: 新しい参照。 次に属します: Stable ABI. Thread safety: Safe for concurrent use on the same object.

buffer protocol を実装した任意のオブジェクト o から、新しいbytearrayオブジェクトを作成し、返します。

On failure, return NULL with 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)
戻り値: 新しい参照。 次に属します: Stable ABI. Thread safety: Atomic.

Create a new bytearray object from string and its length, len.

On failure, return NULL with an exception set.

PyObject *PyByteArray_Concat(PyObject *a, PyObject *b)
戻り値: 新しい参照。 次に属します: Stable ABI. Thread safety: Safe for concurrent use on the same object.

bytearray ab を連結した結果を新しい bytearray として返します。

On failure, return NULL with 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)
次に属します: Stable ABI. Thread safety: Atomic.

NULL ポインタチェックの後に bytearray のサイズを返します。

char *PyByteArray_AsString(PyObject *bytearray)
次に属します: Stable ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

NULL ポインタチェックの後に 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)
次に属します: Stable ABI.

Resize the internal buffer of bytearray to len. Failure is a -1 return 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.

PyByteArray_AsString() に似ていますが、エラーチェックを行いません。

注釈

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.

PyByteArray_Size() に似ていますが、エラーチェックを行いません。