Skip to content

Commit

Permalink
Add patches for all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 16, 2024
1 parent b9e7b1d commit 20d138d
Show file tree
Hide file tree
Showing 6 changed files with 481 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build-macos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python3.12
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
Expand Down
14 changes: 10 additions & 4 deletions cpython-unix/build-cpython.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,18 @@ else
fi

# On Windows, CPython looks for the Tcl/Tk libraries relative to the base prefix,
# with we want. But on Unix, it doesn't. This patch applies similar behavior on Unix,
# which we want. But on Unix, it doesn't. This patch applies similar behavior on Unix,
# thereby ensuring that the Tcl/Tk libraries are found in the correct location.
# A similar patch could be applied to other CPython versions, but would require
# customizations for each minor.
if [ -n "${PYTHON_MEETS_MINIMUM_VERSION_3_13}" ]; then
if [ "${PYTHON_MAJMIN_VERSION}" = "3.13" ]; then
patch -p1 -i ${ROOT}/patch-tkinter-3.13.patch
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.12" ]; then
patch -p1 -i ${ROOT}/patch-tkinter-3.12.patch
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.11" ]; then
patch -p1 -i ${ROOT}/patch-tkinter-3.11.patch
elif [ "${PYTHON_MAJMIN_VERSION}" = "3.10" ]; then
patch -p1 -i ${ROOT}/patch-tkinter-3.10.patch
else
patch -p1 -i ${ROOT}/patch-tkinter-3.9.patch
fi

# Code that runs at ctypes module import time does not work with
Expand Down
112 changes: 112 additions & 0 deletions cpython-unix/patch-tkinter-3.10.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 2a3e65b6c97..b17c5bfd6b1 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -115,6 +115,7 @@ Copyright (C) 1994 Steen Lumholt.
#ifdef MS_WINDOWS
#include <conio.h>
#define WAIT_FOR_STDIN
+#endif

static PyObject *
_get_tcl_lib_path()
@@ -132,6 +133,7 @@ _get_tcl_lib_path()
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) {
@@ -169,11 +171,31 @@ _get_tcl_lib_path()
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.
@@ -822,6 +844,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;
@@ -3628,7 +3674,27 @@ 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) {
+ 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);
123 changes: 123 additions & 0 deletions cpython-unix/patch-tkinter-3.11.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 005036d3ff2..c130ed7b186 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -28,9 +28,7 @@ Copyright (C) 1994 Steen Lumholt.

#include "Python.h"
#include <ctype.h>
-#ifdef MS_WINDOWS
-# include "pycore_fileutils.h" // _Py_stat()
-#endif
+#include "pycore_fileutils.h" // _Py_stat()

#ifdef MS_WINDOWS
#include <windows.h>
@@ -123,6 +121,7 @@ Copyright (C) 1994 Steen Lumholt.
#ifdef MS_WINDOWS
#include <conio.h>
#define WAIT_FOR_STDIN
+#endif

static PyObject *
_get_tcl_lib_path()
@@ -140,6 +139,7 @@ _get_tcl_lib_path()
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) {
@@ -177,11 +177,31 @@ _get_tcl_lib_path()
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.
@@ -687,6 +707,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;
@@ -3428,7 +3472,27 @@ 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) {
+ 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);
123 changes: 123 additions & 0 deletions cpython-unix/patch-tkinter-3.12.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 6b5fcb8a365..99d44ccf1d8 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -28,9 +28,7 @@ Copyright (C) 1994 Steen Lumholt.

#include "Python.h"
#include <ctype.h>
-#ifdef MS_WINDOWS
-# include "pycore_fileutils.h" // _Py_stat()
-#endif
+#include "pycore_fileutils.h" // _Py_stat()

#include "pycore_long.h"

@@ -134,6 +132,7 @@ typedef int Tcl_Size;
#ifdef MS_WINDOWS
#include <conio.h>
#define WAIT_FOR_STDIN
+#endif

static PyObject *
_get_tcl_lib_path(void)
@@ -151,6 +150,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) {
@@ -188,11 +188,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.
@@ -713,6 +733,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;
@@ -3542,7 +3586,27 @@ 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) {
+ 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);
Loading

0 comments on commit 20d138d

Please sign in to comment.