Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 1 | /* ByteArray object interface */ |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 2 | |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 3 | #ifndef Py_BYTEARRAYOBJECT_H |
| 4 | #define Py_BYTEARRAYOBJECT_H |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +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 */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 22 | #ifndef Py_LIMITED_API |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 23 | typedef struct { |
| 24 | PyObject_VAR_HEAD |
Benjamin Peterson | 9185a5a | 2013-10-05 16:28:04 -0400 | [diff] [blame] | 25 | Py_ssize_t ob_alloc; /* How many bytes allocated in ob_bytes */ |
Antoine Pitrou | 5df8a8a | 2013-10-05 21:12:18 +0200 | [diff] [blame] | 26 | char *ob_bytes; /* Physical backing buffer */ |
| 27 | char *ob_start; /* Logical start inside ob_bytes */ |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 28 | /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */ |
Antoine Pitrou | 5df8a8a | 2013-10-05 21:12:18 +0200 | [diff] [blame] | 29 | int ob_exports; /* How many buffer exports */ |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 30 | } PyByteArrayObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 31 | #endif |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 32 | |
| 33 | /* Type object */ |
| 34 | PyAPI_DATA(PyTypeObject) PyByteArray_Type; |
| 35 | PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type; |
| 36 | |
| 37 | /* Type check macros */ |
| 38 | #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type) |
| 39 | #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type) |
| 40 | |
| 41 | /* Direct API functions */ |
| 42 | PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *); |
| 43 | PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *); |
| 44 | PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t); |
| 45 | PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *); |
| 46 | PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *); |
| 47 | PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t); |
| 48 | |
| 49 | /* Macros, trading safety for speed */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 50 | #ifndef Py_LIMITED_API |
Antoine Pitrou | fc8d6f4 | 2010-01-17 12:38:54 +0000 | [diff] [blame] | 51 | #define PyByteArray_AS_STRING(self) \ |
| 52 | (assert(PyByteArray_Check(self)), \ |
Antoine Pitrou | 5df8a8a | 2013-10-05 21:12:18 +0200 | [diff] [blame] | 53 | Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_start : _PyByteArray_empty_string) |
| 54 | #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)), Py_SIZE(self)) |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 55 | |
Antoine Pitrou | 2ff627a | 2010-01-17 16:15:29 +0000 | [diff] [blame] | 56 | PyAPI_DATA(char) _PyByteArray_empty_string[]; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 57 | #endif |
Antoine Pitrou | fc8d6f4 | 2010-01-17 12:38:54 +0000 | [diff] [blame] | 58 | |
Christian Heimes | 2c9c7a5 | 2008-05-26 13:42:13 +0000 | [diff] [blame] | 59 | #ifdef __cplusplus |
| 60 | } |
| 61 | #endif |
Georg Brandl | 0c77a82 | 2008-06-10 16:37:50 +0000 | [diff] [blame] | 62 | #endif /* !Py_BYTEARRAYOBJECT_H */ |