pycore_initconfig.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef Py_INTERNAL_CORECONFIG_H
  2. #define Py_INTERNAL_CORECONFIG_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. /* Forward declaration */
  10. struct pyruntimestate;
  11. /* --- PyStatus ----------------------------------------------- */
  12. /* Almost all errors causing Python initialization to fail */
  13. #ifdef _MSC_VER
  14. /* Visual Studio 2015 doesn't implement C99 __func__ in C */
  15. # define _PyStatus_GET_FUNC() __FUNCTION__
  16. #else
  17. # define _PyStatus_GET_FUNC() __func__
  18. #endif
  19. #define _PyStatus_OK() \
  20. (PyStatus){._type = _PyStatus_TYPE_OK,}
  21. /* other fields are set to 0 */
  22. #define _PyStatus_ERR(ERR_MSG) \
  23. (PyStatus){ \
  24. ._type = _PyStatus_TYPE_ERROR, \
  25. .func = _PyStatus_GET_FUNC(), \
  26. .err_msg = (ERR_MSG)}
  27. /* other fields are set to 0 */
  28. #define _PyStatus_NO_MEMORY() _PyStatus_ERR("memory allocation failed")
  29. #define _PyStatus_EXIT(EXITCODE) \
  30. (PyStatus){ \
  31. ._type = _PyStatus_TYPE_EXIT, \
  32. .exitcode = (EXITCODE)}
  33. #define _PyStatus_IS_ERROR(err) \
  34. ((err)._type == _PyStatus_TYPE_ERROR)
  35. #define _PyStatus_IS_EXIT(err) \
  36. ((err)._type == _PyStatus_TYPE_EXIT)
  37. #define _PyStatus_EXCEPTION(err) \
  38. ((err)._type != _PyStatus_TYPE_OK)
  39. #define _PyStatus_UPDATE_FUNC(err) \
  40. do { (err).func = _PyStatus_GET_FUNC(); } while (0)
  41. /* --- PyWideStringList ------------------------------------------------ */
  42. #define _PyWideStringList_INIT (PyWideStringList){.length = 0, .items = NULL}
  43. #ifndef NDEBUG
  44. PyAPI_FUNC(int) _PyWideStringList_CheckConsistency(const PyWideStringList *list);
  45. #endif
  46. PyAPI_FUNC(void) _PyWideStringList_Clear(PyWideStringList *list);
  47. PyAPI_FUNC(int) _PyWideStringList_Copy(PyWideStringList *list,
  48. const PyWideStringList *list2);
  49. PyAPI_FUNC(PyStatus) _PyWideStringList_Extend(PyWideStringList *list,
  50. const PyWideStringList *list2);
  51. PyAPI_FUNC(PyObject*) _PyWideStringList_AsList(const PyWideStringList *list);
  52. /* --- _PyArgv ---------------------------------------------------- */
  53. typedef struct _PyArgv {
  54. Py_ssize_t argc;
  55. int use_bytes_argv;
  56. char * const *bytes_argv;
  57. wchar_t * const *wchar_argv;
  58. } _PyArgv;
  59. PyAPI_FUNC(PyStatus) _PyArgv_AsWstrList(const _PyArgv *args,
  60. PyWideStringList *list);
  61. /* --- Helper functions ------------------------------------------- */
  62. PyAPI_FUNC(int) _Py_str_to_int(
  63. const char *str,
  64. int *result);
  65. PyAPI_FUNC(const wchar_t*) _Py_get_xoption(
  66. const PyWideStringList *xoptions,
  67. const wchar_t *name);
  68. PyAPI_FUNC(const char*) _Py_GetEnv(
  69. int use_environment,
  70. const char *name);
  71. PyAPI_FUNC(void) _Py_get_env_flag(
  72. int use_environment,
  73. int *flag,
  74. const char *name);
  75. /* Py_GetArgcArgv() helper */
  76. PyAPI_FUNC(void) _Py_ClearArgcArgv(void);
  77. /* --- _PyPreCmdline ------------------------------------------------- */
  78. typedef struct {
  79. PyWideStringList argv;
  80. PyWideStringList xoptions; /* "-X value" option */
  81. int isolated; /* -I option */
  82. int use_environment; /* -E option */
  83. int dev_mode; /* -X dev and PYTHONDEVMODE */
  84. int warn_default_encoding; /* -X warn_default_encoding and PYTHONWARNDEFAULTENCODING */
  85. } _PyPreCmdline;
  86. #define _PyPreCmdline_INIT \
  87. (_PyPreCmdline){ \
  88. .use_environment = -1, \
  89. .isolated = -1, \
  90. .dev_mode = -1}
  91. /* Note: _PyPreCmdline_INIT sets other fields to 0/NULL */
  92. extern void _PyPreCmdline_Clear(_PyPreCmdline *cmdline);
  93. extern PyStatus _PyPreCmdline_SetArgv(_PyPreCmdline *cmdline,
  94. const _PyArgv *args);
  95. extern PyStatus _PyPreCmdline_SetConfig(
  96. const _PyPreCmdline *cmdline,
  97. PyConfig *config);
  98. extern PyStatus _PyPreCmdline_Read(_PyPreCmdline *cmdline,
  99. const PyPreConfig *preconfig);
  100. /* --- PyPreConfig ----------------------------------------------- */
  101. PyAPI_FUNC(void) _PyPreConfig_InitCompatConfig(PyPreConfig *preconfig);
  102. extern void _PyPreConfig_InitFromConfig(
  103. PyPreConfig *preconfig,
  104. const PyConfig *config);
  105. extern PyStatus _PyPreConfig_InitFromPreConfig(
  106. PyPreConfig *preconfig,
  107. const PyPreConfig *config2);
  108. extern PyObject* _PyPreConfig_AsDict(const PyPreConfig *preconfig);
  109. extern void _PyPreConfig_GetConfig(PyPreConfig *preconfig,
  110. const PyConfig *config);
  111. extern PyStatus _PyPreConfig_Read(PyPreConfig *preconfig,
  112. const _PyArgv *args);
  113. extern PyStatus _PyPreConfig_Write(const PyPreConfig *preconfig);
  114. /* --- PyConfig ---------------------------------------------- */
  115. typedef enum {
  116. /* Py_Initialize() API: backward compatibility with Python 3.6 and 3.7 */
  117. _PyConfig_INIT_COMPAT = 1,
  118. _PyConfig_INIT_PYTHON = 2,
  119. _PyConfig_INIT_ISOLATED = 3
  120. } _PyConfigInitEnum;
  121. PyAPI_FUNC(void) _PyConfig_InitCompatConfig(PyConfig *config);
  122. extern PyStatus _PyConfig_Copy(
  123. PyConfig *config,
  124. const PyConfig *config2);
  125. extern PyStatus _PyConfig_InitPathConfig(
  126. PyConfig *config,
  127. int compute_path_config);
  128. extern PyStatus _PyConfig_InitImportConfig(PyConfig *config);
  129. extern PyStatus _PyConfig_Read(PyConfig *config, int compute_path_config);
  130. extern PyStatus _PyConfig_Write(const PyConfig *config,
  131. struct pyruntimestate *runtime);
  132. extern PyStatus _PyConfig_SetPyArgv(
  133. PyConfig *config,
  134. const _PyArgv *args);
  135. PyAPI_FUNC(PyObject*) _PyConfig_AsDict(const PyConfig *config);
  136. PyAPI_FUNC(int) _PyConfig_FromDict(PyConfig *config, PyObject *dict);
  137. extern void _Py_DumpPathConfig(PyThreadState *tstate);
  138. PyAPI_FUNC(PyObject*) _Py_Get_Getpath_CodeObject(void);
  139. /* --- Function used for testing ---------------------------------- */
  140. PyAPI_FUNC(PyObject*) _Py_GetConfigsAsDict(void);
  141. #ifdef __cplusplus
  142. }
  143. #endif
  144. #endif /* !Py_INTERNAL_CORECONFIG_H */