blob: eccd44c751790fcce6c7efe241e067d0ffdd99cb [file] [log] [blame]
Georg Brandl0c77a822008-06-10 16:37:50 +00001/* ByteArray object interface */
Christian Heimes2c9c7a52008-05-26 13:42:13 +00002
Georg Brandl0c77a822008-06-10 16:37:50 +00003#ifndef Py_BYTEARRAYOBJECT_H
4#define Py_BYTEARRAYOBJECT_H
Christian Heimes2c9c7a52008-05-26 13:42:13 +00005#ifdef __cplusplus
6extern "C" {
7#endif
8
9#include <stdarg.h>
10
11/* Type PyByteArrayObject represents a mutable array of bytes.
12 * The Python API is that of a sequence;
13 * the bytes are mapped to ints in [0, 256).
14 * Bytes are not characters; they may be used to encode characters.
15 * The only way to go between bytes and str/unicode is via encoding
16 * and decoding.
17 * For the convenience of C programmers, the bytes type is considered
18 * to contain a char pointer, not an unsigned char pointer.
19 */
20
21/* Object layout */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000022#ifndef Py_LIMITED_API
Christian Heimes2c9c7a52008-05-26 13:42:13 +000023typedef struct {
24 PyObject_VAR_HEAD
25 /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
26 int ob_exports; /* how many buffer exports */
27 Py_ssize_t ob_alloc; /* How many bytes allocated */
28 char *ob_bytes;
29} PyByteArrayObject;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000030#endif
Christian Heimes2c9c7a52008-05-26 13:42:13 +000031
32/* Type object */
33PyAPI_DATA(PyTypeObject) PyByteArray_Type;
34PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
35
36/* Type check macros */
37#define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)
38#define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)
39
40/* Direct API functions */
41PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);
42PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *);
43PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t);
44PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *);
45PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);
46PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
47
48/* Macros, trading safety for speed */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000049#ifndef Py_LIMITED_API
Antoine Pitroufc8d6f42010-01-17 12:38:54 +000050#define PyByteArray_AS_STRING(self) \
51 (assert(PyByteArray_Check(self)), \
52 Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string)
Christian Heimes2c9c7a52008-05-26 13:42:13 +000053#define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self))
54
Antoine Pitrou2ff627a2010-01-17 16:15:29 +000055PyAPI_DATA(char) _PyByteArray_empty_string[];
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000056#endif
Antoine Pitroufc8d6f42010-01-17 12:38:54 +000057
Christian Heimes2c9c7a52008-05-26 13:42:13 +000058#ifdef __cplusplus
59}
60#endif
Georg Brandl0c77a822008-06-10 16:37:50 +000061#endif /* !Py_BYTEARRAYOBJECT_H */