bytesobject.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Bytes object interface */
  2. #ifndef Py_BYTESOBJECT_H
  3. #define Py_BYTESOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <stdarg.h> // va_list
  8. /*
  9. Type PyBytesObject represents a byte string. An extra zero byte is
  10. reserved at the end to ensure it is zero-terminated, but a size is
  11. present so strings with null bytes in them can be represented. This
  12. is an immutable object type.
  13. There are functions to create new bytes objects, to test
  14. an object for bytes-ness, and to get the
  15. byte string value. The latter function returns a null pointer
  16. if the object is not of the proper type.
  17. There is a variant that takes an explicit size as well as a
  18. variant that assumes a zero-terminated string. Note that none of the
  19. functions should be applied to NULL pointer.
  20. */
  21. PyAPI_DATA(PyTypeObject) PyBytes_Type;
  22. PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
  23. #define PyBytes_Check(op) \
  24. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
  25. #define PyBytes_CheckExact(op) Py_IS_TYPE((op), &PyBytes_Type)
  26. PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
  27. PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);
  28. PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
  29. PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list)
  30. Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
  31. PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...)
  32. Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
  33. PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
  34. PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
  35. PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int);
  36. PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *);
  37. PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *);
  38. PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
  39. const char *, Py_ssize_t,
  40. const char *);
  41. /* Provides access to the internal data buffer and size of a bytes object.
  42. Passing NULL as len parameter will force the string buffer to be
  43. 0-terminated (passing a string with embedded NUL characters will
  44. cause an exception). */
  45. PyAPI_FUNC(int) PyBytes_AsStringAndSize(
  46. PyObject *obj, /* bytes object */
  47. char **s, /* pointer to buffer variable */
  48. Py_ssize_t *len /* pointer to length variable or NULL */
  49. );
  50. #ifndef Py_LIMITED_API
  51. # define Py_CPYTHON_BYTESOBJECT_H
  52. # include "cpython/bytesobject.h"
  53. # undef Py_CPYTHON_BYTESOBJECT_H
  54. #endif
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif /* !Py_BYTESOBJECT_H */