initconfig.h 17 KB

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