pycore_unicodeobject.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef Py_INTERNAL_UNICODEOBJECT_H
  2. #define Py_INTERNAL_UNICODEOBJECT_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifndef Py_BUILD_CORE
  7. # error "this header requires Py_BUILD_CORE define"
  8. #endif
  9. #include "pycore_fileutils.h" // _Py_error_handler
  10. #include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
  11. void _PyUnicode_ExactDealloc(PyObject *op);
  12. Py_ssize_t _PyUnicode_InternedSize(void);
  13. Py_ssize_t _PyUnicode_InternedSize_Immortal(void);
  14. /* runtime lifecycle */
  15. extern void _PyUnicode_InitState(PyInterpreterState *);
  16. extern PyStatus _PyUnicode_InitGlobalObjects(PyInterpreterState *);
  17. extern PyStatus _PyUnicode_InitInternDict(PyInterpreterState *);
  18. extern PyStatus _PyUnicode_InitTypes(PyInterpreterState *);
  19. extern void _PyUnicode_Fini(PyInterpreterState *);
  20. extern void _PyUnicode_FiniTypes(PyInterpreterState *);
  21. extern PyTypeObject _PyUnicodeASCIIIter_Type;
  22. /* Interning */
  23. // All these are "ref-neutral", like the public PyUnicode_InternInPlace.
  24. // Explicit interning routines:
  25. PyAPI_FUNC(void) _PyUnicode_InternMortal(PyInterpreterState *interp, PyObject **);
  26. PyAPI_FUNC(void) _PyUnicode_InternImmortal(PyInterpreterState *interp, PyObject **);
  27. // Left here to help backporting:
  28. PyAPI_FUNC(void) _PyUnicode_InternInPlace(PyInterpreterState *interp, PyObject **p);
  29. // Only for statically allocated strings:
  30. extern void _PyUnicode_InternStatic(PyInterpreterState *interp, PyObject **);
  31. /* other API */
  32. struct _Py_unicode_runtime_ids {
  33. PyThread_type_lock lock;
  34. // next_index value must be preserved when Py_Initialize()/Py_Finalize()
  35. // is called multiple times: see _PyUnicode_FromId() implementation.
  36. Py_ssize_t next_index;
  37. };
  38. struct _Py_unicode_runtime_state {
  39. struct _Py_unicode_runtime_ids ids;
  40. };
  41. /* fs_codec.encoding is initialized to NULL.
  42. Later, it is set to a non-NULL string by _PyUnicode_InitEncodings(). */
  43. struct _Py_unicode_fs_codec {
  44. char *encoding; // Filesystem encoding (encoded to UTF-8)
  45. int utf8; // encoding=="utf-8"?
  46. char *errors; // Filesystem errors (encoded to UTF-8)
  47. _Py_error_handler error_handler;
  48. };
  49. struct _Py_unicode_ids {
  50. Py_ssize_t size;
  51. PyObject **array;
  52. };
  53. struct _Py_unicode_state {
  54. struct _Py_unicode_fs_codec fs_codec;
  55. _PyUnicode_Name_CAPI *ucnhash_capi;
  56. // Unicode identifiers (_Py_Identifier): see _PyUnicode_FromId()
  57. struct _Py_unicode_ids ids;
  58. };
  59. extern void _PyUnicode_ClearInterned(PyInterpreterState *interp);
  60. // Like PyUnicode_AsUTF8(), but check for embedded null characters.
  61. extern const char* _PyUnicode_AsUTF8NoNUL(PyObject *);
  62. #ifdef __cplusplus
  63. }
  64. #endif
  65. #endif /* !Py_INTERNAL_UNICODEOBJECT_H */