Skip to content

GH-91173: disable frozen modules in debug builds #92023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

MS_WINDOWS = (os.name == 'nt')
MACOS = (sys.platform == 'darwin')

Py_DEBUG = hasattr(sys, 'gettotalrefcount')
PYMEM_ALLOCATOR_NOT_SET = 0
PYMEM_ALLOCATOR_DEBUG = 2
PYMEM_ALLOCATOR_MALLOC = 3
Expand Down Expand Up @@ -464,7 +464,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
'pathconfig_warnings': 1,
'_init_main': 1,
'_isolated_interpreter': 0,
'use_frozen_modules': 1,
'use_frozen_modules': not Py_DEBUG,
'_is_python_build': IGNORE_CONFIG,
}
if MS_WINDOWS:
Expand Down Expand Up @@ -1163,7 +1163,7 @@ def test_init_setpath_config(self):
# The current getpath.c doesn't determine the stdlib dir
# in this case.
'stdlib_dir': '',
'use_frozen_modules': 1,
'use_frozen_modules': not Py_DEBUG,
# overridden by PyConfig
'program_name': 'conf_program_name',
'base_executable': 'conf_executable',
Expand Down Expand Up @@ -1402,12 +1402,12 @@ def test_init_pyvenv_cfg(self):
config['base_prefix'] = pyvenv_home
config['prefix'] = pyvenv_home
config['stdlib_dir'] = os.path.join(pyvenv_home, 'Lib')
config['use_frozen_modules'] = 1
config['use_frozen_modules'] = not Py_DEBUG
else:
# cannot reliably assume stdlib_dir here because it
# depends too much on our build. But it ought to be found
config['stdlib_dir'] = self.IGNORE_CONFIG
config['use_frozen_modules'] = 1
config['use_frozen_modules'] = not Py_DEBUG

env = self.copy_paths_by_env(config)
self.check_all_configs("test_init_compat_config", config,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable frozen modules in debug builds. Patch by Kumar Aditya.
41 changes: 21 additions & 20 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,11 @@ _PyConfig_InitCompatConfig(PyConfig *config)
#ifdef MS_WINDOWS
config->legacy_windows_stdio = -1;
#endif
config->use_frozen_modules = -1;
#ifdef Py_DEBUG
config->use_frozen_modules = 0;
#else
config->use_frozen_modules = 1;
#endif
config->_is_python_build = 0;
config->code_debug_ranges = 1;
}
Expand Down Expand Up @@ -1978,25 +1982,22 @@ config_init_import(PyConfig *config, int compute_path_config)
}

/* -X frozen_modules=[on|off] */
if (config->use_frozen_modules < 0) {
const wchar_t *value = config_get_xoption_value(config, L"frozen_modules");
if (value == NULL) {
config->use_frozen_modules = !config->_is_python_build;
}
else if (wcscmp(value, L"on") == 0) {
config->use_frozen_modules = 1;
}
else if (wcscmp(value, L"off") == 0) {
config->use_frozen_modules = 0;
}
else if (wcslen(value) == 0) {
// "-X frozen_modules" and "-X frozen_modules=" both imply "on".
config->use_frozen_modules = 1;
}
else {
return PyStatus_Error("bad value for option -X frozen_modules "
"(expected \"on\" or \"off\")");
}
const wchar_t *value = config_get_xoption_value(config, L"frozen_modules");
if (value == NULL) {
}
else if (wcscmp(value, L"on") == 0) {
config->use_frozen_modules = 1;
}
else if (wcscmp(value, L"off") == 0) {
config->use_frozen_modules = 0;
}
else if (wcslen(value) == 0) {
// "-X frozen_modules" and "-X frozen_modules=" both imply "on".
config->use_frozen_modules = 1;
}
else {
return PyStatus_Error("bad value for option -X frozen_modules "
"(expected \"on\" or \"off\")");
}

return _PyStatus_OK();
Expand Down