From 6ea84b2726bb6a1a8a6819d30c368ac34c50eabe Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 27 Feb 2026 10:02:19 +0200 Subject: [PATCH 1/2] Fix unlikely potential reference leak in _locale._getdefaultlocale (GH-145250) It occurs in a code which perhaps never executed. --- Modules/_localemodule.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 7174eebd0c94de..f0a418ee5024e3 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -567,7 +567,6 @@ _locale__getdefaultlocale_impl(PyObject *module) } /* cannot determine the language code (very unlikely) */ - Py_INCREF(Py_None); return Py_BuildValue("Os", Py_None, encoding); } #endif From 171e0facc4131f74baec38f58fb0971c52ac2c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AF=E5=87=9B?= <34085039+mokurin000@users.noreply.github.com> Date: Fri, 27 Feb 2026 18:06:46 +0800 Subject: [PATCH 2/2] gh-123853: Cleanup Windows 95 locale fallback support (#144738) Closes #123853 --- Lib/locale.py | 4 ---- .../2026-02-21-17-34-53.gh-issue-123853.6RUwWh.rst | 1 + Modules/_localemodule.c | 11 ----------- 3 files changed, 1 insertion(+), 15 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-02-21-17-34-53.gh-issue-123853.6RUwWh.rst diff --git a/Lib/locale.py b/Lib/locale.py index dea3ee55cf4d24..e7382796905ebd 100644 --- a/Lib/locale.py +++ b/Lib/locale.py @@ -570,10 +570,6 @@ def _getdefaultlocale(envvars=('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE')): except (ImportError, AttributeError): pass else: - # make sure the code/encoding values are valid - if sys.platform == "win32" and code and code[:2] == "0x": - # map windows language identifier to language name - code = windows_locale.get(int(code, 0)) # ...add other platform-specific processing here, if # necessary... return code, encoding diff --git a/Misc/NEWS.d/next/Library/2026-02-21-17-34-53.gh-issue-123853.6RUwWh.rst b/Misc/NEWS.d/next/Library/2026-02-21-17-34-53.gh-issue-123853.6RUwWh.rst new file mode 100644 index 00000000000000..1babcbfd8e678a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-21-17-34-53.gh-issue-123853.6RUwWh.rst @@ -0,0 +1 @@ +Removed Windows 95 compatibility for :func:`locale.getdefaultlocale`. diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index f0a418ee5024e3..86a390e52a554b 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -555,17 +555,6 @@ _locale__getdefaultlocale_impl(PyObject *module) return Py_BuildValue("ss", locale, encoding); } - /* If we end up here, this windows version didn't know about - ISO639/ISO3166 names (it's probably Windows 95). Return the - Windows language identifier instead (a hexadecimal number) */ - - locale[0] = '0'; - locale[1] = 'x'; - if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE, - locale+2, sizeof(locale)-2)) { - return Py_BuildValue("ss", locale, encoding); - } - /* cannot determine the language code (very unlikely) */ return Py_BuildValue("Os", Py_None, encoding); }