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