| 1 | #ifndef Py_CPYTHON_BYTEARRAYOBJECT_H |
|---|---|
| 2 | # error "this header file must not be included directly" |
| 3 | #endif |
| 4 | |
| 5 | /* Object layout */ |
| 6 | typedef struct { |
| 7 | PyObject_VAR_HEAD |
| 8 | Py_ssize_t ob_alloc; /* How many bytes allocated in ob_bytes */ |
| 9 | char *ob_bytes; /* Physical backing buffer */ |
| 10 | char *ob_start; /* Logical start inside ob_bytes */ |
| 11 | Py_ssize_t ob_exports; /* How many buffer exports */ |
| 12 | } PyByteArrayObject; |
| 13 | |
| 14 | PyAPI_DATA(char) _PyByteArray_empty_string[]; |
| 15 | |
| 16 | /* Macros and static inline functions, trading safety for speed */ |
| 17 | #define _PyByteArray_CAST(op) \ |
| 18 | (assert(PyByteArray_Check(op)), _Py_CAST(PyByteArrayObject*, op)) |
| 19 | |
| 20 | static inline char* PyByteArray_AS_STRING(PyObject *op) |
| 21 | { |
| 22 | PyByteArrayObject *self = _PyByteArray_CAST(op); |
| 23 | if (Py_SIZE(self)) { |
| 24 | return self->ob_start; |
| 25 | } |
| 26 | return _PyByteArray_empty_string; |
| 27 | } |
| 28 | #define PyByteArray_AS_STRING(self) PyByteArray_AS_STRING(_PyObject_CAST(self)) |
| 29 | |
| 30 | static inline Py_ssize_t PyByteArray_GET_SIZE(PyObject *op) { |
| 31 | PyByteArrayObject *self = _PyByteArray_CAST(op); |
| 32 | return Py_SIZE(self); |
| 33 | } |
| 34 | #define PyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self)) |
| 35 |
