Gregory P. Smith | 1bd52d7 | 2008-06-01 22:57:47 +0000 | [diff] [blame] | 1 | /* ByteArray object interface */ |
Christian Heimes | 3497f94 | 2008-05-26 12:29:14 +0000 | [diff] [blame] | 2 | |
Gregory P. Smith | 1bd52d7 | 2008-06-01 22:57:47 +0000 | [diff] [blame] | 3 | #ifndef Py_BYTEARRAYOBJECT_H |
| 4 | #define Py_BYTEARRAYOBJECT_H |
Christian Heimes | 3497f94 | 2008-05-26 12:29:14 +0000 | [diff] [blame] | 5 | #ifdef __cplusplus |
| 6 | extern "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 */ |
| 22 | typedef struct { |
| 23 | PyObject_VAR_HEAD |
| 24 | /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */ |
| 25 | int ob_exports; /* how many buffer exports */ |
| 26 | Py_ssize_t ob_alloc; /* How many bytes allocated */ |
| 27 | char *ob_bytes; |
| 28 | } PyByteArrayObject; |
| 29 | |
| 30 | /* Type object */ |
| 31 | PyAPI_DATA(PyTypeObject) PyByteArray_Type; |
| 32 | PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type; |
| 33 | |
| 34 | /* Type check macros */ |
| 35 | #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type) |
| 36 | #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type) |
| 37 | |
| 38 | /* Direct API functions */ |
| 39 | PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *); |
| 40 | PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *); |
| 41 | PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t); |
| 42 | PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *); |
| 43 | PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *); |
| 44 | PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); |
| 45 | |
| 46 | /* Macros, trading safety for speed */ |
| 47 | #define PyByteArray_AS_STRING(self) (assert(PyByteArray_Check(self)),((PyByteArrayObject *)(self))->ob_bytes) |
| 48 | #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self)) |
| 49 | |
| 50 | #ifdef __cplusplus |
| 51 | } |
| 52 | #endif |
Gregory P. Smith | 1bd52d7 | 2008-06-01 22:57:47 +0000 | [diff] [blame] | 53 | #endif /* !Py_BYTEARRAYOBJECT_H */ |