blob: 09f9a2947efef38a01a4a1242477a2f0a26d156e [file] [log] [blame]
Victor Stinner6c785c02018-08-01 17:56:14 +02001#ifndef Py_PYCORECONFIG_H
2#define Py_PYCORECONFIG_H
Victor Stinnerf684d832019-03-01 03:44:13 +01003#ifndef Py_LIMITED_API
Victor Stinner6c785c02018-08-01 17:56:14 +02004
Victor Stinner331a6a52019-05-27 16:39:22 +02005/* --- PyStatus ----------------------------------------------- */
Victor Stinner6c785c02018-08-01 17:56:14 +02006
Victor Stinner6c785c02018-08-01 17:56:14 +02007typedef struct {
Victor Stinnerdb719752019-05-01 05:35:33 +02008 enum {
Victor Stinner331a6a52019-05-27 16:39:22 +02009 _PyStatus_TYPE_OK=0,
10 _PyStatus_TYPE_ERROR=1,
11 _PyStatus_TYPE_EXIT=2
Victor Stinnerdb719752019-05-01 05:35:33 +020012 } _type;
Victor Stinner331a6a52019-05-27 16:39:22 +020013 const char *func;
Victor Stinnerdb719752019-05-01 05:35:33 +020014 const char *err_msg;
Victor Stinnerdfe88472019-03-01 12:14:41 +010015 int exitcode;
Victor Stinner331a6a52019-05-27 16:39:22 +020016} PyStatus;
Victor Stinner6c785c02018-08-01 17:56:14 +020017
Victor Stinner331a6a52019-05-27 16:39:22 +020018PyAPI_FUNC(PyStatus) PyStatus_Ok(void);
19PyAPI_FUNC(PyStatus) PyStatus_Error(const char *err_msg);
20PyAPI_FUNC(PyStatus) PyStatus_NoMemory(void);
21PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
22PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
23PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
24PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
Victor Stinner6c785c02018-08-01 17:56:14 +020025
Victor Stinner331a6a52019-05-27 16:39:22 +020026/* --- PyWideStringList ------------------------------------------------ */
Victor Stinner74f65682019-03-15 15:08:05 +010027
28typedef 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;
Victor Stinner331a6a52019-05-27 16:39:22 +020033} PyWideStringList;
34
35PyAPI_FUNC(PyStatus) PyWideStringList_Append(PyWideStringList *list,
36 const wchar_t *item);
Victor Stinner3842f292019-08-23 16:57:54 +010037PyAPI_FUNC(PyStatus) PyWideStringList_Insert(PyWideStringList *list,
38 Py_ssize_t index,
39 const wchar_t *item);
Victor Stinner74f65682019-03-15 15:08:05 +010040
Victor Stinner74f65682019-03-15 15:08:05 +010041
Victor Stinner331a6a52019-05-27 16:39:22 +020042/* --- PyPreConfig ----------------------------------------------- */
Victor Stinner022be022019-05-22 23:58:50 +020043
Victor Stinnercfb41e82020-11-04 16:15:54 +010044typedef struct PyPreConfig {
Victor Stinner022be022019-05-22 23:58:50 +020045 int _config_init; /* _PyConfigInitEnum value */
Victor Stinner373893c2019-05-02 14:46:29 -040046
Victor Stinner331a6a52019-05-27 16:39:22 +020047 /* Parse Py_PreInitializeFromBytesArgs() arguments?
48 See PyConfig.parse_argv */
Victor Stinner6d1c4672019-05-20 11:02:00 +020049 int parse_argv;
50
Victor Stinnercad1f742019-03-05 02:01:27 +010051 /* 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;
Victor Stinner6c785c02018-08-01 17:56:14 +020057
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;
Victor Stinner5a02e0d2019-03-05 12:32:09 +010062
Victor Stinnerbcfbbd72019-05-17 22:44:16 +020063 /* 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
Victor Stinnerd929f182019-03-27 18:28:46 +010067 /* 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".
Victor Stinnerf72346c2019-03-25 17:54:58 +010071
MandarJKulkarni33ce3f02019-05-29 04:25:05 +053072 If it is equal to 1, LC_CTYPE locale is read to decide if it should be
Victor Stinnerf72346c2019-03-25 17:54:58 +010073 coerced or not (ex: PYTHONCOERCECLOCALE=1). Internally, it is set to 2
Victor Stinnercab5d072019-05-17 19:01:14 +020074 if the LC_CTYPE locale must be coerced.
75
MandarJKulkarni33ce3f02019-05-29 04:25:05 +053076 Disable by default (set to 0). Set it to -1 to let Python decide if it
Victor Stinnercab5d072019-05-17 19:01:14 +020077 should be enabled or not. */
Victor Stinnerf72346c2019-03-25 17:54:58 +010078 int coerce_c_locale;
Victor Stinnerd929f182019-03-27 18:28:46 +010079
80 /* Emit a warning if the LC_CTYPE locale is coerced?
81
Victor Stinnercab5d072019-05-17 19:01:14 +020082 Set to 1 by PYTHONCOERCECLOCALE=warn.
83
MandarJKulkarni33ce3f02019-05-29 04:25:05 +053084 Disable by default (set to 0). Set it to -1 to let Python decide if it
Victor Stinnercab5d072019-05-17 19:01:14 +020085 should be enabled or not. */
Victor Stinnerd929f182019-03-27 18:28:46 +010086 int coerce_c_locale_warn;
Victor Stinner5a02e0d2019-03-05 12:32:09 +010087
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
Victor Stinnerd929f182019-03-27 18:28:46 +0100100 /* 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
Victor Stinner022be022019-05-22 23:58:50 +0200110 "POSIX", otherwise it is set to 0. Inherit Py_UTF8Mode value value. */
Victor Stinner5a02e0d2019-03-05 12:32:09 +0100111 int utf8_mode;
Victor Stinnerb35be4b2019-03-05 17:37:44 +0100112
Victor Stinnerb9783d22020-01-24 10:22:18 +0100113 /* 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;
Victor Stinnerb16b4e42019-05-17 15:20:52 +0200118
Victor Stinner6d1c4672019-05-20 11:02:00 +0200119 /* Memory allocator: PYTHONMALLOC env var.
120 See PyMemAllocatorName for valid values. */
121 int allocator;
Victor Stinner331a6a52019-05-27 16:39:22 +0200122} PyPreConfig;
Victor Stinnercad1f742019-03-05 02:01:27 +0100123
Victor Stinner3c30a762019-10-01 10:56:37 +0200124PyAPI_FUNC(void) PyPreConfig_InitPythonConfig(PyPreConfig *config);
125PyAPI_FUNC(void) PyPreConfig_InitIsolatedConfig(PyPreConfig *config);
Victor Stinnercab5d072019-05-17 19:01:14 +0200126
Victor Stinnercad1f742019-03-05 02:01:27 +0100127
Victor Stinner331a6a52019-05-27 16:39:22 +0200128/* --- PyConfig ---------------------------------------------- */
Victor Stinnercad1f742019-03-05 02:01:27 +0100129
Victor Stinner4b9aad42020-11-02 16:49:54 +0100130/* This structure is best documented in the Doc/c-api/init_config.rst file. */
Victor Stinnercfb41e82020-11-04 16:15:54 +0100131typedef struct PyConfig {
Victor Stinner022be022019-05-22 23:58:50 +0200132 int _config_init; /* _PyConfigInitEnum value */
Victor Stinner373893c2019-05-02 14:46:29 -0400133
Victor Stinner4b9aad42020-11-02 16:49:54 +0100134 int isolated;
135 int use_environment;
136 int dev_mode;
Victor Stinnercad1f742019-03-05 02:01:27 +0100137 int install_signal_handlers;
Victor Stinner4b9aad42020-11-02 16:49:54 +0100138 int use_hash_seed;
Victor Stinner6c785c02018-08-01 17:56:14 +0200139 unsigned long hash_seed;
Victor Stinner6c785c02018-08-01 17:56:14 +0200140 int faulthandler;
Victor Stinner6c785c02018-08-01 17:56:14 +0200141 int tracemalloc;
Victor Stinner4b9aad42020-11-02 16:49:54 +0100142 int import_time;
143 int show_ref_count;
144 int dump_refs;
145 int malloc_stats;
Victor Stinner709d23d2019-05-02 14:56:30 -0400146 wchar_t *filesystem_encoding;
147 wchar_t *filesystem_errors;
Victor Stinner4b9aad42020-11-02 16:49:54 +0100148 wchar_t *pycache_prefix;
149 int parse_argv;
Victor Stinnercfb41e82020-11-04 16:15:54 +0100150 PyWideStringList orig_argv;
Victor Stinner331a6a52019-05-27 16:39:22 +0200151 PyWideStringList argv;
Victor Stinner4b9aad42020-11-02 16:49:54 +0100152 PyWideStringList xoptions;
Victor Stinnerfb4ae152019-09-30 01:40:17 +0200153 PyWideStringList warnoptions;
Victor Stinner6c785c02018-08-01 17:56:14 +0200154 int site_import;
Victor Stinner6c785c02018-08-01 17:56:14 +0200155 int bytes_warning;
Inada Naoki48274832021-03-29 12:28:14 +0900156 int warn_default_encoding;
Victor Stinner6c785c02018-08-01 17:56:14 +0200157 int inspect;
Victor Stinner6c785c02018-08-01 17:56:14 +0200158 int interactive;
Victor Stinner6c785c02018-08-01 17:56:14 +0200159 int optimization_level;
Victor Stinner6c785c02018-08-01 17:56:14 +0200160 int parser_debug;
Victor Stinner6c785c02018-08-01 17:56:14 +0200161 int write_bytecode;
Victor Stinner6c785c02018-08-01 17:56:14 +0200162 int verbose;
Victor Stinner6c785c02018-08-01 17:56:14 +0200163 int quiet;
Victor Stinner6c785c02018-08-01 17:56:14 +0200164 int user_site_directory;
Victor Stinner54b43bb2019-05-16 18:30:15 +0200165 int configure_c_stdio;
Victor Stinner6c785c02018-08-01 17:56:14 +0200166 int buffered_stdio;
Victor Stinner709d23d2019-05-02 14:56:30 -0400167 wchar_t *stdio_encoding;
Victor Stinner709d23d2019-05-02 14:56:30 -0400168 wchar_t *stdio_errors;
Victor Stinner6c785c02018-08-01 17:56:14 +0200169#ifdef MS_WINDOWS
Victor Stinner6c785c02018-08-01 17:56:14 +0200170 int legacy_windows_stdio;
171#endif
Victor Stinner331a6a52019-05-27 16:39:22 +0200172 wchar_t *check_hash_pycs_mode;
173
Victor Stinnerae239f62019-05-16 17:02:56 +0200174 /* --- Path configuration inputs ------------ */
Victor Stinner331a6a52019-05-27 16:39:22 +0200175 int pathconfig_warnings;
Victor Stinnercfb41e82020-11-04 16:15:54 +0100176 wchar_t *program_name;
Victor Stinner4b9aad42020-11-02 16:49:54 +0100177 wchar_t *pythonpath_env;
178 wchar_t *home;
Victor Stinnercfb41e82020-11-04 16:15:54 +0100179 wchar_t *platlibdir;
Victor Stinnerae239f62019-05-16 17:02:56 +0200180
181 /* --- Path configuration outputs ----------- */
Victor Stinner4b9aad42020-11-02 16:49:54 +0100182 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;
Victor Stinnerae239f62019-05-16 17:02:56 +0200190
Victor Stinner62be7632019-03-01 13:10:14 +0100191 /* --- Parameter only used by Py_Main() ---------- */
Victor Stinner62be7632019-03-01 13:10:14 +0100192 int skip_source_first_line;
Victor Stinner4b9aad42020-11-02 16:49:54 +0100193 wchar_t *run_command;
194 wchar_t *run_module;
195 wchar_t *run_filename;
Victor Stinner62be7632019-03-01 13:10:14 +0100196
197 /* --- Private fields ---------------------------- */
Victor Stinner6c785c02018-08-01 17:56:14 +0200198
Victor Stinner4b9aad42020-11-02 16:49:54 +0100199 // Install importlib? If equals to 0, importlib is not initialized at all.
200 // Needed by freeze_importlib.
Victor Stinner6c785c02018-08-01 17:56:14 +0200201 int _install_importlib;
202
Victor Stinner4b9aad42020-11-02 16:49:54 +0100203 // If equal to 0, stop Python initialization before the "main" phase.
Victor Stinner9ef5dca2019-05-16 17:38:16 +0200204 int _init_main;
Victor Stinner252346a2020-05-01 11:33:44 +0200205
Victor Stinner4b9aad42020-11-02 16:49:54 +0100206 // If non-zero, disallow threads, subprocesses, and fork.
207 // Default: 0.
Victor Stinner252346a2020-05-01 11:33:44 +0200208 int _isolated_interpreter;
Victor Stinner331a6a52019-05-27 16:39:22 +0200209} PyConfig;
Victor Stinner6c785c02018-08-01 17:56:14 +0200210
Victor Stinner8462a492019-10-01 12:06:16 +0200211PyAPI_FUNC(void) PyConfig_InitPythonConfig(PyConfig *config);
212PyAPI_FUNC(void) PyConfig_InitIsolatedConfig(PyConfig *config);
Victor Stinner331a6a52019-05-27 16:39:22 +0200213PyAPI_FUNC(void) PyConfig_Clear(PyConfig *);
214PyAPI_FUNC(PyStatus) PyConfig_SetString(
215 PyConfig *config,
Victor Stinnerbab0db62019-05-18 03:21:27 +0200216 wchar_t **config_str,
217 const wchar_t *str);
Victor Stinner331a6a52019-05-27 16:39:22 +0200218PyAPI_FUNC(PyStatus) PyConfig_SetBytesString(
219 PyConfig *config,
Victor Stinnerbab0db62019-05-18 03:21:27 +0200220 wchar_t **config_str,
221 const char *str);
Victor Stinner331a6a52019-05-27 16:39:22 +0200222PyAPI_FUNC(PyStatus) PyConfig_Read(PyConfig *config);
223PyAPI_FUNC(PyStatus) PyConfig_SetBytesArgv(
224 PyConfig *config,
Victor Stinnerbab0db62019-05-18 03:21:27 +0200225 Py_ssize_t argc,
Victor Stinner6d1c4672019-05-20 11:02:00 +0200226 char * const *argv);
Victor Stinner331a6a52019-05-27 16:39:22 +0200227PyAPI_FUNC(PyStatus) PyConfig_SetArgv(PyConfig *config,
Victor Stinnerbab0db62019-05-18 03:21:27 +0200228 Py_ssize_t argc,
Victor Stinner6d1c4672019-05-20 11:02:00 +0200229 wchar_t * const *argv);
Victor Stinner36242fd2019-07-01 19:13:50 +0200230PyAPI_FUNC(PyStatus) PyConfig_SetWideStringList(PyConfig *config,
231 PyWideStringList *list,
232 Py_ssize_t length, wchar_t **items);
Victor Stinnercab5d072019-05-17 19:01:14 +0200233
Victor Stinnere81f6e62020-06-08 18:12:59 +0200234
235/* --- Helper functions --------------------------------------- */
236
237/* Get the original command line arguments, before Python modified them.
238
Victor Stinnerdd8a93e2020-06-30 00:49:03 +0200239 See also PyConfig.orig_argv. */
Victor Stinnere81f6e62020-06-08 18:12:59 +0200240PyAPI_FUNC(void) Py_GetArgcArgv(int *argc, wchar_t ***argv);
241
Victor Stinnerf684d832019-03-01 03:44:13 +0100242#endif /* !Py_LIMITED_API */
Victor Stinner6c785c02018-08-01 17:56:14 +0200243#endif /* !Py_PYCORECONFIG_H */