initconfig.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. /* --- PyWideStringList ------------------------------------------------ */
  26. typedef struct {
  27. /* If length is greater than zero, items must be non-NULL
  28. and all items strings must be non-NULL */
  29. Py_ssize_t length;
  30. wchar_t **items;
  31. } PyWideStringList;
  32. PyAPI_FUNC(PyStatus) PyWideStringList_Append(PyWideStringList *list,
  33. const wchar_t *item);
  34. PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
  35. Py_ssize_t index,
  36. const wchar_t *item);
  37. /* --- PyPreConfig ----------------------------------------------- */
  38. typedef struct {
  39. int _config_init; /* _PyConfigInitEnum value */
  40. /* Parse Py_PreInitializeFromBytesArgs() arguments?
  41. See PyConfig.parse_argv */
  42. int parse_argv;
  43. /* If greater than 0, enable isolated mode: sys.path contains
  44. neither the script's directory nor the user's site-packages directory.
  45. Set to 1 by the -I command line option. If set to -1 (default), inherit
  46. Py_IsolatedFlag value. */
  47. int isolated;
  48. /* If greater than 0: use environment variables.
  49. Set to 0 by -E command line option. If set to -1 (default), it is
  50. set to !Py_IgnoreEnvironmentFlag. */
  51. int use_environment;
  52. /* Set the LC_CTYPE locale to the user preferred locale? If equals to 0,
  53. set coerce_c_locale and coerce_c_locale_warn to 0. */
  54. int configure_locale;
  55. /* Coerce the LC_CTYPE locale if it's equal to "C"? (PEP 538)
  56. Set to 0 by PYTHONCOERCECLOCALE=0. Set to 1 by PYTHONCOERCECLOCALE=1.
  57. Set to 2 if the user preferred LC_CTYPE locale is "C".
  58. If it is equal to 1, LC_CTYPE locale is read to decide if it should be
  59. coerced or not (ex: PYTHONCOERCECLOCALE=1). Internally, it is set to 2
  60. if the LC_CTYPE locale must be coerced.
  61. Disable by default (set to 0). Set it to -1 to let Python decide if it
  62. should be enabled or not. */
  63. int coerce_c_locale;
  64. /* Emit a warning if the LC_CTYPE locale is coerced?
  65. Set to 1 by PYTHONCOERCECLOCALE=warn.
  66. Disable by default (set to 0). Set it to -1 to let Python decide if it
  67. should be enabled or not. */
  68. int coerce_c_locale_warn;
  69. #ifdef MS_WINDOWS
  70. /* If greater than 1, use the "mbcs" encoding instead of the UTF-8
  71. encoding for the filesystem encoding.
  72. Set to 1 if the PYTHONLEGACYWINDOWSFSENCODING environment variable is
  73. set to a non-empty string. If set to -1 (default), inherit
  74. Py_LegacyWindowsFSEncodingFlag value.
  75. See PEP 529 for more details. */
  76. int legacy_windows_fs_encoding;
  77. #endif
  78. /* Enable UTF-8 mode? (PEP 540)
  79. Disabled by default (equals to 0).
  80. Set to 1 by "-X utf8" and "-X utf8=1" command line options.
  81. Set to 1 by PYTHONUTF8=1 environment variable.
  82. Set to 0 by "-X utf8=0" and PYTHONUTF8=0.
  83. If equals to -1, it is set to 1 if the LC_CTYPE locale is "C" or
  84. "POSIX", otherwise it is set to 0. Inherit Py_UTF8Mode value value. */
  85. int utf8_mode;
  86. int dev_mode; /* Development mode. PYTHONDEVMODE, -X dev */
  87. /* Memory allocator: PYTHONMALLOC env var.
  88. See PyMemAllocatorName for valid values. */
  89. int allocator;
  90. } PyPreConfig;
  91. PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
  92. PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
  93. /* --- PyConfig ---------------------------------------------- */
  94. typedef struct {
  95. int _config_init; /* _PyConfigInitEnum value */
  96. int isolated; /* Isolated mode? see PyPreConfig.isolated */
  97. int use_environment; /* Use environment variables? see PyPreConfig.use_environment */
  98. int dev_mode; /* Development mode? See PyPreConfig.dev_mode */
  99. /* Install signal handlers? Yes by default. */
  100. int install_signal_handlers;
  101. int use_hash_seed; /* PYTHONHASHSEED=x */
  102. unsigned long hash_seed;
  103. /* Enable faulthandler?
  104. Set to 1 by -X faulthandler and PYTHONFAULTHANDLER. -1 means unset. */
  105. int faulthandler;
  106. /* Enable tracemalloc?
  107. Set by -X tracemalloc=N and PYTHONTRACEMALLOC. -1 means unset */
  108. int tracemalloc;
  109. int import_time; /* PYTHONPROFILEIMPORTTIME, -X importtime */
  110. int show_ref_count; /* -X showrefcount */
  111. int show_alloc_count; /* -X showalloccount */
  112. int dump_refs; /* PYTHONDUMPREFS */
  113. int malloc_stats; /* PYTHONMALLOCSTATS */
  114. /* Python filesystem encoding and error handler:
  115. sys.getfilesystemencoding() and sys.getfilesystemencodeerrors().
  116. Default encoding and error handler:
  117. * if Py_SetStandardStreamEncoding() has been called: they have the
  118. highest priority;
  119. * PYTHONIOENCODING environment variable;
  120. * The UTF-8 Mode uses UTF-8/surrogateescape;
  121. * If Python forces the usage of the ASCII encoding (ex: C locale
  122. or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape;
  123. * locale encoding: ANSI code page on Windows, UTF-8 on Android and
  124. VxWorks, LC_CTYPE locale encoding on other platforms;
  125. * On Windows, "surrogateescape" error handler;
  126. * "surrogateescape" error handler if the LC_CTYPE locale is "C" or "POSIX";
  127. * "surrogateescape" error handler if the LC_CTYPE locale has been coerced
  128. (PEP 538);
  129. * "strict" error handler.
  130. Supported error handlers: "strict", "surrogateescape" and
  131. "surrogatepass". The surrogatepass error handler is only supported
  132. if Py_DecodeLocale() and Py_EncodeLocale() use directly the UTF-8 codec;
  133. it's only used on Windows.
  134. initfsencoding() updates the encoding to the Python codec name.
  135. For example, "ANSI_X3.4-1968" is replaced with "ascii".
  136. On Windows, sys._enablelegacywindowsfsencoding() sets the
  137. encoding/errors to mbcs/replace at runtime.
  138. See Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors.
  139. */
  140. wchar_t *filesystem_encoding;
  141. wchar_t *filesystem_errors;
  142. wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */
  143. int parse_argv; /* Parse argv command line arguments? */
  144. /* Command line arguments (sys.argv).
  145. Set parse_argv to 1 to parse argv as Python command line arguments
  146. and then strip Python arguments from argv.
  147. If argv is empty, an empty string is added to ensure that sys.argv
  148. always exists and is never empty. */
  149. PyWideStringList argv;
  150. /* Program name:
  151. - If Py_SetProgramName() was called, use its value.
  152. - On macOS, use PYTHONEXECUTABLE environment variable if set.
  153. - If WITH_NEXT_FRAMEWORK macro is defined, use __PYVENV_LAUNCHER__
  154. environment variable is set.
  155. - Use argv[0] if available and non-empty.
  156. - Use "python" on Windows, or "python3 on other platforms. */
  157. wchar_t *program_name;
  158. PyWideStringList xoptions; /* Command line -X options */
  159. /* Warnings options: lowest to highest priority. warnings.filters
  160. is built in the reverse order (highest to lowest priority). */
  161. PyWideStringList warnoptions;
  162. /* If equal to zero, disable the import of the module site and the
  163. site-dependent manipulations of sys.path that it entails. Also disable
  164. these manipulations if site is explicitly imported later (call
  165. site.main() if you want them to be triggered).
  166. Set to 0 by the -S command line option. If set to -1 (default), it is
  167. set to !Py_NoSiteFlag. */
  168. int site_import;
  169. /* Bytes warnings:
  170. * If equal to 1, issue a warning when comparing bytes or bytearray with
  171. str or bytes with int.
  172. * If equal or greater to 2, issue an error.
  173. Incremented by the -b command line option. If set to -1 (default), inherit
  174. Py_BytesWarningFlag value. */
  175. int bytes_warning;
  176. /* If greater than 0, enable inspect: when a script is passed as first
  177. argument or the -c option is used, enter interactive mode after
  178. executing the script or the command, even when sys.stdin does not appear
  179. to be a terminal.
  180. Incremented by the -i command line option. Set to 1 if the PYTHONINSPECT
  181. environment variable is non-empty. If set to -1 (default), inherit
  182. Py_InspectFlag value. */
  183. int inspect;
  184. /* If greater than 0: enable the interactive mode (REPL).
  185. Incremented by the -i command line option. If set to -1 (default),
  186. inherit Py_InteractiveFlag value. */
  187. int interactive;
  188. /* Optimization level.
  189. Incremented by the -O command line option. Set by the PYTHONOPTIMIZE
  190. environment variable. If set to -1 (default), inherit Py_OptimizeFlag
  191. value. */
  192. int optimization_level;
  193. /* If greater than 0, enable the debug mode: turn on parser debugging
  194. output (for expert only, depending on compilation options).
  195. Incremented by the -d command line option. Set by the PYTHONDEBUG
  196. environment variable. If set to -1 (default), inherit Py_DebugFlag
  197. value. */
  198. int parser_debug;
  199. /* If equal to 0, Python won't try to write ``.pyc`` files on the
  200. import of source modules.
  201. Set to 0 by the -B command line option and the PYTHONDONTWRITEBYTECODE
  202. environment variable. If set to -1 (default), it is set to
  203. !Py_DontWriteBytecodeFlag. */
  204. int write_bytecode;
  205. /* If greater than 0, enable the verbose mode: print a message each time a
  206. module is initialized, showing the place (filename or built-in module)
  207. from which it is loaded.
  208. If greater or equal to 2, print a message for each file that is checked
  209. for when searching for a module. Also provides information on module
  210. cleanup at exit.
  211. Incremented by the -v option. Set by the PYTHONVERBOSE environment
  212. variable. If set to -1 (default), inherit Py_VerboseFlag value. */
  213. int verbose;
  214. /* If greater than 0, enable the quiet mode: Don't display the copyright
  215. and version messages even in interactive mode.
  216. Incremented by the -q option. If set to -1 (default), inherit
  217. Py_QuietFlag value. */
  218. int quiet;
  219. /* If greater than 0, don't add the user site-packages directory to
  220. sys.path.
  221. Set to 0 by the -s and -I command line options , and the PYTHONNOUSERSITE
  222. environment variable. If set to -1 (default), it is set to
  223. !Py_NoUserSiteDirectory. */
  224. int user_site_directory;
  225. /* If non-zero, configure C standard steams (stdio, stdout,
  226. stderr):
  227. - Set O_BINARY mode on Windows.
  228. - If buffered_stdio is equal to zero, make streams unbuffered.
  229. Otherwise, enable streams buffering if interactive is non-zero. */
  230. int configure_c_stdio;
  231. /* If equal to 0, enable unbuffered mode: force the stdout and stderr
  232. streams to be unbuffered.
  233. Set to 0 by the -u option. Set by the PYTHONUNBUFFERED environment
  234. variable.
  235. If set to -1 (default), it is set to !Py_UnbufferedStdioFlag. */
  236. int buffered_stdio;
  237. /* Encoding of sys.stdin, sys.stdout and sys.stderr.
  238. Value set from PYTHONIOENCODING environment variable and
  239. Py_SetStandardStreamEncoding() function.
  240. See also 'stdio_errors' attribute. */
  241. wchar_t *stdio_encoding;
  242. /* Error handler of sys.stdin and sys.stdout.
  243. Value set from PYTHONIOENCODING environment variable and
  244. Py_SetStandardStreamEncoding() function.
  245. See also 'stdio_encoding' attribute. */
  246. wchar_t *stdio_errors;
  247. #ifdef MS_WINDOWS
  248. /* If greater than zero, use io.FileIO instead of WindowsConsoleIO for sys
  249. standard streams.
  250. Set to 1 if the PYTHONLEGACYWINDOWSSTDIO environment variable is set to
  251. a non-empty string. If set to -1 (default), inherit
  252. Py_LegacyWindowsStdioFlag value.
  253. See PEP 528 for more details. */
  254. int legacy_windows_stdio;
  255. #endif
  256. /* Value of the --check-hash-based-pycs command line option:
  257. - "default" means the 'check_source' flag in hash-based pycs
  258. determines invalidation
  259. - "always" causes the interpreter to hash the source file for
  260. invalidation regardless of value of 'check_source' bit
  261. - "never" causes the interpreter to always assume hash-based pycs are
  262. valid
  263. The default value is "default".
  264. See PEP 552 "Deterministic pycs" for more details. */
  265. wchar_t *check_hash_pycs_mode;
  266. /* --- Path configuration inputs ------------ */
  267. /* If greater than 0, suppress _PyPathConfig_Calculate() warnings on Unix.
  268. The parameter has no effect on Windows.
  269. If set to -1 (default), inherit !Py_FrozenFlag value. */
  270. int pathconfig_warnings;
  271. wchar_t *pythonpath_env; /* PYTHONPATH environment variable */
  272. wchar_t *home; /* PYTHONHOME environment variable,
  273. see also Py_SetPythonHome(). */
  274. /* --- Path configuration outputs ----------- */
  275. int module_search_paths_set; /* If non-zero, use module_search_paths */
  276. PyWideStringList module_search_paths; /* sys.path paths. Computed if
  277. module_search_paths_set is equal
  278. to zero. */
  279. wchar_t *executable; /* sys.executable */
  280. wchar_t *base_executable; /* sys._base_executable */
  281. wchar_t *prefix; /* sys.prefix */
  282. wchar_t *base_prefix; /* sys.base_prefix */
  283. wchar_t *exec_prefix; /* sys.exec_prefix */
  284. wchar_t *base_exec_prefix; /* sys.base_exec_prefix */
  285. /* --- Parameter only used by Py_Main() ---------- */
  286. /* Skip the first line of the source ('run_filename' parameter), allowing use of non-Unix forms of
  287. "#!cmd". This is intended for a DOS specific hack only.
  288. Set by the -x command line option. */
  289. int skip_source_first_line;
  290. wchar_t *run_command; /* -c command line argument */
  291. wchar_t *run_module; /* -m command line argument */
  292. wchar_t *run_filename; /* Trailing command line argument without -c or -m */
  293. /* --- Private fields ---------------------------- */
  294. /* Install importlib? If set to 0, importlib is not initialized at all.
  295. Needed by freeze_importlib. */
  296. int _install_importlib;
  297. /* If equal to 0, stop Python initialization before the "main" phase */
  298. int _init_main;
  299. } PyConfig;
  300. PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
  301. PyAPI_FUNC(void) PyConfig_InitIsolatedConfig(PyConfig *config);
  302. PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
  303. PyAPI_FUNC(PyStatus) PyConfig_SetString(
  304. PyConfig *config,
  305. wchar_t **config_str,
  306. const wchar_t *str);
  307. PyAPI_FUNC(PyStatus) PyConfig_SetBytesString(
  308. PyConfig *config,
  309. wchar_t **config_str,
  310. const char *str);
  311. PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config);
  312. PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
  313. PyConfig *config,
  314. Py_ssize_t argc,
  315. char * const *argv);
  316. PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
  317. Py_ssize_t argc,
  318. wchar_t * const *argv);
  319. PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
  320. PyWideStringList *list,
  321. Py_ssize_t length, wchar_t **items);
  322. #ifdef __cplusplus
  323. }
  324. #endif
  325. #endif /* !Py_LIMITED_API */
  326. #endif /* !Py_PYCORECONFIG_H */