bytesobject.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Bytes (String) object interface */
  2. #ifndef Py_BYTESOBJECT_H
  3. #define Py_BYTESOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. #include <stdarg.h>
  8. /*
  9. Type PyBytesObject represents a character 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 string objects, to test
  14. an object for string-ness, and to get the
  15. 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 nil objects.
  20. */
  21. /* Caching the hash (ob_shash) saves recalculation of a string's hash value.
  22. This significantly speeds up dict lookups. */
  23. PyAPI_DATA(PyTypeObject) PyBytes_Type;
  24. PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
  25. #define PyBytes_Check(op) \
  26. PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS)
  27. #define PyBytes_CheckExact(op) Py_IS_TYPE(op, &PyBytes_Type)
  28. PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
  29. PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *);
  30. PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
  31. PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list)
  32. Py_GCC_ATTRIBUTE((format(printf, 1, 0)));
  33. PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...)
  34. Py_GCC_ATTRIBUTE((format(printf, 1, 2)));
  35. PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
  36. PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
  37. PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int);
  38. PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *);
  39. PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *);
  40. PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t,
  41. const char *, Py_ssize_t,
  42. const char *);
  43. /* Provides access to the internal data buffer and size of a string
  44. object or the default encoded version of a Unicode object. Passing
  45. NULL as *len parameter will force the string buffer to be
  46. 0-terminated (passing a string with embedded NULL characters will
  47. cause an exception). */
  48. PyAPI_FUNC(int) PyBytes_AsStringAndSize(
  49. PyObject *obj, /* string or Unicode object */
  50. char **s, /* pointer to buffer variable */
  51. Py_ssize_t *len /* pointer to length variable or NULL
  52. (only possible for 0-terminated
  53. strings) */
  54. );
  55. /* Flags used by string formatting */
  56. #define F_LJUST (1<<0)
  57. #define F_SIGN (1<<1)
  58. #define F_BLANK (1<<2)
  59. #define F_ALT (1<<3)
  60. #define F_ZERO (1<<4)
  61. #ifndef Py_LIMITED_API
  62. # define Py_CPYTHON_BYTESOBJECT_H
  63. # include "cpython/bytesobject.h"
  64. # undef Py_CPYTHON_BYTESOBJECT_H
  65. #endif
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* !Py_BYTESOBJECT_H */