CONFIG_COMPAT = {
'_config_init': API_COMPAT,
- 'isolated': 0,
- 'use_environment': 1,
- 'dev_mode': 0,
+ 'isolated': False,
+ 'use_environment': True,
+ 'dev_mode': False,
- 'install_signal_handlers': 1,
- 'use_hash_seed': 0,
+ 'install_signal_handlers': True,
+ 'use_hash_seed': False,
'hash_seed': 0,
'int_max_str_digits': sys.int_info.default_max_str_digits,
'cpu_count': -1,
- 'faulthandler': 0,
+ 'faulthandler': False,
'tracemalloc': 0,
- 'perf_profiling': 0,
- 'import_time': 0,
- 'code_debug_ranges': 1,
- 'show_ref_count': 0,
- 'dump_refs': 0,
+ 'perf_profiling': False,
+ 'import_time': False,
+ 'code_debug_ranges': True,
+ 'show_ref_count': False,
+ 'dump_refs': False,
'dump_refs_file': None,
- 'malloc_stats': 0,
+ 'malloc_stats': False,
'filesystem_encoding': GET_DEFAULT_CONFIG,
'filesystem_errors': GET_DEFAULT_CONFIG,
'pycache_prefix': None,
'program_name': GET_DEFAULT_CONFIG,
- 'parse_argv': 0,
+ 'parse_argv': False,
'argv': [""],
'orig_argv': [],
'exec_prefix': GET_DEFAULT_CONFIG,
'base_exec_prefix': GET_DEFAULT_CONFIG,
'module_search_paths': GET_DEFAULT_CONFIG,
- 'module_search_paths_set': 1,
+ 'module_search_paths_set': True,
'platlibdir': sys.platlibdir,
'stdlib_dir': GET_DEFAULT_CONFIG,
- 'site_import': 1,
+ 'site_import': True,
'bytes_warning': 0,
- 'warn_default_encoding': 0,
- 'inspect': 0,
- 'interactive': 0,
+ 'warn_default_encoding': False,
+ 'inspect': False,
+ 'interactive': False,
'optimization_level': 0,
- 'parser_debug': 0,
- 'write_bytecode': 1,
+ 'parser_debug': False,
+ 'write_bytecode': True,
'verbose': 0,
- 'quiet': 0,
- 'user_site_directory': 1,
- 'configure_c_stdio': 0,
- 'buffered_stdio': 1,
+ 'quiet': False,
+ 'user_site_directory': True,
+ 'configure_c_stdio': False,
+ 'buffered_stdio': True,
'stdio_encoding': GET_DEFAULT_CONFIG,
'stdio_errors': GET_DEFAULT_CONFIG,
- 'skip_source_first_line': 0,
+ 'skip_source_first_line': False,
'run_command': None,
'run_module': None,
'run_filename': None,
'sys_path_0': None,
- '_install_importlib': 1,
+ '_install_importlib': True,
'check_hash_pycs_mode': 'default',
- 'pathconfig_warnings': 1,
- '_init_main': 1,
+ 'pathconfig_warnings': True,
+ '_init_main': True,
'use_frozen_modules': not support.Py_DEBUG,
- 'safe_path': 0,
+ 'safe_path': False,
'_is_python_build': IGNORE_CONFIG,
}
if Py_STATS:
CONFIG_PYTHON = dict(CONFIG_COMPAT,
_config_init=API_PYTHON,
- configure_c_stdio=1,
- parse_argv=2,
+ configure_c_stdio=True,
+ parse_argv=True,
)
CONFIG_ISOLATED = dict(CONFIG_COMPAT,
_config_init=API_ISOLATED,
- isolated=1,
- use_environment=0,
- user_site_directory=0,
- safe_path=1,
- dev_mode=0,
- install_signal_handlers=0,
- use_hash_seed=0,
- faulthandler=0,
+ isolated=True,
+ use_environment=False,
+ user_site_directory=False,
+ safe_path=True,
+ dev_mode=False,
+ install_signal_handlers=False,
+ use_hash_seed=False,
+ faulthandler=False,
tracemalloc=0,
- perf_profiling=0,
- pathconfig_warnings=0,
+ perf_profiling=False,
+ pathconfig_warnings=False,
)
if MS_WINDOWS:
CONFIG_ISOLATED['legacy_windows_stdio'] = 0
'utf8_mode': 1,
}
config = {
- 'install_signal_handlers': 0,
- 'use_hash_seed': 1,
+ 'install_signal_handlers': False,
+ 'use_hash_seed': True,
'hash_seed': 123,
'tracemalloc': 2,
- 'perf_profiling': 0,
- 'import_time': 1,
- 'code_debug_ranges': 0,
- 'show_ref_count': 1,
- 'malloc_stats': 1,
+ 'perf_profiling': False,
+ 'import_time': True,
+ 'code_debug_ranges': False,
+ 'show_ref_count': True,
+ 'malloc_stats': True,
'stdio_encoding': 'iso8859-1',
'stdio_errors': 'replace',
'-X', 'cmdline_xoption',
'-c', 'pass',
'arg2'],
- 'parse_argv': 2,
+ 'parse_argv': True,
'xoptions': [
'config_xoption1=3',
'config_xoption2=',
],
'run_command': 'pass\n',
- 'site_import': 0,
+ 'site_import': False,
'bytes_warning': 1,
- 'inspect': 1,
- 'interactive': 1,
+ 'inspect': True,
+ 'interactive': True,
'optimization_level': 2,
- 'write_bytecode': 0,
+ 'write_bytecode': False,
'verbose': 1,
- 'quiet': 1,
- 'configure_c_stdio': 1,
- 'buffered_stdio': 0,
- 'user_site_directory': 0,
- 'faulthandler': 1,
+ 'quiet': True,
+ 'configure_c_stdio': True,
+ 'buffered_stdio': False,
+ 'user_site_directory': False,
+ 'faulthandler': True,
'platlibdir': 'my_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
- 'safe_path': 1,
+ 'safe_path': True,
'int_max_str_digits': 31337,
'cpu_count': 4321,
'check_hash_pycs_mode': 'always',
- 'pathconfig_warnings': 0,
+ 'pathconfig_warnings': False,
}
if Py_STATS:
config['_pystats'] = 1
'allocator': ALLOCATOR_FOR_CONFIG,
}
config = {
- 'use_hash_seed': 1,
+ 'use_hash_seed': True,
'hash_seed': 42,
'tracemalloc': 2,
- 'perf_profiling': 0,
- 'import_time': 1,
- 'code_debug_ranges': 0,
- 'malloc_stats': 1,
- 'inspect': 1,
+ 'perf_profiling': False,
+ 'import_time': True,
+ 'code_debug_ranges': False,
+ 'malloc_stats': True,
+ 'inspect': True,
'optimization_level': 2,
'pythonpath_env': '/my/path',
'pycache_prefix': 'env_pycache_prefix',
- 'write_bytecode': 0,
+ 'write_bytecode': False,
'verbose': 1,
- 'buffered_stdio': 0,
+ 'buffered_stdio': False,
'stdio_encoding': 'iso8859-1',
'stdio_errors': 'replace',
- 'user_site_directory': 0,
- 'faulthandler': 1,
+ 'user_site_directory': False,
+ 'faulthandler': True,
'warnoptions': ['EnvVar'],
'platlibdir': 'env_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
- 'safe_path': 1,
+ 'safe_path': True,
'int_max_str_digits': 4567,
}
if Py_STATS:
'utf8_mode': 1,
}
config = {
- 'use_hash_seed': 1,
+ 'use_hash_seed': True,
'hash_seed': 42,
'tracemalloc': 2,
- 'perf_profiling': 0,
- 'import_time': 1,
- 'code_debug_ranges': 0,
- 'malloc_stats': 1,
- 'inspect': 1,
+ 'perf_profiling': False,
+ 'import_time': True,
+ 'code_debug_ranges': False,
+ 'malloc_stats': True,
+ 'inspect': True,
'optimization_level': 2,
'pythonpath_env': '/my/path',
'pycache_prefix': 'env_pycache_prefix',
- 'write_bytecode': 0,
+ 'write_bytecode': False,
'verbose': 1,
- 'buffered_stdio': 0,
+ 'buffered_stdio': False,
'stdio_encoding': 'iso8859-1',
'stdio_errors': 'replace',
- 'user_site_directory': 0,
- 'faulthandler': 1,
+ 'user_site_directory': False,
+ 'faulthandler': True,
'warnoptions': ['EnvVar'],
'platlibdir': 'env_platlibdir',
'module_search_paths': self.IGNORE_CONFIG,
- 'safe_path': 1,
+ 'safe_path': True,
'int_max_str_digits': 4567,
}
if Py_STATS:
- config['_pystats'] = 1
+ config['_pystats'] = True
self.check_all_configs("test_init_python_env", config, preconfig,
api=API_PYTHON)
'allocator': PYMEM_ALLOCATOR_DEBUG,
}
config = {
- 'faulthandler': 1,
- 'dev_mode': 1,
+ 'faulthandler': True,
+ 'dev_mode': True,
'warnoptions': ['default'],
}
self.check_all_configs("test_init_dev_mode", config, preconfig,
'argv': ['script.py'],
'orig_argv': ['python3', '-X', 'dev', '-P', 'script.py'],
'run_filename': os.path.abspath('script.py'),
- 'dev_mode': 1,
- 'faulthandler': 1,
+ 'dev_mode': True,
+ 'faulthandler': True,
'warnoptions': ['default'],
'xoptions': ['dev'],
- 'safe_path': 1,
+ 'safe_path': True,
}
self.check_all_configs("test_preinit_parse_argv", config, preconfig,
api=API_PYTHON)
def test_init_isolated_flag(self):
config = {
- 'isolated': 1,
- 'safe_path': 1,
- 'use_environment': 0,
- 'user_site_directory': 0,
+ 'isolated': True,
+ 'safe_path': True,
+ 'use_environment': False,
+ 'user_site_directory': False,
}
self.check_all_configs("test_init_isolated_flag", config, api=API_PYTHON)
def test_preinit_isolated1(self):
# _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
config = {
- 'isolated': 1,
- 'safe_path': 1,
- 'use_environment': 0,
- 'user_site_directory': 0,
+ 'isolated': True,
+ 'safe_path': True,
+ 'use_environment': False,
+ 'user_site_directory': False,
}
self.check_all_configs("test_preinit_isolated1", config, api=API_COMPAT)
def test_preinit_isolated2(self):
# _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
config = {
- 'isolated': 1,
- 'safe_path': 1,
- 'use_environment': 0,
- 'user_site_directory': 0,
+ 'isolated': True,
+ 'safe_path': True,
+ 'use_environment': False,
+ 'user_site_directory': False,
}
self.check_all_configs("test_preinit_isolated2", config, api=API_COMPAT)
'orig_argv': ['python3', '-c', code, 'arg2'],
'program_name': './python3',
'run_command': code + '\n',
- 'parse_argv': 2,
+ 'parse_argv': True,
'sys_path_0': '',
}
self.check_all_configs("test_init_run_main", config, api=API_PYTHON)
'arg2'],
'program_name': './python3',
'run_command': code + '\n',
- 'parse_argv': 2,
+ 'parse_argv': True,
'_init_main': 0,
'sys_path_0': '',
}
def test_init_parse_argv(self):
config = {
- 'parse_argv': 2,
+ 'parse_argv': True,
'argv': ['-c', 'arg1', '-v', 'arg3'],
'orig_argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
'run_command': 'pass\n',
- 'use_environment': 0,
+ 'use_environment': False,
}
self.check_all_configs("test_init_parse_argv", config, api=API_PYTHON)
'parse_argv': 0,
}
config = {
- 'parse_argv': 0,
+ 'parse_argv': False,
'argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'orig_argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
'program_name': './argv0',
def test_init_use_frozen_modules(self):
tests = {
- ('=on', 1),
- ('=off', 0),
- ('=', 1),
- ('', 1),
+ ('=on', True),
+ ('=off', False),
+ ('=', True),
+ ('', True),
}
for raw, expected in tests:
optval = f'frozen_modules{raw}'
config = {
- 'parse_argv': 2,
+ 'parse_argv': True,
'argv': ['-c'],
'orig_argv': ['./argv0', '-X', optval, '-c', 'pass'],
'program_name': './argv0',
'run_command': 'pass\n',
- 'use_environment': 1,
+ 'use_environment': True,
'xoptions': [optval],
'use_frozen_modules': expected,
}
sys.argv ['./argv0', '-E', 'arg1', 'arg2']
config program_name: ./argv0
config executable: {executable}
- config use_environment: 1
- config configure_c_stdio: 1
- config buffered_stdio: 0
+ config use_environment: True
+ config configure_c_stdio: True
+ config buffered_stdio: False
""").lstrip()
self.assertEqual(out, expected)
PyConfig_MEMBER_INT = 0,
PyConfig_MEMBER_UINT = 1,
PyConfig_MEMBER_ULONG = 2,
+ PyConfig_MEMBER_BOOL = 3,
PyConfig_MEMBER_WSTR = 10,
PyConfig_MEMBER_WSTR_OPT = 11,
#define SPEC(MEMBER, TYPE) \
{#MEMBER, offsetof(PyConfig, MEMBER), PyConfig_MEMBER_##TYPE}
+// Update _test_embed_set_config when adding new members
static const PyConfigSpec PYCONFIG_SPEC[] = {
SPEC(_config_init, UINT),
- SPEC(isolated, UINT),
- SPEC(use_environment, UINT),
- SPEC(dev_mode, UINT),
- SPEC(install_signal_handlers, UINT),
- SPEC(use_hash_seed, UINT),
+ SPEC(isolated, BOOL),
+ SPEC(use_environment, BOOL),
+ SPEC(dev_mode, BOOL),
+ SPEC(install_signal_handlers, BOOL),
+ SPEC(use_hash_seed, BOOL),
SPEC(hash_seed, ULONG),
- SPEC(faulthandler, UINT),
+ SPEC(faulthandler, BOOL),
SPEC(tracemalloc, UINT),
- SPEC(perf_profiling, UINT),
- SPEC(import_time, UINT),
- SPEC(code_debug_ranges, UINT),
- SPEC(show_ref_count, UINT),
- SPEC(dump_refs, UINT),
+ SPEC(perf_profiling, BOOL),
+ SPEC(import_time, BOOL),
+ SPEC(code_debug_ranges, BOOL),
+ SPEC(show_ref_count, BOOL),
+ SPEC(dump_refs, BOOL),
SPEC(dump_refs_file, WSTR_OPT),
- SPEC(malloc_stats, UINT),
+ SPEC(malloc_stats, BOOL),
SPEC(filesystem_encoding, WSTR),
SPEC(filesystem_errors, WSTR),
SPEC(pycache_prefix, WSTR_OPT),
- SPEC(parse_argv, UINT),
+ SPEC(parse_argv, BOOL),
SPEC(orig_argv, WSTR_LIST),
SPEC(argv, WSTR_LIST),
SPEC(xoptions, WSTR_LIST),
SPEC(warnoptions, WSTR_LIST),
- SPEC(site_import, UINT),
+ SPEC(site_import, BOOL),
SPEC(bytes_warning, UINT),
- SPEC(warn_default_encoding, UINT),
- SPEC(inspect, UINT),
- SPEC(interactive, UINT),
+ SPEC(warn_default_encoding, BOOL),
+ SPEC(inspect, BOOL),
+ SPEC(interactive, BOOL),
SPEC(optimization_level, UINT),
- SPEC(parser_debug, UINT),
- SPEC(write_bytecode, UINT),
+ SPEC(parser_debug, BOOL),
+ SPEC(write_bytecode, BOOL),
SPEC(verbose, UINT),
- SPEC(quiet, UINT),
- SPEC(user_site_directory, UINT),
- SPEC(configure_c_stdio, UINT),
- SPEC(buffered_stdio, UINT),
+ SPEC(quiet, BOOL),
+ SPEC(user_site_directory, BOOL),
+ SPEC(configure_c_stdio, BOOL),
+ SPEC(buffered_stdio, BOOL),
SPEC(stdio_encoding, WSTR),
SPEC(stdio_errors, WSTR),
#ifdef MS_WINDOWS
- SPEC(legacy_windows_stdio, UINT),
+ SPEC(legacy_windows_stdio, BOOL),
#endif
SPEC(check_hash_pycs_mode, WSTR),
- SPEC(use_frozen_modules, UINT),
- SPEC(safe_path, UINT),
+ SPEC(use_frozen_modules, BOOL),
+ SPEC(safe_path, BOOL),
SPEC(int_max_str_digits, INT),
SPEC(cpu_count, INT),
- SPEC(pathconfig_warnings, UINT),
+ SPEC(pathconfig_warnings, BOOL),
SPEC(program_name, WSTR),
SPEC(pythonpath_env, WSTR_OPT),
SPEC(home, WSTR_OPT),
SPEC(platlibdir, WSTR),
SPEC(sys_path_0, WSTR_OPT),
- SPEC(module_search_paths_set, UINT),
+ SPEC(module_search_paths_set, BOOL),
SPEC(module_search_paths, WSTR_LIST),
SPEC(stdlib_dir, WSTR_OPT),
SPEC(executable, WSTR_OPT),
SPEC(base_prefix, WSTR_OPT),
SPEC(exec_prefix, WSTR_OPT),
SPEC(base_exec_prefix, WSTR_OPT),
- SPEC(skip_source_first_line, UINT),
+ SPEC(skip_source_first_line, BOOL),
SPEC(run_command, WSTR_OPT),
SPEC(run_module, WSTR_OPT),
SPEC(run_filename, WSTR_OPT),
- SPEC(_install_importlib, UINT),
- SPEC(_init_main, UINT),
- SPEC(_is_python_build, UINT),
+ SPEC(_install_importlib, BOOL),
+ SPEC(_init_main, BOOL),
+ SPEC(_is_python_build, BOOL),
#ifdef Py_STATS
- SPEC(_pystats, UINT),
+ SPEC(_pystats, BOOL),
#endif
#ifdef Py_DEBUG
SPEC(run_presite, WSTR_OPT),
switch (spec->type) {
case PyConfig_MEMBER_INT:
case PyConfig_MEMBER_UINT:
+ case PyConfig_MEMBER_BOOL:
{
*(int*)member = *(int*)member2;
break;
obj = PyLong_FromLong(value);
break;
}
+ case PyConfig_MEMBER_BOOL:
+ {
+ int value = *(int*)member;
+ obj = PyBool_FromLong(value);
+ break;
+ }
case PyConfig_MEMBER_ULONG:
{
unsigned long value = *(unsigned long*)member;
char *member = (char *)config + spec->offset;
switch (spec->type) {
case PyConfig_MEMBER_INT:
- if (config_dict_get_int(dict, spec->name, (int*)member) < 0) {
- return -1;
- }
- break;
case PyConfig_MEMBER_UINT:
+ case PyConfig_MEMBER_BOOL:
{
int value;
if (config_dict_get_int(dict, spec->name, &value) < 0) {
return -1;
}
- if (value < 0) {
- config_dict_invalid_value(spec->name);
- return -1;
+ if (spec->type == PyConfig_MEMBER_BOOL
+ || spec->type == PyConfig_MEMBER_UINT)
+ {
+ if (value < 0) {
+ config_dict_invalid_value(spec->name);
+ return -1;
+ }
}
*(int*)member = value;
break;