bytearrayobject.h 1.1 KB

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