forked from astral-sh/python-build-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-tkinter-3.13.patch
129 lines (122 loc) · 3.95 KB
/
patch-tkinter-3.13.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 45897817a56..5633187730a 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -26,9 +26,8 @@ Copyright (C) 1994 Steen Lumholt.
#endif
#include "Python.h"
-#ifdef MS_WINDOWS
-# include "pycore_fileutils.h" // _Py_stat()
-#endif
+
+#include "pycore_fileutils.h" // _Py_stat()
#include "pycore_long.h" // _PyLong_IsNegative()
@@ -132,6 +131,7 @@ typedef int Tcl_Size;
#ifdef MS_WINDOWS
#include <conio.h>
#define WAIT_FOR_STDIN
+#endif
static PyObject *
_get_tcl_lib_path(void)
@@ -148,6 +148,7 @@ _get_tcl_lib_path(void)
return NULL;
}
+#ifdef MS_WINDOWS
/* Check expected location for an installed Python first */
tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION);
if (tcl_library_path == NULL) {
@@ -185,11 +186,31 @@ _get_tcl_lib_path(void)
tcl_library_path = NULL;
#endif
}
+#else
+ /* Check expected location for an installed Python first */
+ tcl_library_path = PyUnicode_FromString("/lib/tcl" TCL_VERSION);
+ if (tcl_library_path == NULL) {
+ return NULL;
+ }
+ tcl_library_path = PyUnicode_Concat(prefix, tcl_library_path);
+ if (tcl_library_path == NULL) {
+ return NULL;
+ }
+ stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
+ if (stat_return_value == -2) {
+ return NULL;
+ }
+ if (stat_return_value == -1) {
+ /* install location doesn't exist, reset errno and leave Tcl
+ to its own devices */
+ errno = 0;
+ tcl_library_path = NULL;
+ }
+#endif
already_checked = 1;
}
return tcl_library_path;
}
-#endif /* MS_WINDOWS */
/* The threading situation is complicated. Tcl is not thread-safe, except
when configured with --enable-threads.
@@ -710,6 +731,30 @@ Tkapp_New(const char *screenName, const char *className,
ret = GetEnvironmentVariableW(L"TCL_LIBRARY", NULL, 0);
if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
+ str_path = _get_tcl_lib_path();
+ if (str_path == NULL && PyErr_Occurred()) {
+ return NULL;
+ }
+ if (str_path != NULL) {
+ utf8_path = PyUnicode_AsUTF8String(str_path);
+ if (utf8_path == NULL) {
+ return NULL;
+ }
+ Tcl_SetVar(v->interp,
+ "tcl_library",
+ PyBytes_AS_STRING(utf8_path),
+ TCL_GLOBAL_ONLY);
+ Py_DECREF(utf8_path);
+ }
+ }
+ }
+#else
+ {
+ const char *env_val = getenv("TCL_LIBRARY");
+ if (!env_val) {
+ PyObject *str_path;
+ PyObject *utf8_path;
+
str_path = _get_tcl_lib_path();
if (str_path == NULL && PyErr_Occurred()) {
return NULL;
@@ -3552,7 +3597,32 @@ PyInit__tkinter(void)
PyMem_Free(wcs_path);
}
#else
+ int set_var = 0;
+ PyObject *str_path;
+ char *path;
+
+ if (!getenv("TCL_LIBRARY")) {
+ str_path = _get_tcl_lib_path();
+ if (str_path == NULL && PyErr_Occurred()) {
+ Py_DECREF(m);
+ return NULL;
+ }
+ if (str_path != NULL) {
+ path = PyUnicode_AsUTF8(str_path);
+ if (path == NULL) {
+ Py_DECREF(m);
+ return NULL;
+ }
+ setenv("TCL_LIBRARY", path, 1);
+ set_var = 1;
+ }
+ }
+
Tcl_FindExecutable(PyBytes_AS_STRING(cexe));
+
+ if (set_var) {
+ unsetenv("TCL_LIBRARY");
+ }
#endif /* MS_WINDOWS */
}
Py_XDECREF(cexe);