bytearrayobject.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* ByteArray object interface */
  2. #ifndef Py_BYTEARRAYOBJECT_H
  3. #define Py_BYTEARRAYOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <stdarg.h>
  8. /* Type PyByteArrayObject represents a mutable array of bytes.
  9. * The Python API is that of a sequence;
  10. * the bytes are mapped to ints in [0, 256).
  11. * Bytes are not characters; they may be used to encode characters.
  12. * The only way to go between bytes and str/unicode is via encoding
  13. * and decoding.
  14. * For the convenience of C programmers, the bytes type is considered
  15. * to contain a char pointer, not an unsigned char pointer.
  16. */
  17. /* Object layout */
  18. #ifndef Py_LIMITED_API
  19. typedef struct {
  20. PyObject_VAR_HEAD
  21. Py_ssize_t ob_alloc; /* How many bytes allocated in ob_bytes */
  22. char *ob_bytes; /* Physical backing buffer */
  23. char *ob_start; /* Logical start inside ob_bytes */
  24. /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
  25. int ob_exports; /* How many buffer exports */
  26. } PyByteArrayObject;
  27. #endif
  28. /* Type object */
  29. PyAPI_DATA(PyTypeObject) PyByteArray_Type;
  30. PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
  31. /* Type check macros */
  32. #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)
  33. #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)
  34. /* Direct API functions */
  35. PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);
  36. PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *);
  37. PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t);
  38. PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *);
  39. PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);
  40. PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
  41. /* Macros, trading safety for speed */
  42. #ifndef Py_LIMITED_API
  43. #define PyByteArray_AS_STRING(self) \
  44. (assert(PyByteArray_Check(self)), \
  45. Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_start : _PyByteArray_empty_string)
  46. #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)), Py_SIZE(self))
  47. PyAPI_DATA(char) _PyByteArray_empty_string[];
  48. #endif
  49. #ifdef __cplusplus
  50. }
  51. #endif
  52. #endif /* !Py_BYTEARRAYOBJECT_H */