Skip to content

Commit e8d7661

Browse files
GH-91173: disable frozen modules in debug builds (#92023)
1 parent 48c6165 commit e8d7661

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

Lib/test/test_embed.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
MS_WINDOWS = (os.name == 'nt')
2424
MACOS = (sys.platform == 'darwin')
25-
25+
Py_DEBUG = hasattr(sys, 'gettotalrefcount')
2626
PYMEM_ALLOCATOR_NOT_SET = 0
2727
PYMEM_ALLOCATOR_DEBUG = 2
2828
PYMEM_ALLOCATOR_MALLOC = 3
@@ -478,7 +478,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
478478
'pathconfig_warnings': 1,
479479
'_init_main': 1,
480480
'_isolated_interpreter': 0,
481-
'use_frozen_modules': 1,
481+
'use_frozen_modules': not Py_DEBUG,
482482
'_is_python_build': IGNORE_CONFIG,
483483
}
484484
if MS_WINDOWS:
@@ -1177,7 +1177,7 @@ def test_init_setpath_config(self):
11771177
# The current getpath.c doesn't determine the stdlib dir
11781178
# in this case.
11791179
'stdlib_dir': '',
1180-
'use_frozen_modules': 1,
1180+
'use_frozen_modules': not Py_DEBUG,
11811181
# overridden by PyConfig
11821182
'program_name': 'conf_program_name',
11831183
'base_executable': 'conf_executable',
@@ -1416,12 +1416,12 @@ def test_init_pyvenv_cfg(self):
14161416
config['base_prefix'] = pyvenv_home
14171417
config['prefix'] = pyvenv_home
14181418
config['stdlib_dir'] = os.path.join(pyvenv_home, 'Lib')
1419-
config['use_frozen_modules'] = 1
1419+
config['use_frozen_modules'] = not Py_DEBUG
14201420
else:
14211421
# cannot reliably assume stdlib_dir here because it
14221422
# depends too much on our build. But it ought to be found
14231423
config['stdlib_dir'] = self.IGNORE_CONFIG
1424-
config['use_frozen_modules'] = 1
1424+
config['use_frozen_modules'] = not Py_DEBUG
14251425

14261426
env = self.copy_paths_by_env(config)
14271427
self.check_all_configs("test_init_compat_config", config,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable frozen modules in debug builds. Patch by Kumar Aditya.

Python/initconfig.c

+21-20
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,11 @@ _PyConfig_InitCompatConfig(PyConfig *config)
732732
#ifdef MS_WINDOWS
733733
config->legacy_windows_stdio = -1;
734734
#endif
735-
config->use_frozen_modules = -1;
735+
#ifdef Py_DEBUG
736+
config->use_frozen_modules = 0;
737+
#else
738+
config->use_frozen_modules = 1;
739+
#endif
736740
config->_is_python_build = 0;
737741
config->code_debug_ranges = 1;
738742
}
@@ -1978,25 +1982,22 @@ config_init_import(PyConfig *config, int compute_path_config)
19781982
}
19791983

19801984
/* -X frozen_modules=[on|off] */
1981-
if (config->use_frozen_modules < 0) {
1982-
const wchar_t *value = config_get_xoption_value(config, L"frozen_modules");
1983-
if (value == NULL) {
1984-
config->use_frozen_modules = !config->_is_python_build;
1985-
}
1986-
else if (wcscmp(value, L"on") == 0) {
1987-
config->use_frozen_modules = 1;
1988-
}
1989-
else if (wcscmp(value, L"off") == 0) {
1990-
config->use_frozen_modules = 0;
1991-
}
1992-
else if (wcslen(value) == 0) {
1993-
// "-X frozen_modules" and "-X frozen_modules=" both imply "on".
1994-
config->use_frozen_modules = 1;
1995-
}
1996-
else {
1997-
return PyStatus_Error("bad value for option -X frozen_modules "
1998-
"(expected \"on\" or \"off\")");
1999-
}
1985+
const wchar_t *value = config_get_xoption_value(config, L"frozen_modules");
1986+
if (value == NULL) {
1987+
}
1988+
else if (wcscmp(value, L"on") == 0) {
1989+
config->use_frozen_modules = 1;
1990+
}
1991+
else if (wcscmp(value, L"off") == 0) {
1992+
config->use_frozen_modules = 0;
1993+
}
1994+
else if (wcslen(value) == 0) {
1995+
// "-X frozen_modules" and "-X frozen_modules=" both imply "on".
1996+
config->use_frozen_modules = 1;
1997+
}
1998+
else {
1999+
return PyStatus_Error("bad value for option -X frozen_modules "
2000+
"(expected \"on\" or \"off\")");
20002001
}
20012002

20022003
return _PyStatus_OK();

0 commit comments

Comments
 (0)