blob: 0a256d4b5b0b8206dae4cc6a72493fe6195bd679 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001#ifndef Py_PYCORECONFIG_H
2#define Py_PYCORECONFIG_H
3#ifndef Py_LIMITED_API
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8/* --- PyStatus ----------------------------------------------- */
9
10typedef struct {
11 enum {
12 _PyStatus_TYPE_OK=0,
13 _PyStatus_TYPE_ERROR=1,
14 _PyStatus_TYPE_EXIT=2
15 } _type;
16 const char *func;
17 const char *err_msg;
18 int exitcode;
19} PyStatus;
20
21PyAPI_FUNC(PyStatus) PyStatus_Ok(void);
22PyAPI_FUNC(PyStatus) PyStatus_Error(const char *err_msg);
23PyAPI_FUNC(PyStatus) PyStatus_NoMemory(void);
24PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
25PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
26PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
27PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
28
29/* --- PyWideStringList ------------------------------------------------ */
30
31typedef struct {
32 /* If length is greater than zero, items must be non-NULL
33 and all items strings must be non-NULL */
34 Py_ssize_t length;
35 wchar_t **items;
36} PyWideStringList;
37
38PyAPI_FUNC(PyStatus) PyWideStringList_Append(PyWideStringList *list,
39 const wchar_t *item);
40PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
41 Py_ssize_t index,
42 const wchar_t *item);
43
44
45/* --- PyPreConfig ----------------------------------------------- */
46
47typedef struct {
48 int _config_init; /* _PyConfigInitEnum value */
49
50 /* Parse Py_PreInitializeFromBytesArgs() arguments?
51 See PyConfig.parse_argv */
52 int parse_argv;
53
54 /* If greater than 0, enable isolated mode: sys.path contains
55 neither the script's directory nor the user's site-packages directory.
56
57 Set to 1 by the -I command line option. If set to -1 (default), inherit
58 Py_IsolatedFlag value. */
59 int isolated;
60
61 /* If greater than 0: use environment variables.
62 Set to 0 by -E command line option. If set to -1 (default), it is
63 set to !Py_IgnoreEnvironmentFlag. */
64 int use_environment;
65
66 /* Set the LC_CTYPE locale to the user preferred locale? If equals to 0,
67 set coerce_c_locale and coerce_c_locale_warn to 0. */
68 int configure_locale;
69
70 /* Coerce the LC_CTYPE locale if it's equal to "C"? (PEP 538)
71
72 Set to 0 by PYTHONCOERCECLOCALE=0. Set to 1 by PYTHONCOERCECLOCALE=1.
73 Set to 2 if the user preferred LC_CTYPE locale is "C".
74
75 If it is equal to 1, LC_CTYPE locale is read to decide if it should be
76 coerced or not (ex: PYTHONCOERCECLOCALE=1). Internally, it is set to 2
77 if the LC_CTYPE locale must be coerced.
78
79 Disable by default (set to 0). Set it to -1 to let Python decide if it
80 should be enabled or not. */
81 int coerce_c_locale;
82
83 /* Emit a warning if the LC_CTYPE locale is coerced?
84
85 Set to 1 by PYTHONCOERCECLOCALE=warn.
86
87 Disable by default (set to 0). Set it to -1 to let Python decide if it
88 should be enabled or not. */
89 int coerce_c_locale_warn;
90
91#ifdef MS_WINDOWS
92 /* If greater than 1, use the "mbcs" encoding instead of the UTF-8
93 encoding for the filesystem encoding.
94
95 Set to 1 if the PYTHONLEGACYWINDOWSFSENCODING environment variable is
96 set to a non-empty string. If set to -1 (default), inherit
97 Py_LegacyWindowsFSEncodingFlag value.
98
99 See PEP 529 for more details. */
100 int legacy_windows_fs_encoding;
101#endif
102
103 /* Enable UTF-8 mode? (PEP 540)
104
105 Disabled by default (equals to 0).
106
107 Set to 1 by "-X utf8" and "-X utf8=1" command line options.
108 Set to 1 by PYTHONUTF8=1 environment variable.
109
110 Set to 0 by "-X utf8=0" and PYTHONUTF8=0.
111
112 If equals to -1, it is set to 1 if the LC_CTYPE locale is "C" or
113 "POSIX", otherwise it is set to 0. Inherit Py_UTF8Mode value value. */
114 int utf8_mode;
115
116 /* If non-zero, enable the Python Development Mode.
117
118 Set to 1 by the -X dev command line option. Set by the PYTHONDEVMODE
119 environment variable. */
120 int dev_mode;
121
122 /* Memory allocator: PYTHONMALLOC env var.
123 See PyMemAllocatorName for valid values. */
124 int allocator;
125} PyPreConfig;
126
127PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
128PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
129
130
131/* --- PyConfig ---------------------------------------------- */
132
133typedef struct {
134 int _config_init; /* _PyConfigInitEnum value */
135
136 int isolated; /* Isolated mode? see PyPreConfig.isolated */
137 int use_environment; /* Use environment variables? see PyPreConfig.use_environment */
138 int dev_mode; /* Python Development Mode? See PyPreConfig.dev_mode */
139
140 /* Install signal handlers? Yes by default. */
141 int install_signal_handlers;
142
143 int use_hash_seed; /* PYTHONHASHSEED=x */
144 unsigned long hash_seed;
145
146 /* Enable faulthandler?
147 Set to 1 by -X faulthandler and PYTHONFAULTHANDLER. -1 means unset. */
148 int faulthandler;
149
150 /* Enable PEG parser?
151 1 by default, set to 0 by -X oldparser and PYTHONOLDPARSER */
152 int _use_peg_parser;
153
154 /* Enable tracemalloc?
155 Set by -X tracemalloc=N and PYTHONTRACEMALLOC. -1 means unset */
156 int tracemalloc;
157
158 int import_time; /* PYTHONPROFILEIMPORTTIME, -X importtime */
159 int show_ref_count; /* -X showrefcount */
160 int dump_refs; /* PYTHONDUMPREFS */
161 int malloc_stats; /* PYTHONMALLOCSTATS */
162
163 /* Python filesystem encoding and error handler:
164 sys.getfilesystemencoding() and sys.getfilesystemencodeerrors().
165
166 Default encoding and error handler:
167
168 * if Py_SetStandardStreamEncoding() has been called: they have the
169 highest priority;
170 * PYTHONIOENCODING environment variable;
171 * The UTF-8 Mode uses UTF-8/surrogateescape;
172 * If Python forces the usage of the ASCII encoding (ex: C locale
173 or POSIX locale on FreeBSD or HP-UX), use ASCII/surrogateescape;
174 * locale encoding: ANSI code page on Windows, UTF-8 on Android and
175 VxWorks, LC_CTYPE locale encoding on other platforms;
176 * On Windows, "surrogateescape" error handler;
177 * "surrogateescape" error handler if the LC_CTYPE locale is "C" or "POSIX";
178 * "surrogateescape" error handler if the LC_CTYPE locale has been coerced
179 (PEP 538);
180 * "strict" error handler.
181
182 Supported error handlers: "strict", "surrogateescape" and
183 "surrogatepass". The surrogatepass error handler is only supported
184 if Py_DecodeLocale() and Py_EncodeLocale() use directly the UTF-8 codec;
185 it's only used on Windows.
186
187 initfsencoding() updates the encoding to the Python codec name.
188 For example, "ANSI_X3.4-1968" is replaced with "ascii".
189
190 On Windows, sys._enablelegacywindowsfsencoding() sets the
191 encoding/errors to mbcs/replace at runtime.
192
193
194 See Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors.
195 */
196 wchar_t *filesystem_encoding;
197 wchar_t *filesystem_errors;
198
199 wchar_t *pycache_prefix; /* PYTHONPYCACHEPREFIX, -X pycache_prefix=PATH */
200 int parse_argv; /* Parse argv command line arguments? */
201
202 /* Command line arguments (sys.argv).
203
204 Set parse_argv to 1 to parse argv as Python command line arguments
205 and then strip Python arguments from argv.
206
207 If argv is empty, an empty string is added to ensure that sys.argv
208 always exists and is never empty. */
209 PyWideStringList argv;
210
211 /* Program name:
212
213 - If Py_SetProgramName() was called, use its value.
214 - On macOS, use PYTHONEXECUTABLE environment variable if set.
215 - If WITH_NEXT_FRAMEWORK macro is defined, use __PYVENV_LAUNCHER__
216 environment variable is set.
217 - Use argv[0] if available and non-empty.
218 - Use "python" on Windows, or "python3 on other platforms. */
219 wchar_t *program_name;
220
221 PyWideStringList xoptions; /* Command line -X options */
222
223 /* Warnings options: lowest to highest priority. warnings.filters
224 is built in the reverse order (highest to lowest priority). */
225 PyWideStringList warnoptions;
226
227 /* If equal to zero, disable the import of the module site and the
228 site-dependent manipulations of sys.path that it entails. Also disable
229 these manipulations if site is explicitly imported later (call
230 site.main() if you want them to be triggered).
231
232 Set to 0 by the -S command line option. If set to -1 (default), it is
233 set to !Py_NoSiteFlag. */
234 int site_import;
235
236 /* Bytes warnings:
237
238 * If equal to 1, issue a warning when comparing bytes or bytearray with
239 str or bytes with int.
240 * If equal or greater to 2, issue an error.
241
242 Incremented by the -b command line option. If set to -1 (default), inherit
243 Py_BytesWarningFlag value. */
244 int bytes_warning;
245
246 /* If greater than 0, enable inspect: when a script is passed as first
247 argument or the -c option is used, enter interactive mode after
248 executing the script or the command, even when sys.stdin does not appear
249 to be a terminal.
250
251 Incremented by the -i command line option. Set to 1 if the PYTHONINSPECT
252 environment variable is non-empty. If set to -1 (default), inherit
253 Py_InspectFlag value. */
254 int inspect;
255
256 /* If greater than 0: enable the interactive mode (REPL).
257
258 Incremented by the -i command line option. If set to -1 (default),
259 inherit Py_InteractiveFlag value. */
260 int interactive;
261
262 /* Optimization level.
263
264 Incremented by the -O command line option. Set by the PYTHONOPTIMIZE
265 environment variable. If set to -1 (default), inherit Py_OptimizeFlag
266 value. */
267 int optimization_level;
268
269 /* If greater than 0, enable the debug mode: turn on parser debugging
270 output (for expert only, depending on compilation options).
271
272 Incremented by the -d command line option. Set by the PYTHONDEBUG
273 environment variable. If set to -1 (default), inherit Py_DebugFlag
274 value. */
275 int parser_debug;
276
277 /* If equal to 0, Python won't try to write ``.pyc`` files on the
278 import of source modules.
279
280 Set to 0 by the -B command line option and the PYTHONDONTWRITEBYTECODE
281 environment variable. If set to -1 (default), it is set to
282 !Py_DontWriteBytecodeFlag. */
283 int write_bytecode;
284
285 /* If greater than 0, enable the verbose mode: print a message each time a
286 module is initialized, showing the place (filename or built-in module)
287 from which it is loaded.
288
289 If greater or equal to 2, print a message for each file that is checked
290 for when searching for a module. Also provides information on module
291 cleanup at exit.
292
293 Incremented by the -v option. Set by the PYTHONVERBOSE environment
294 variable. If set to -1 (default), inherit Py_VerboseFlag value. */
295 int verbose;
296
297 /* If greater than 0, enable the quiet mode: Don't display the copyright
298 and version messages even in interactive mode.
299
300 Incremented by the -q option. If set to -1 (default), inherit
301 Py_QuietFlag value. */
302 int quiet;
303
304 /* If greater than 0, don't add the user site-packages directory to
305 sys.path.
306
307 Set to 0 by the -s and -I command line options , and the PYTHONNOUSERSITE
308 environment variable. If set to -1 (default), it is set to
309 !Py_NoUserSiteDirectory. */
310 int user_site_directory;
311
312 /* If non-zero, configure C standard steams (stdio, stdout,
313 stderr):
314
315 - Set O_BINARY mode on Windows.
316 - If buffered_stdio is equal to zero, make streams unbuffered.
317 Otherwise, enable streams buffering if interactive is non-zero. */
318 int configure_c_stdio;
319
320 /* If equal to 0, enable unbuffered mode: force the stdout and stderr
321 streams to be unbuffered.
322
323 Set to 0 by the -u option. Set by the PYTHONUNBUFFERED environment
324 variable.
325 If set to -1 (default), it is set to !Py_UnbufferedStdioFlag. */
326 int buffered_stdio;
327
328 /* Encoding of sys.stdin, sys.stdout and sys.stderr.
329 Value set from PYTHONIOENCODING environment variable and
330 Py_SetStandardStreamEncoding() function.
331 See also 'stdio_errors' attribute. */
332 wchar_t *stdio_encoding;
333
334 /* Error handler of sys.stdin and sys.stdout.
335 Value set from PYTHONIOENCODING environment variable and
336 Py_SetStandardStreamEncoding() function.
337 See also 'stdio_encoding' attribute. */
338 wchar_t *stdio_errors;
339
340#ifdef MS_WINDOWS
341 /* If greater than zero, use io.FileIO instead of WindowsConsoleIO for sys
342 standard streams.
343
344 Set to 1 if the PYTHONLEGACYWINDOWSSTDIO environment variable is set to
345 a non-empty string. If set to -1 (default), inherit
346 Py_LegacyWindowsStdioFlag value.
347
348 See PEP 528 for more details. */
349 int legacy_windows_stdio;
350#endif
351
352 /* Value of the --check-hash-based-pycs command line option:
353
354 - "default" means the 'check_source' flag in hash-based pycs
355 determines invalidation
356 - "always" causes the interpreter to hash the source file for
357 invalidation regardless of value of 'check_source' bit
358 - "never" causes the interpreter to always assume hash-based pycs are
359 valid
360
361 The default value is "default".
362
363 See PEP 552 "Deterministic pycs" for more details. */
364 wchar_t *check_hash_pycs_mode;
365
366 /* --- Path configuration inputs ------------ */
367
368 /* If greater than 0, suppress _PyPathConfig_Calculate() warnings on Unix.
369 The parameter has no effect on Windows.
370
371 If set to -1 (default), inherit !Py_FrozenFlag value. */
372 int pathconfig_warnings;
373
374 wchar_t *pythonpath_env; /* PYTHONPATH environment variable */
375 wchar_t *home; /* PYTHONHOME environment variable,
376 see also Py_SetPythonHome(). */
377
378 /* --- Path configuration outputs ----------- */
379
380 int module_search_paths_set; /* If non-zero, use module_search_paths */
381 PyWideStringList module_search_paths; /* sys.path paths. Computed if
382 module_search_paths_set is equal
383 to zero. */
384
385 wchar_t *executable; /* sys.executable */
386 wchar_t *base_executable; /* sys._base_executable */
387 wchar_t *prefix; /* sys.prefix */
388 wchar_t *base_prefix; /* sys.base_prefix */
389 wchar_t *exec_prefix; /* sys.exec_prefix */
390 wchar_t *base_exec_prefix; /* sys.base_exec_prefix */
391 wchar_t *platlibdir; /* sys.platlibdir */
392
393 /* --- Parameter only used by Py_Main() ---------- */
394
395 /* Skip the first line of the source ('run_filename' parameter), allowing use of non-Unix forms of
396 "#!cmd". This is intended for a DOS specific hack only.
397
398 Set by the -x command line option. */
399 int skip_source_first_line;
400
401 wchar_t *run_command; /* -c command line argument */
402 wchar_t *run_module; /* -m command line argument */
403 wchar_t *run_filename; /* Trailing command line argument without -c or -m */
404
405 /* --- Private fields ---------------------------- */
406
407 /* Install importlib? If set to 0, importlib is not initialized at all.
408 Needed by freeze_importlib. */
409 int _install_importlib;
410
411 /* If equal to 0, stop Python initialization before the "main" phase */
412 int _init_main;
413
414 /* If non-zero, disallow threads, subprocesses, and fork.
415 Default: 0. */
416 int _isolated_interpreter;
417
418 /* Original command line arguments. If _orig_argv is empty and _argv is
419 not equal to [''], PyConfig_Read() copies the configuration 'argv' list
420 into '_orig_argv' list before modifying 'argv' list (if parse_argv
421 is non-zero).
422
423 _PyConfig_Write() initializes Py_GetArgcArgv() to this list. */
424 PyWideStringList _orig_argv;
425} PyConfig;
426
427PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
428PyAPI_FUNC(void) PyConfig_InitIsolatedConfig(PyConfig *config);
429PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
430PyAPI_FUNC(PyStatus) PyConfig_SetString(
431 PyConfig *config,
432 wchar_t **config_str,
433 const wchar_t *str);
434PyAPI_FUNC(PyStatus) PyConfig_SetBytesString(
435 PyConfig *config,
436 wchar_t **config_str,
437 const char *str);
438PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config);
439PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
440 PyConfig *config,
441 Py_ssize_t argc,
442 char * const *argv);
443PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
444 Py_ssize_t argc,
445 wchar_t * const *argv);
446PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
447 PyWideStringList *list,
448 Py_ssize_t length, wchar_t **items);
449
450
451/* --- Helper functions --------------------------------------- */
452
453/* Get the original command line arguments, before Python modified them.
454
455 See also PyConfig._orig_argv. */
456PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);
457
458#ifdef __cplusplus
459}
460#endif
461#endif /* !Py_LIMITED_API */
462#endif /* !Py_PYCORECONFIG_H */