From 8aba3a87038fb301418a6ec4f18d500ed8228862 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 28 Apr 2022 15:11:32 +0000 Subject: [PATCH 1/4] GH-91173: disable frozen modules in debug builds --- Python/initconfig.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Python/initconfig.c b/Python/initconfig.c index 729f7f393a39b5..f4d52180a9f18e 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -1981,7 +1981,11 @@ config_init_import(PyConfig *config, int compute_path_config) 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; +#ifdef Py_DEBUG + config->use_frozen_modules = 0; +#else + config->use_frozen_modules = 1; +#endif } else if (wcscmp(value, L"on") == 0) { config->use_frozen_modules = 1; From c2d677258abc180f51212a16f121846455b07cb5 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 2 May 2022 12:25:23 +0000 Subject: [PATCH 2/4] rework --- Lib/test/test_embed.py | 10 +++++----- Python/initconfig.c | 43 ++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py index 16d1c7dea6b4fa..951a6a9eb92bd5 100644 --- a/Lib/test/test_embed.py +++ b/Lib/test/test_embed.py @@ -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 @@ -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: @@ -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', @@ -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, diff --git a/Python/initconfig.c b/Python/initconfig.c index f4d52180a9f18e..5052169db9ed9d 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -732,7 +732,11 @@ _PyConfig_InitCompatConfig(PyConfig *config) #ifdef MS_WINDOWS config->legacy_windows_stdio = -1; #endif +#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; } @@ -1978,29 +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) { -#ifdef Py_DEBUG - config->use_frozen_modules = 0; -#else - config->use_frozen_modules = 1; -#endif - } - 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(); From a5e9e9cd21a84ecdf7dbc9768659509d1708b622 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 2 May 2022 12:35:57 +0000 Subject: [PATCH 3/4] fix release builds --- Python/initconfig.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/initconfig.c b/Python/initconfig.c index 5052169db9ed9d..d928ebe88553a3 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -735,7 +735,7 @@ _PyConfig_InitCompatConfig(PyConfig *config) #ifdef Py_DEBUG config->use_frozen_modules = 0; #else - config->use_frozen_modules = -1; + config->use_frozen_modules = 1; #endif config->_is_python_build = 0; config->code_debug_ranges = 1; From e86e2b4a22c168de9c482d6a5e6670eeacf746b0 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 2 May 2022 12:40:19 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022-05-02-12-40-18.gh-issue-91173.k_Dr6z.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-05-02-12-40-18.gh-issue-91173.k_Dr6z.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-05-02-12-40-18.gh-issue-91173.k_Dr6z.rst b/Misc/NEWS.d/next/Core and Builtins/2022-05-02-12-40-18.gh-issue-91173.k_Dr6z.rst new file mode 100644 index 00000000000000..fa7761381b3140 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-05-02-12-40-18.gh-issue-91173.k_Dr6z.rst @@ -0,0 +1 @@ +Disable frozen modules in debug builds. Patch by Kumar Aditya.