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