initconfig.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #ifndef Py_PYCORECONFIG_H
  2. #define Py_PYCORECONFIG_H
  3. #ifndef Py_LIMITED_API
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /* --- PyStatus ----------------------------------------------- */
  8. typedef struct {
  9. enum {
  10. _PyStatus_TYPE_OK=0,
  11. _PyStatus_TYPE_ERROR=1,
  12. _PyStatus_TYPE_EXIT=2
  13. } _type;
  14. const char *func;
  15. const char *err_msg;
  16. int exitcode;
  17. } PyStatus;
  18. PyAPI_FUNC(PyStatus) PyStatus_Ok(void);
  19. PyAPI_FUNC(PyStatus) PyStatus_Error(const char *err_msg);
  20. PyAPI_FUNC(PyStatus) PyStatus_NoMemory(void);
  21. PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
  22. PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
  23. PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
  24. PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
  25. PyAPI_FUNC(PyObject *) _PyErr_SetFromPyStatus(PyStatus status);
  26. /* --- PyWideStringList ------------------------------------------------ */
  27. typedef struct {
  28. /* If length is greater than zero, items must be non-NULL
  29. and all items strings must be non-NULL */
  30. Py_ssize_t length;
  31. wchar_t **items;
  32. } PyWideStringList;
  33. PyAPI_FUNC(PyStatus) PyWideStringList_Append(PyWideStringList *list,
  34. const wchar_t *item);
  35. PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
  36. Py_ssize_t index,
  37. const wchar_t *item);
  38. /* --- PyPreConfig ----------------------------------------------- */
  39. typedef struct PyPreConfig {
  40. int _config_init; /* _PyConfigInitEnum value */
  41. /* Parse Py_PreInitializeFromBytesArgs() arguments?
  42. See PyConfig.parse_argv */
  43. int parse_argv;
  44. /* If greater than 0, enable isolated mode: sys.path contains
  45. neither the script's directory nor the user's site-packages directory.
  46. Set to 1 by the -I command line option. If set to -1 (default), inherit
  47. Py_IsolatedFlag value. */
  48. int isolated;
  49. /* If greater than 0: use environment variables.
  50. Set to 0 by -E command line option. If set to -1 (default), it is
  51. set to !Py_IgnoreEnvironmentFlag. */
  52. int use_environment;
  53. /* Set the LC_CTYPE locale to the user preferred locale? If equals to 0,
  54. set coerce_c_locale and coerce_c_locale_warn to 0. */
  55. int configure_locale;
  56. /* Coerce the LC_CTYPE locale if it's equal to "C"? (PEP 538)
  57. Set to 0 by PYTHONCOERCECLOCALE=0. Set to 1 by PYTHONCOERCECLOCALE=1.
  58. Set to 2 if the user preferred LC_CTYPE locale is "C".
  59. If it is equal to 1, LC_CTYPE locale is read to decide if it should be
  60. coerced or not (ex: PYTHONCOERCECLOCALE=1). Internally, it is set to 2
  61. if the LC_CTYPE locale must be coerced.
  62. Disable by default (set to 0). Set it to -1 to let Python decide if it
  63. should be enabled or not. */
  64. int coerce_c_locale;
  65. /* Emit a warning if the LC_CTYPE locale is coerced?
  66. Set to 1 by PYTHONCOERCECLOCALE=warn.
  67. Disable by default (set to 0). Set it to -1 to let Python decide if it
  68. should be enabled or not. */
  69. int coerce_c_locale_warn;
  70. #ifdef MS_WINDOWS
  71. /* If greater than 1, use the "mbcs" encoding instead of the UTF-8
  72. encoding for the filesystem encoding.
  73. Set to 1 if the PYTHONLEGACYWINDOWSFSENCODING environment variable is
  74. set to a non-empty string. If set to -1 (default), inherit
  75. Py_LegacyWindowsFSEncodingFlag value.
  76. See PEP 529 for more details. */
  77. int legacy_windows_fs_encoding;
  78. #endif
  79. /* Enable UTF-8 mode? (PEP 540)
  80. Disabled by default (equals to 0).
  81. Set to 1 by "-X utf8" and "-X utf8=1" command line options.
  82. Set to 1 by PYTHONUTF8=1 environment variable.
  83. Set to 0 by "-X utf8=0" and PYTHONUTF8=0.
  84. If equals to -1, it is set to 1 if the LC_CTYPE locale is "C" or
  85. "POSIX", otherwise it is set to 0. Inherit Py_UTF8Mode value value. */
  86. int utf8_mode;
  87. /* If non-zero, enable the Python Development Mode.
  88. Set to 1 by the -X dev command line option. Set by the PYTHONDEVMODE
  89. environment variable. */
  90. int dev_mode;
  91. /* Memory allocator: PYTHONMALLOC env var.
  92. See PyMemAllocatorName for valid values. */
  93. int allocator;
  94. } PyPreConfig;
  95. PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
  96. PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
  97. /* --- PyConfig ---------------------------------------------- */
  98. /* This structure is best documented in the Doc/c-api/init_config.rst file. */
  99. typedef struct PyConfig {
  100. int _config_init; /* _PyConfigInitEnum value */
  101. int isolated;
  102. int use_environment;
  103. int dev_mode;
  104. int install_signal_handlers;
  105. int use_hash_seed;
  106. unsigned long hash_seed;
  107. int faulthandler;
  108. int tracemalloc;
  109. int perf_profiling;
  110. int import_time;
  111. int code_debug_ranges;
  112. int show_ref_count;
  113. int dump_refs;
  114. wchar_t *dump_refs_file;
  115. int malloc_stats;
  116. wchar_t *filesystem_encoding;
  117. wchar_t *filesystem_errors;
  118. wchar_t *pycache_prefix;
  119. int parse_argv;
  120. PyWideStringList orig_argv;
  121. PyWideStringList argv;
  122. PyWideStringList xoptions;
  123. PyWideStringList warnoptions;
  124. int site_import;
  125. int bytes_warning;
  126. int warn_default_encoding;
  127. int inspect;
  128. int interactive;
  129. int optimization_level;
  130. int parser_debug;
  131. int write_bytecode;
  132. int verbose;
  133. int quiet;
  134. int user_site_directory;
  135. int configure_c_stdio;
  136. int buffered_stdio;
  137. wchar_t *stdio_encoding;
  138. wchar_t *stdio_errors;
  139. #ifdef MS_WINDOWS
  140. int legacy_windows_stdio;
  141. #endif
  142. wchar_t *check_hash_pycs_mode;
  143. int use_frozen_modules;
  144. int safe_path;
  145. int int_max_str_digits;
  146. /* --- Path configuration inputs ------------ */
  147. int pathconfig_warnings;
  148. wchar_t *program_name;
  149. wchar_t *pythonpath_env;
  150. wchar_t *home;
  151. wchar_t *platlibdir;
  152. /* --- Path configuration outputs ----------- */
  153. int module_search_paths_set;
  154. PyWideStringList module_search_paths;
  155. wchar_t *stdlib_dir;
  156. wchar_t *executable;
  157. wchar_t *base_executable;
  158. wchar_t *prefix;
  159. wchar_t *base_prefix;
  160. wchar_t *exec_prefix;
  161. wchar_t *base_exec_prefix;
  162. /* --- Parameter only used by Py_Main() ---------- */
  163. int skip_source_first_line;
  164. wchar_t *run_command;
  165. wchar_t *run_module;
  166. wchar_t *run_filename;
  167. /* --- Private fields ---------------------------- */
  168. // Install importlib? If equals to 0, importlib is not initialized at all.
  169. // Needed by freeze_importlib.
  170. int _install_importlib;
  171. // If equal to 0, stop Python initialization before the "main" phase.
  172. int _init_main;
  173. // If non-zero, we believe we're running from a source tree.
  174. int _is_python_build;
  175. } PyConfig;
  176. PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
  177. PyAPI_FUNC(void) PyConfig_InitIsolatedConfig(PyConfig *config);
  178. PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
  179. PyAPI_FUNC(PyStatus) PyConfig_SetString(
  180. PyConfig *config,
  181. wchar_t **config_str,
  182. const wchar_t *str);
  183. PyAPI_FUNC(PyStatus) PyConfig_SetBytesString(
  184. PyConfig *config,
  185. wchar_t **config_str,
  186. const char *str);
  187. PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config);
  188. PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
  189. PyConfig *config,
  190. Py_ssize_t argc,
  191. char * const *argv);
  192. PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
  193. Py_ssize_t argc,
  194. wchar_t * const *argv);
  195. PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
  196. PyWideStringList *list,
  197. Py_ssize_t length, wchar_t **items);
  198. /* --- Helper functions --------------------------------------- */
  199. /* Get the original command line arguments, before Python modified them.
  200. See also PyConfig.orig_argv. */
  201. PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);
  202. #ifdef __cplusplus
  203. }
  204. #endif
  205. #endif /* !Py_LIMITED_API */
  206. #endif /* !Py_PYCORECONFIG_H */