pycore_initconfig.h 5.0 KB

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