11diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
2- index 005036d3ff2..c130ed7b186 100644
2+ index 005036d3ff2..91289c16616 100644
33--- a/Modules/_tkinter.c
44+++ b/Modules/_tkinter.c
55@@ -28,9 +28,7 @@ Copyright (C) 1994 Steen Lumholt.
@@ -9,7 +9,7 @@ index 005036d3ff2..c130ed7b186 100644
99- #ifdef MS_WINDOWS
1010- # include "pycore_fileutils.h" // _Py_stat()
1111- #endif
12- + #include "pycore_fileutils.h" // _Py_stat()
12+ + #include "pycore_fileutils.h"
1313
1414 #ifdef MS_WINDOWS
1515 #include <windows.h>
@@ -21,15 +21,16 @@ index 005036d3ff2..c130ed7b186 100644
2121
2222 static PyObject *
2323 _get_tcl_lib_path()
24- @@ -140,6 +139,7 @@ _get_tcl_lib_path()
24+ @@ -139,7 +138,7 @@ _get_tcl_lib_path()
25+ if (prefix == NULL) {
2526 return NULL;
2627 }
27-
28+ -
2829+ #ifdef MS_WINDOWS
2930 /* Check expected location for an installed Python first */
3031 tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION);
3132 if (tcl_library_path == NULL) {
32- @@ -177,11 +177 ,31 @@ _get_tcl_lib_path()
33+ @@ -177,11 +176 ,31 @@ _get_tcl_lib_path()
3334 tcl_library_path = NULL;
3435 #endif
3536 }
@@ -62,7 +63,7 @@ index 005036d3ff2..c130ed7b186 100644
6263
6364 /* The threading situation is complicated. Tcl is not thread-safe, except
6465 when configured with --enable-threads.
65- @@ -687,6 +707 ,30 @@ Tkapp_New(const char *screenName, const char *className,
66+ @@ -687,6 +706 ,30 @@ Tkapp_New(const char *screenName, const char *className,
6667
6768 ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0);
6869 if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
@@ -93,7 +94,7 @@ index 005036d3ff2..c130ed7b186 100644
9394 str_path = _get_tcl_lib_path();
9495 if (str_path == NULL && PyErr_Occurred()) {
9596 return NULL;
96- @@ -3428,7 +3472,27 @@ PyInit__tkinter(void)
97+ @@ -3428,7 +3471,32 @@ PyInit__tkinter(void)
9798 PyMem_Free(wcs_path);
9899 }
99100 #else
@@ -108,6 +109,11 @@ index 005036d3ff2..c130ed7b186 100644
108109+ return NULL;
109110+ }
110111+ if (str_path != NULL) {
112+ + path = PyUnicode_AsUTF8(str_path);
113+ + if (path == NULL) {
114+ + Py_DECREF(m);
115+ + return NULL;
116+ + }
111117+ setenv("TCL_LIBRARY", path, 1);
112118+ set_var = 1;
113119+ }
0 commit comments