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

source code of include/python3.12/cpython/initconfig.h