Chris@87: /* ByteArray object interface */ Chris@87: Chris@87: #ifndef Py_BYTEARRAYOBJECT_H Chris@87: #define Py_BYTEARRAYOBJECT_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: #include Chris@87: Chris@87: /* Type PyByteArrayObject represents a mutable array of bytes. Chris@87: * The Python API is that of a sequence; Chris@87: * the bytes are mapped to ints in [0, 256). Chris@87: * Bytes are not characters; they may be used to encode characters. Chris@87: * The only way to go between bytes and str/unicode is via encoding Chris@87: * and decoding. Chris@87: * For the convenience of C programmers, the bytes type is considered Chris@87: * to contain a char pointer, not an unsigned char pointer. Chris@87: */ Chris@87: Chris@87: /* Object layout */ Chris@87: typedef struct { Chris@87: PyObject_VAR_HEAD Chris@87: /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */ Chris@87: int ob_exports; /* how many buffer exports */ Chris@87: Py_ssize_t ob_alloc; /* How many bytes allocated */ Chris@87: char *ob_bytes; Chris@87: } PyByteArrayObject; Chris@87: Chris@87: /* Type object */ Chris@87: PyAPI_DATA(PyTypeObject) PyByteArray_Type; Chris@87: PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type; Chris@87: Chris@87: /* Type check macros */ Chris@87: #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type) Chris@87: #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type) Chris@87: Chris@87: /* Direct API functions */ Chris@87: PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *); Chris@87: PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *); Chris@87: PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t); Chris@87: PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *); Chris@87: PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *); Chris@87: PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); Chris@87: Chris@87: /* Macros, trading safety for speed */ Chris@87: #define PyByteArray_AS_STRING(self) \ Chris@87: (assert(PyByteArray_Check(self)), \ Chris@87: Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string) Chris@87: #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self)) Chris@87: Chris@87: PyAPI_DATA(char) _PyByteArray_empty_string[]; Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_BYTEARRAYOBJECT_H */