bytearrayobject.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. typedef struct {
  19. PyObject_VAR_HEAD
  20. /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
  21. int ob_exports; /* how many buffer exports */
  22. Py_ssize_t ob_alloc; /* How many bytes allocated */
  23. char *ob_bytes;
  24. } PyByteArrayObject;
  25. /* Type object */
  26. PyAPI_DATA(PyTypeObject) PyByteArray_Type;
  27. PyAPI_DATA(PyTypeObject) PyByteArrayIter_Type;
  28. /* Type check macros */
  29. #define PyByteArray_Check(self) PyObject_TypeCheck(self, &PyByteArray_Type)
  30. #define PyByteArray_CheckExact(self) (Py_TYPE(self) == &PyByteArray_Type)
  31. /* Direct API functions */
  32. PyAPI_FUNC(PyObject *) PyByteArray_FromObject(PyObject *);
  33. PyAPI_FUNC(PyObject *) PyByteArray_Concat(PyObject *, PyObject *);
  34. PyAPI_FUNC(PyObject *) PyByteArray_FromStringAndSize(const char *, Py_ssize_t);
  35. PyAPI_FUNC(Py_ssize_t) PyByteArray_Size(PyObject *);
  36. PyAPI_FUNC(char *) PyByteArray_AsString(PyObject *);
  37. PyAPI_FUNC(int) PyByteArray_Resize(PyObject *, Py_ssize_t);
  38. /* Macros, trading safety for speed */
  39. #define PyByteArray_AS_STRING(self) \
  40. (assert(PyByteArray_Check(self)), \
  41. Py_SIZE(self) ? ((PyByteArrayObject *)(self))->ob_bytes : _PyByteArray_empty_string)
  42. #define PyByteArray_GET_SIZE(self) (assert(PyByteArray_Check(self)),Py_SIZE(self))
  43. PyAPI_DATA(char) _PyByteArray_empty_string[];
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif /* !Py_BYTEARRAYOBJECT_H */