바이트 배열 객체

type PyByteArrayObject

PyObject의 서브 형은 파이썬 bytearray 객체를 나타냅니다.

PyTypeObject PyByteArray_Type
Part of the 안정 ABI.

PyTypeObject 인스턴스는 파이썬 bytearray 형을 나타냅니다; 파이썬 계층의 bytearray와 같은 객체입니다.

형 검사 매크로

int PyByteArray_Check(PyObject *o)

객체 o가 bytearray 객체이거나 bytearray 형의 서브 형 인스턴스면 참을 반환합니다. 이 함수는 항상 성공합니다.

int PyByteArray_CheckExact(PyObject *o)

객체 o가 bytearray 객체이지만, bytearray 형의 서브 형 인스턴스는 아니면 참을 반환합니다. 이 함수는 항상 성공합니다.

직접 API 함수

PyObject *PyByteArray_FromObject(PyObject *o)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Safe for concurrent use on the same object.

버퍼 프로토콜을 구현하는 임의의 객체(o)로부터 써서 새로운 bytearray 객체를 돌려줍니다.

실패하면, NULL을 반환하고 예외를 설정합니다.

참고

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)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Atomic.

string과 그 길이(len)로 새로운 bytearray 객체를 만듭니다.

실패하면, NULL을 반환하고 예외를 설정합니다.

PyObject *PyByteArray_Concat(PyObject *a, PyObject *b)
반환값: 새 참조. Part of the 안정 ABI. Thread safety: Safe for concurrent use on the same object.

바이트 배열 ab를 이어붙여 새로운 bytearray로 반환합니다.

실패하면, NULL을 반환하고 예외를 설정합니다.

참고

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 안정 ABI. Thread safety: Atomic.

NULL 포인터를 확인한 후 bytearray의 크기를 반환합니다.

char *PyByteArray_AsString(PyObject *bytearray)
Part of the 안정 ABI. Thread safety: Safe to call from multiple threads with external synchronization only.

NULL 포인터를 확인한 후 bytearray의 내용을 char 배열로 반환합니다. 반환되는 배열에는 항상 여분의 널 바이트가 추가됩니다.

참고

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 안정 ABI.

bytearray의 내부 버퍼의 크기를 len으로 조정합니다. 실패 시 예외와 함께 -1이 반환됩니다.

버전 3.14에서 변경: 음수 len을 사용하면 예외가 발생하고 -1이 반환됩니다.

매크로

이 매크로는 속도를 위해 안전을 희생하며 포인터를 확인하지 않습니다.

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()와 유사하지만 에러를 검사하지 않습니다.