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 PyPreConfig {
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
127 PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
128 PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
129
130
131 /* --- PyConfig ---------------------------------------------- */
132
133 /* This structure is best documented in the Doc/c-api/init_config.rst file. */
134 typedef struct PyConfig {
135 int _config_init; /* _PyConfigInitEnum value */
136
137 int isolated;
138 int use_environment;
139 int dev_mode;
140 int install_signal_handlers;
141 int use_hash_seed;
142 unsigned long hash_seed;
143 int faulthandler;
144 int tracemalloc;
145 int import_time;
146 int code_debug_ranges;
147 int show_ref_count;
148 int dump_refs;
149 wchar_t *dump_refs_file;
150 int malloc_stats;
151 wchar_t *filesystem_encoding;
152 wchar_t *filesystem_errors;
153 wchar_t *pycache_prefix;
154 int parse_argv;
155 PyWideStringList orig_argv;
156 PyWideStringList argv;
157 PyWideStringList xoptions;
158 PyWideStringList warnoptions;
159 int site_import;
160 int bytes_warning;
161 int warn_default_encoding;
162 int inspect;
163 int interactive;
164 int optimization_level;
165 int parser_debug;
166 int write_bytecode;
167 int verbose;
168 int quiet;
169 int user_site_directory;
170 int configure_c_stdio;
171 int buffered_stdio;
172 wchar_t *stdio_encoding;
173 wchar_t *stdio_errors;
174 #ifdef MS_WINDOWS
175 int legacy_windows_stdio;
176 #endif
177 wchar_t *check_hash_pycs_mode;
178 int use_frozen_modules;
179 int safe_path;
180
181 /* --- Path configuration inputs ------------ */
182 int pathconfig_warnings;
183 wchar_t *program_name;
184 wchar_t *pythonpath_env;
185 wchar_t *home;
186 wchar_t *platlibdir;
187
188 /* --- Path configuration outputs ----------- */
189 int module_search_paths_set;
190 PyWideStringList module_search_paths;
191 wchar_t *stdlib_dir;
192 wchar_t *executable;
193 wchar_t *base_executable;
194 wchar_t *prefix;
195 wchar_t *base_prefix;
196 wchar_t *exec_prefix;
197 wchar_t *base_exec_prefix;
198
199 /* --- Parameter only used by Py_Main() ---------- */
200 int skip_source_first_line;
201 wchar_t *run_command;
202 wchar_t *run_module;
203 wchar_t *run_filename;
204
205 /* --- Private fields ---------------------------- */
206
207 // Install importlib? If equals to 0, importlib is not initialized at all.
208 // Needed by freeze_importlib.
209 int _install_importlib;
210
211 // If equal to 0, stop Python initialization before the "main" phase.
212 int _init_main;
213
214 // If non-zero, disallow threads, subprocesses, and fork.
215 // Default: 0.
216 int _isolated_interpreter;
217
218 // If non-zero, we believe we're running from a source tree.
219 int _is_python_build;
220 } PyConfig;
221
222 PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
223 PyAPI_FUNC(void) PyConfig_InitIsolatedConfig(PyConfig *config);
224 PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
225 PyAPI_FUNC(PyStatus) PyConfig_SetString(
226 PyConfig *config,
227 wchar_t **config_str,
228 const wchar_t *str);
229 PyAPI_FUNC(PyStatus) PyConfig_SetBytesString(
230 PyConfig *config,
231 wchar_t **config_str,
232 const char *str);
233 PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config);
234 PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
235 PyConfig *config,
236 Py_ssize_t argc,
237 char * const *argv);
238 PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
239 Py_ssize_t argc,
240 wchar_t * const *argv);
241 PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
242 PyWideStringList *list,
243 Py_ssize_t length, wchar_t **items);
244
245
246 /* --- Helper functions --------------------------------------- */
247
248 /* Get the original command line arguments, before Python modified them.
249
250 See also PyConfig.orig_argv. */
251 PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);
252
253 #ifdef __cplusplus
254 }
255 #endif
256 #endif /* !Py_LIMITED_API */
257 #endif /* !Py_PYCORECONFIG_H */