From 059adad256a05d64fc9f3e95997857912272ea35 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Tue, 16 Dec 2025 09:13:10 -0600 Subject: [PATCH 01/13] Update to Tcl/Tk 9.0.3 Update Tcl/Tk 8.6.14 -> 9.0.3 --- cpython-unix/build-cpython.sh | 6 +++--- cpython-unix/build-tk.sh | 2 +- cpython-unix/build.py | 8 +++----- cpython-unix/extension-modules.yml | 4 ++-- pythonbuild/downloads.py | 22 ++++++++++++++++++++-- src/validation.rs | 15 ++++++++++----- 6 files changed, 39 insertions(+), 18 deletions(-) diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 2afeb134..4a65b5c0 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -1257,11 +1257,11 @@ fi # And prune libraries we never reference. rm -f ${ROOT}/out/python/build/lib/{libdb-6.0,libxcb-*,libX11-xcb}.a -if [ -d "${TOOLS_PATH}/deps/lib/tcl8" ]; then +if [ -d "${TOOLS_PATH}/deps/lib/tk9.0" ]; then # Copy tcl/tk resources needed by tkinter. - mkdir ${ROOT}/out/python/install/lib/tcl + mkdir ${ROOT}/out/python/install/lib/tk9.0 # Keep this list in sync with tcl_library_paths. - for source in ${TOOLS_PATH}/deps/lib/{itcl4.2.4,tcl8,tcl8.6,thread2.8.9,tk8.6}; do + for source in ${TOOLS_PATH}/deps/lib/{itcl4.3.5,thread3.0.4,tk9.0}; do cp -av $source ${ROOT}/out/python/install/lib/ done diff --git a/cpython-unix/build-tk.sh b/cpython-unix/build-tk.sh index ef13bedd..d827d572 100755 --- a/cpython-unix/build-tk.sh +++ b/cpython-unix/build-tk.sh @@ -48,7 +48,7 @@ if [[ "${PYBUILD_PLATFORM}" = macos* ]]; then else sed_args=(-i) fi -sed "${sed_args[@]}" 's/all: binaries libraries doc/all: libraries/' Makefile +sed "${sed_args[@]}" 's/all: binaries libraries/all: libraries/' Makefile sed "${sed_args[@]}" 's/install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE) ${WISH_EXE}/install-binaries: $(TK_STUB_LIB_FILE) $(TK_LIB_FILE)/' Makefile # We are statically linking libX11, and static libraries do not carry diff --git a/cpython-unix/build.py b/cpython-unix/build.py index fd9810c6..43894ecf 100755 --- a/cpython-unix/build.py +++ b/cpython-unix/build.py @@ -913,11 +913,9 @@ def build_cpython( python_info["tcl_library_path"] = "install/lib" python_info["tcl_library_paths"] = [ - "itcl4.2.4", - "tcl8", - "tcl8.6", - "thread2.8.7", - "tk8.6", + "itcl4.3.5", + "thread3.0.4", + "tk9.0", ] if "-apple" in target_triple: diff --git a/cpython-unix/extension-modules.yml b/cpython-unix/extension-modules.yml index 1fb0860d..1a57c461 100644 --- a/cpython-unix/extension-modules.yml +++ b/cpython-unix/extension-modules.yml @@ -664,8 +664,8 @@ _tkinter: - include/X11 build-mode: shared links: - - tcl8.6 - - tk8.6 + - tcl9.0 + - tcl9tk9.0 links-conditional: - name: X11 targets: diff --git a/pythonbuild/downloads.py b/pythonbuild/downloads.py index 7c2184e6..269fe5a6 100644 --- a/pythonbuild/downloads.py +++ b/pythonbuild/downloads.py @@ -317,7 +317,7 @@ "sha256": "ea451686065d6338d7e4d4a04c9af49f17951d15aa4c2e19ab8cb56fa2373440", "version": "5.38.2.2", }, - "tcl": { + "tcl-86": { "url": "https://prdownloads.sourceforge.net/tcl/tcl8.6.14-src.tar.gz", "size": 11627322, "sha256": "5880225babf7954c58d4fb0f5cf6279104ce1cd6aa9b71e9a6322540e1c4de66", @@ -326,6 +326,15 @@ "licenses": ["TCL"], "license_file": "LICENSE.tcl.txt", }, + "tcl": { + "url": "https://prdownloads.sourceforge.net/tcl/tcl9.0.3-src.tar.gz", + "size": 11922915, + "sha256": "2537ba0c86112c8c953f7c09d33f134dd45c0fb3a71f2d7f7691fd301d2c33a6", + "version": "9.0.3", + "library_names": ["tcl9.0"], + "licenses": ["TCL"], + "license_file": "LICENSE.tcl.txt", + }, "tix": { "url": "https://github.com/python/cpython-source-deps/archive/tix-8.4.3.6.tar.gz", "size": 1836451, @@ -334,7 +343,7 @@ "licenses": ["TCL"], "license_file": "LICENSE.tix.txt", }, - "tk": { + "tk-86": { "url": "https://prdownloads.sourceforge.net/tcl/tk8.6.14-src.tar.gz", "size": 4510695, "sha256": "8ffdb720f47a6ca6107eac2dd877e30b0ef7fac14f3a84ebbd0b3612cee41a94", @@ -343,6 +352,15 @@ "licenses": ["TCL"], "license_file": "LICENSE.tcl.txt", }, + "tk": { + "url": "https://prdownloads.sourceforge.net/tcl/tk9.0.3-src.tar.gz", + "size": 4644835, + "sha256": "bf344efadb618babb7933f69275620f72454d1c8220130da93e3f7feb0efbf9b", + "version": "9.0.3", + "library_names": ["tk9.0"], + "licenses": ["TCL"], + "license_file": "LICENSE.tcl.txt", + }, "tk-windows-bin": { "url": "https://github.com/python/cpython-bin-deps/archive/c624cc881bd0e5071dec9de4b120cbe9985d8c14.tar.gz", "size": 9497943, diff --git a/src/validation.rs b/src/validation.rs index 5886f1ea..46f9f441 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -286,7 +286,7 @@ static ELF_ALLOWED_LIBRARIES_BY_MODULE: Lazy> = Lazy::new(|| { max_compatibility_version: "1.0.0".try_into().unwrap(), required: true, }, + MachOAllowedDylib { + name: "/System/Library/Frameworks/Security.framework/Versions/A/Security".to_string(), + max_compatibility_version: "1.0.0".try_into().unwrap(), + required: true, + }, MachOAllowedDylib { name: "/usr/lib/libedit.3.dylib".to_string(), max_compatibility_version: "2.0.0".try_into().unwrap(), @@ -494,13 +499,13 @@ static ALLOWED_DYLIBS_BY_MODULE: Lazy Date: Wed, 17 Dec 2025 16:55:34 -0600 Subject: [PATCH 02/13] add no libtommath patch for 3.11 and 3.10 --- cpython-unix/build-cpython.sh | 7 +++++++ cpython-unix/patch-tkinter-for-no-libtommath.patch | 14 ++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 cpython-unix/patch-tkinter-for-no-libtommath.patch diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 4a65b5c0..e3f08fe4 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -281,6 +281,13 @@ if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then patch -p1 -i ${ROOT}/patch-configure-crypt-no-modify-libs.patch fi +# CPython <3.12 expects an external libtommath. Backport +# https://github.com/python/cpython/pull/103842 to avoid this behavior. +# TODO(jjh): Other changes from https://github.com/python/cpython/issues/103194 +if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_11}" ]; then + patch -p1 -i ${ROOT}/patch-tkinter-for-no-libtommath.patch +fi + # BOLT instrumented binaries segfault in some test_embed tests for unknown reasons. # On 3.12 (minimum BOLT version), the segfault causes the test harness to # abort and BOLT optimization uses the partial test results. On 3.13, the segfault diff --git a/cpython-unix/patch-tkinter-for-no-libtommath.patch b/cpython-unix/patch-tkinter-for-no-libtommath.patch new file mode 100644 index 00000000..7da62545 --- /dev/null +++ b/cpython-unix/patch-tkinter-for-no-libtommath.patch @@ -0,0 +1,14 @@ +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 005036d3ff2..f58fd5b6764 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -58,6 +58,9 @@ Copyright (C) 1994 Steen Lumholt. + #error "Tk older than 8.5.12 not supported" + #endif + ++#ifndef TCL_WITH_EXTERNAL_TOMMATH ++#define TCL_NO_TOMMATH_H ++#endif + #include + + #if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) From 06fbe943d5a2ab45140327576b9eeb1734d0db0d Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Thu, 18 Dec 2025 12:47:16 -0600 Subject: [PATCH 03/13] backport Tcl/tk 9 tkinter support to 3.10, 3.11 --- ...building-Tkinter-against-Tcl-8.7-310.patch | 37 ++++ ...building-Tkinter-against-Tcl-8.7-311.patch | 37 ++++ ...se-newer-libtommath-APIs-when-ne-310.patch | 83 +++++++++ ...se-newer-libtommath-APIs-when-ne-311.patch | 29 +++ ...ix-Tkinter-s-Tcl-value-type-hand-310.patch | 134 ++++++++++++++ ...ix-Tkinter-s-Tcl-value-type-hand-311.patch | 132 ++++++++++++++ ...ix-builtin-Tkinter-with-Tcl-9.0--310.patch | 165 ++++++++++++++++++ ...ix-builtin-Tkinter-with-Tcl-9.0--311.patch | 163 +++++++++++++++++ cpython-unix/build-cpython.sh | 25 ++- 9 files changed, 801 insertions(+), 4 deletions(-) create mode 100644 cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch create mode 100644 cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch create mode 100644 cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch create mode 100644 cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch create mode 100644 cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch create mode 100644 cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch create mode 100644 cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch create mode 100644 cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch diff --git a/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch b/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch new file mode 100644 index 00000000..a1de5120 --- /dev/null +++ b/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch @@ -0,0 +1,37 @@ +From 5ea21ecc7ea3a8798be250566fe44fe11e8a98f8 Mon Sep 17 00:00:00 2001 +From: Christopher Chavez +Date: Fri, 19 May 2023 14:09:59 -0500 +Subject: [3.10] gh-103839: Allow building Tkinter against Tcl 8.7 without + external libtommath (GH-103842) + +--- + .../Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst | 2 ++ + Modules/_tkinter.c | 3 +++ + 2 files changed, 5 insertions(+) + create mode 100644 Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst + +diff --git a/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst +new file mode 100644 +index 00000000000..1d40a8fbcd3 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst +@@ -0,0 +1,2 @@ ++Avoid compilation error due to tommath.h not being found when building ++Tkinter against Tcl 8.7 built with bundled libtommath. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 2a3e65b6c97..6aa7e6d7da1 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -55,6 +55,9 @@ Copyright (C) 1994 Steen Lumholt. + #if TK_HEX_VERSION >= 0x08050208 && TK_HEX_VERSION < 0x08060000 || \ + TK_HEX_VERSION >= 0x08060200 + #define HAVE_LIBTOMMATH ++#ifndef TCL_WITH_EXTERNAL_TOMMATH ++#define TCL_NO_TOMMATH_H ++#endif + #include + #endif + +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch b/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch new file mode 100644 index 00000000..f666bcd8 --- /dev/null +++ b/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch @@ -0,0 +1,37 @@ +From e8111a757ceb83f6bf607912a55441ef3cdccb67 Mon Sep 17 00:00:00 2001 +From: Christopher Chavez +Date: Fri, 19 May 2023 14:09:59 -0500 +Subject: [3.11] gh-103839: Allow building Tkinter against Tcl 8.7 without + external libtommath (GH-103842) + +--- + .../Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst | 2 ++ + Modules/_tkinter.c | 3 +++ + 2 files changed, 5 insertions(+) + create mode 100644 Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst + +diff --git a/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst +new file mode 100644 +index 00000000000..1d40a8fbcd3 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst +@@ -0,0 +1,2 @@ ++Avoid compilation error due to tommath.h not being found when building ++Tkinter against Tcl 8.7 built with bundled libtommath. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 005036d3ff2..f58fd5b6764 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -58,6 +58,9 @@ Copyright (C) 1994 Steen Lumholt. + #error "Tk older than 8.5.12 not supported" + #endif + ++#ifndef TCL_WITH_EXTERNAL_TOMMATH ++#define TCL_NO_TOMMATH_H ++#endif + #include + + #if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch b/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch new file mode 100644 index 00000000..45892d5e --- /dev/null +++ b/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch @@ -0,0 +1,83 @@ +From 519ea464f0bb64c6db3b11aca5a892c48a4f9627 Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Tue, 6 Jun 2023 07:01:28 -0700 +Subject: [3.10] [3.12] gh-104399: Use newer libtommath APIs when necessary + (GH-104407) (#105343) + +gh-104399: Use newer libtommath APIs when necessary (GH-104407) +(cherry picked from commit 00d73caf804c0474980e471347d6385757af975f) + +Co-authored-by: Christopher Chavez +--- + ...-05-11-23-03-00.gh-issue-104399.MMatTP.rst | 4 ++++ + Modules/_tkinter.c | 23 +++++++++++++++++-- + 2 files changed, 25 insertions(+), 2 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst + +diff --git a/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst +new file mode 100644 +index 00000000000..84cc888635b +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst +@@ -0,0 +1,4 @@ ++Prepare the ``_tkinter`` module for building with Tcl 9.0 and future ++libtommath by replacing usage of deprecated functions ++:c:func:`mp_to_unsigned_bin_n` and :c:func:`mp_unsigned_bin_size` ++when necessary. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 6aa7e6d7da1..61296c8668a 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -61,6 +61,12 @@ Copyright (C) 1994 Steen Lumholt. + #include + #endif + ++#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) ++#define USE_DEPRECATED_TOMMATH_API 0 ++#else ++#define USE_DEPRECATED_TOMMATH_API 1 ++#endif ++ + #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) + #define HAVE_CREATEFILEHANDLER + #endif +@@ -1232,20 +1238,33 @@ static PyObject* + fromBignumObj(TkappObject *tkapp, Tcl_Obj *value) + { + mp_int bigValue; ++ mp_err err; ++#if USE_DEPRECATED_TOMMATH_API + unsigned long numBytes; ++#else ++ size_t numBytes; ++#endif + unsigned char *bytes; + PyObject *res; + + if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK) + return Tkinter_Error(tkapp); ++#if USE_DEPRECATED_TOMMATH_API + numBytes = mp_unsigned_bin_size(&bigValue); ++#else ++ numBytes = mp_ubin_size(&bigValue); ++#endif + bytes = PyMem_Malloc(numBytes); + if (bytes == NULL) { + mp_clear(&bigValue); + return PyErr_NoMemory(); + } +- if (mp_to_unsigned_bin_n(&bigValue, bytes, +- &numBytes) != MP_OKAY) { ++#if USE_DEPRECATED_TOMMATH_API ++ err = mp_to_unsigned_bin_n(&bigValue, bytes, &numBytes); ++#else ++ err = mp_to_ubin(&bigValue, bytes, numBytes, NULL); ++#endif ++ if (err != MP_OKAY) { + mp_clear(&bigValue); + PyMem_Free(bytes); + return PyErr_NoMemory(); +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch b/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch new file mode 100644 index 00000000..a473fd1c --- /dev/null +++ b/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch @@ -0,0 +1,29 @@ +From 348e6959bc324550b5dafda24d69d1dbba9c1e5e Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Tue, 6 Jun 2023 07:01:28 -0700 +Subject: [3.11] [3.12] gh-104399: Use newer libtommath APIs when necessary + (GH-104407) (#105343) + +gh-104399: Use newer libtommath APIs when necessary (GH-104407) +(cherry picked from commit 00d73caf804c0474980e471347d6385757af975f) + +Co-authored-by: Christopher Chavez +--- + .../Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst | 4 ++++ + 1 file changed, 4 insertions(+) + create mode 100644 Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst + +diff --git a/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst +new file mode 100644 +index 00000000000..84cc888635b +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst +@@ -0,0 +1,4 @@ ++Prepare the ``_tkinter`` module for building with Tcl 9.0 and future ++libtommath by replacing usage of deprecated functions ++:c:func:`mp_to_unsigned_bin_n` and :c:func:`mp_unsigned_bin_size` ++when necessary. +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch b/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch new file mode 100644 index 00000000..dfe4d89d --- /dev/null +++ b/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch @@ -0,0 +1,134 @@ +From c64d272d4ba410296a9b6df3a256b767c1d61c46 Mon Sep 17 00:00:00 2001 +From: Serhiy Storchaka +Date: Fri, 31 May 2024 12:15:53 +0300 +Subject: [3.10] =?UTF-8?q?[3.12]=20gh-103194:=20Fix=20Tkinter=E2=80=99s=20?= + =?UTF-8?q?Tcl=20value=20type=20handling=20for=20Tcl=208.7/9.0=20(GH-10384?= + =?UTF-8?q?6)=20(GH-119831)?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some of standard Tcl types were renamed, removed, or no longer +registered in Tcl 8.7/9.0. This change fixes automatic conversion of Tcl +values to Python values to avoid returning a Tcl_Obj where the primary +Python types (int, bool, str, bytes) were returned in older Tcl. +(cherry picked from commit 94e9585e99abc2d060cedc77b3c03e06b4a0a9c4) + +Co-authored-by: Christopher Chavez +--- + ...-04-24-05-34-23.gh-issue-103194.GwBwWL.rst | 4 ++ + Modules/_tkinter.c | 56 +++++++++++-------- + 2 files changed, 36 insertions(+), 24 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst + +diff --git a/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst +new file mode 100644 +index 00000000000..3f70168b810 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst +@@ -0,0 +1,4 @@ ++Prepare Tkinter for C API changes in Tcl 8.7/9.0 to avoid ++:class:`_tkinter.Tcl_Obj` being unexpectedly returned ++instead of :class:`bool`, :class:`str`, ++:class:`bytearray`, or :class:`int`. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 61296c8668a..dee90d6bc27 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -317,6 +317,7 @@ typedef struct { + const Tcl_ObjType *ListType; + const Tcl_ObjType *ProcBodyType; + const Tcl_ObjType *StringType; ++ const Tcl_ObjType *UTF32StringType; + } TkappObject; + + #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) +@@ -745,15 +746,41 @@ Tkapp_New(const char *screenName, const char *className, + } + + v->OldBooleanType = Tcl_GetObjType("boolean"); +- v->BooleanType = Tcl_GetObjType("booleanString"); +- v->ByteArrayType = Tcl_GetObjType("bytearray"); ++ { ++ Tcl_Obj *value; ++ int boolValue; ++ ++ /* Tcl 8.5 "booleanString" type is not registered ++ and is renamed to "boolean" in Tcl 9.0. ++ Based on approach suggested at ++ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */ ++ value = Tcl_NewStringObj("true", -1); ++ Tcl_GetBooleanFromObj(NULL, value, &boolValue); ++ v->BooleanType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ ++ // "bytearray" type is not registered in Tcl 9.0 ++ value = Tcl_NewByteArrayObj(NULL, 0); ++ v->ByteArrayType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->DoubleType = Tcl_GetObjType("double"); ++ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int") ++ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7 ++ only uses the "wideInt" type on platforms with 32-bit long, it still has ++ a registered "int" type, which FromObj() should recognize just in case. */ + v->IntType = Tcl_GetObjType("int"); ++ if (v->IntType == NULL) { ++ Tcl_Obj *value = Tcl_NewIntObj(0); ++ v->IntType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->WideIntType = Tcl_GetObjType("wideInt"); + v->BignumType = Tcl_GetObjType("bignum"); + v->ListType = Tcl_GetObjType("list"); + v->ProcBodyType = Tcl_GetObjType("procbody"); + v->StringType = Tcl_GetObjType("string"); ++ v->UTF32StringType = Tcl_GetObjType("utf32string"); + + /* Delete the 'exit' command, which can screw things up */ + Tcl_DeleteCommand(v->interp, "exit"); +@@ -1308,14 +1335,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return PyFloat_FromDouble(value->internalRep.doubleValue); + } + +- if (value->typePtr == tkapp->IntType) { +- long longValue; +- if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) +- return PyLong_FromLong(longValue); +- /* If there is an error in the long conversion, +- fall through to wideInt handling. */ +- } +- + if (value->typePtr == tkapp->IntType || + value->typePtr == tkapp->WideIntType) { + result = fromWideIntObj(tkapp, value); +@@ -1362,23 +1381,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return result; + } + +- if (value->typePtr == tkapp->ProcBodyType) { +- /* fall through: return tcl object. */ +- } +- +- if (value->typePtr == tkapp->StringType) { ++ if (value->typePtr == tkapp->StringType || ++ value->typePtr == tkapp->UTF32StringType) ++ { + return unicodeFromTclObj(value); + } + +-#if TK_HEX_VERSION >= 0x08050000 +- if (tkapp->BooleanType == NULL && +- strcmp(value->typePtr->name, "booleanString") == 0) { +- /* booleanString type is not registered in Tcl */ +- tkapp->BooleanType = value->typePtr; +- return fromBoolean(tkapp, value); +- } +-#endif +- + #ifdef HAVE_LIBTOMMATH + if (tkapp->BignumType == NULL && + strcmp(value->typePtr->name, "bignum") == 0) { +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch b/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch new file mode 100644 index 00000000..e4c09f84 --- /dev/null +++ b/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch @@ -0,0 +1,132 @@ +From c47d167498e8c57e33d948f27227821fece31022 Mon Sep 17 00:00:00 2001 +From: Serhiy Storchaka +Date: Fri, 31 May 2024 12:15:53 +0300 +Subject: [3.11] =?UTF-8?q?[3.12]=20gh-103194:=20Fix=20Tkinter=E2=80=99s=20?= + =?UTF-8?q?Tcl=20value=20type=20handling=20for=20Tcl=208.7/9.0=20(GH-10384?= + =?UTF-8?q?6)=20(GH-119831)?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some of standard Tcl types were renamed, removed, or no longer +registered in Tcl 8.7/9.0. This change fixes automatic conversion of Tcl +values to Python values to avoid returning a Tcl_Obj where the primary +Python types (int, bool, str, bytes) were returned in older Tcl. +(cherry picked from commit 94e9585e99abc2d060cedc77b3c03e06b4a0a9c4) + +Co-authored-by: Christopher Chavez +--- + ...-04-24-05-34-23.gh-issue-103194.GwBwWL.rst | 4 ++ + Modules/_tkinter.c | 54 +++++++++++-------- + 2 files changed, 36 insertions(+), 22 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst + +diff --git a/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst +new file mode 100644 +index 00000000000..3f70168b810 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst +@@ -0,0 +1,4 @@ ++Prepare Tkinter for C API changes in Tcl 8.7/9.0 to avoid ++:class:`_tkinter.Tcl_Obj` being unexpectedly returned ++instead of :class:`bool`, :class:`str`, ++:class:`bytearray`, or :class:`int`. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index f58fd5b6764..df8bc124926 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -319,6 +319,7 @@ typedef struct { + const Tcl_ObjType *ListType; + const Tcl_ObjType *ProcBodyType; + const Tcl_ObjType *StringType; ++ const Tcl_ObjType *UTF32StringType; + } TkappObject; + + #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) +@@ -604,15 +605,41 @@ Tkapp_New(const char *screenName, const char *className, + } + + v->OldBooleanType = Tcl_GetObjType("boolean"); +- v->BooleanType = Tcl_GetObjType("booleanString"); +- v->ByteArrayType = Tcl_GetObjType("bytearray"); ++ { ++ Tcl_Obj *value; ++ int boolValue; ++ ++ /* Tcl 8.5 "booleanString" type is not registered ++ and is renamed to "boolean" in Tcl 9.0. ++ Based on approach suggested at ++ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */ ++ value = Tcl_NewStringObj("true", -1); ++ Tcl_GetBooleanFromObj(NULL, value, &boolValue); ++ v->BooleanType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ ++ // "bytearray" type is not registered in Tcl 9.0 ++ value = Tcl_NewByteArrayObj(NULL, 0); ++ v->ByteArrayType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->DoubleType = Tcl_GetObjType("double"); ++ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int") ++ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7 ++ only uses the "wideInt" type on platforms with 32-bit long, it still has ++ a registered "int" type, which FromObj() should recognize just in case. */ + v->IntType = Tcl_GetObjType("int"); ++ if (v->IntType == NULL) { ++ Tcl_Obj *value = Tcl_NewIntObj(0); ++ v->IntType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->WideIntType = Tcl_GetObjType("wideInt"); + v->BignumType = Tcl_GetObjType("bignum"); + v->ListType = Tcl_GetObjType("list"); + v->ProcBodyType = Tcl_GetObjType("procbody"); + v->StringType = Tcl_GetObjType("string"); ++ v->UTF32StringType = Tcl_GetObjType("utf32string"); + + /* Delete the 'exit' command, which can screw things up */ + Tcl_DeleteCommand(v->interp, "exit"); +@@ -1162,14 +1189,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return PyFloat_FromDouble(value->internalRep.doubleValue); + } + +- if (value->typePtr == tkapp->IntType) { +- long longValue; +- if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) +- return PyLong_FromLong(longValue); +- /* If there is an error in the long conversion, +- fall through to wideInt handling. */ +- } +- + if (value->typePtr == tkapp->IntType || + value->typePtr == tkapp->WideIntType) { + result = fromWideIntObj(tkapp, value); +@@ -1214,21 +1233,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return result; + } + +- if (value->typePtr == tkapp->ProcBodyType) { +- /* fall through: return tcl object. */ +- } +- +- if (value->typePtr == tkapp->StringType) { ++ if (value->typePtr == tkapp->StringType || ++ value->typePtr == tkapp->UTF32StringType) ++ { + return unicodeFromTclObj(value); + } + +- if (tkapp->BooleanType == NULL && +- strcmp(value->typePtr->name, "booleanString") == 0) { +- /* booleanString type is not registered in Tcl */ +- tkapp->BooleanType = value->typePtr; +- return fromBoolean(tkapp, value); +- } +- + if (tkapp->BignumType == NULL && + strcmp(value->typePtr->name, "bignum") == 0) { + /* bignum type is not registered in Tcl */ +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch b/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch new file mode 100644 index 00000000..285e12fc --- /dev/null +++ b/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch @@ -0,0 +1,165 @@ +From 2a31c3a635da113dac20fe4e453e6ff5d7a7e02e Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Fri, 7 Jun 2024 12:18:42 +0200 +Subject: [3.10] [3.12] gh-112672: Fix builtin Tkinter with Tcl 9.0 (GH-112681) + (GH-120209) + +* Add declaration of Tcl_AppInit(), missing in Tcl 9.0. +* Use Tcl_Size instead of int where needed. + +(cherry picked from commit e0799352823289fafb8131341abd751923ee9c08) + +Co-authored-by: Christopher Chavez +Co-authored-by: Serhiy Storchaka +--- + ...-06-04-19-03-25.gh-issue-112672.K2XfZH.rst | 1 + + Modules/_tkinter.c | 40 ++++++++++++------- + 2 files changed, 26 insertions(+), 15 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst + +diff --git a/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst +new file mode 100644 +index 00000000000..46345bff117 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst +@@ -0,0 +1 @@ ++Support building :mod:`tkinter` with Tcl 9.0. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index dee90d6bc27..8bed45f933d 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -67,6 +67,12 @@ Copyright (C) 1994 Steen Lumholt. + #define USE_DEPRECATED_TOMMATH_API 1 + #endif + ++// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9 ++#ifndef TCL_SIZE_MAX ++typedef int Tcl_Size; ++#define TCL_SIZE_MAX INT_MAX ++#endif ++ + #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) + #define HAVE_CREATEFILEHANDLER + #endif +@@ -498,7 +504,7 @@ unicodeFromTclString(const char *s) + static PyObject * + unicodeFromTclObj(Tcl_Obj *value) + { +- int len; ++ Tcl_Size len; + #if USE_TCL_UNICODE + int byteorder = NATIVE_BYTEORDER; + const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); +@@ -665,6 +671,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" + + /**** Tkapp Object ****/ + ++#if TK_MAJOR_VERSION >= 9 ++int Tcl_AppInit(Tcl_Interp *); ++#endif ++ + #ifndef WITH_APPINIT + int + Tcl_AppInit(Tcl_Interp *interp) +@@ -1326,7 +1336,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + } + + if (value->typePtr == tkapp->ByteArrayType) { +- int size; ++ Tcl_Size size; + char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); + return PyBytes_FromStringAndSize(data, size); + } +@@ -1354,8 +1364,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + #endif + + if (value->typePtr == tkapp->ListType) { +- int size; +- int i, status; ++ Tcl_Size i, size; ++ int status; + PyObject *elem; + Tcl_Obj *tcl_elem; + +@@ -1412,10 +1422,10 @@ typedef struct Tkapp_CallEvent { + Tcl_Condition *done; + } Tkapp_CallEvent; + +-void +-Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) ++static void ++Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc) + { +- int i; ++ Tcl_Size i; + for (i = 0; i < objc; i++) + Tcl_DecrRefCount(objv[i]); + if (objv != objStore) +@@ -1426,7 +1436,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) + interpreter thread, which may or may not be the calling thread. */ + + static Tcl_Obj** +-Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) ++Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc) + { + Tcl_Obj **objv = objStore; + Py_ssize_t objc = 0, i; +@@ -1474,10 +1484,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) + Tcl_IncrRefCount(objv[i]); + } + } +- *pobjc = (int)objc; ++ *pobjc = (Tcl_Size)objc; + return objv; + finally: +- Tkapp_CallDeallocArgs(objv, objStore, (int)objc); ++ Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc); + return NULL; + } + +@@ -1520,7 +1530,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv; +- int objc; ++ Tcl_Size objc; + int i; + ENTER_PYTHON + objv = Tkapp_CallArgs(e->args, objStore, &objc); +@@ -1571,7 +1581,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv = NULL; +- int objc, i; ++ Tcl_Size objc; + PyObject *res = NULL; + TkappObject *self = (TkappObject*)selfptr; + int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; +@@ -1617,6 +1627,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + else + { + ++ int i; + objv = Tkapp_CallArgs(args, objStore, &objc); + if (!objv) + return NULL; +@@ -2306,13 +2317,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) + /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ + { + char *list; +- int argc; ++ Tcl_Size argc, i; + const char **argv; + PyObject *v; +- int i; + + if (PyTclObject_Check(arg)) { +- int objc; ++ Tcl_Size objc; + Tcl_Obj **objv; + if (Tcl_ListObjGetElements(Tkapp_Interp(self), + ((PyTclObject*)arg)->value, +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch b/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch new file mode 100644 index 00000000..bbb749b5 --- /dev/null +++ b/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch @@ -0,0 +1,163 @@ +From 9ae60c0e74d71e13c13507227d8f15beb6058b7b Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <31488909+miss-islington@users.noreply.github.com> +Date: Fri, 7 Jun 2024 12:18:42 +0200 +Subject: [3.11] [3.12] gh-112672: Fix builtin Tkinter with Tcl 9.0 (GH-112681) + (GH-120209) + +* Add declaration of Tcl_AppInit(), missing in Tcl 9.0. +* Use Tcl_Size instead of int where needed. + +(cherry picked from commit e0799352823289fafb8131341abd751923ee9c08) + +Co-authored-by: Christopher Chavez +Co-authored-by: Serhiy Storchaka +--- + ...-06-04-19-03-25.gh-issue-112672.K2XfZH.rst | 1 + + Modules/_tkinter.c | 38 ++++++++++++------- + 2 files changed, 25 insertions(+), 14 deletions(-) + create mode 100644 Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst + +diff --git a/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst +new file mode 100644 +index 00000000000..46345bff117 +--- /dev/null ++++ b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst +@@ -0,0 +1 @@ ++Support building :mod:`tkinter` with Tcl 9.0. +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index df8bc124926..2bc963a4025 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -69,6 +69,12 @@ Copyright (C) 1994 Steen Lumholt. + #define USE_DEPRECATED_TOMMATH_API 1 + #endif + ++// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9 ++#ifndef TCL_SIZE_MAX ++typedef int Tcl_Size; ++#define TCL_SIZE_MAX INT_MAX ++#endif ++ + #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) + #define HAVE_CREATEFILEHANDLER + #endif +@@ -496,7 +502,7 @@ unicodeFromTclString(const char *s) + static PyObject * + unicodeFromTclObj(Tcl_Obj *value) + { +- int len; ++ Tcl_Size len; + #if USE_TCL_UNICODE + int byteorder = NATIVE_BYTEORDER; + const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); +@@ -524,6 +530,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" + + /**** Tkapp Object ****/ + ++#if TK_MAJOR_VERSION >= 9 ++int Tcl_AppInit(Tcl_Interp *); ++#endif ++ + #ifndef WITH_APPINIT + int + Tcl_AppInit(Tcl_Interp *interp) +@@ -1180,7 +1190,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + } + + if (value->typePtr == tkapp->ByteArrayType) { +- int size; ++ Tcl_Size size; + char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); + return PyBytes_FromStringAndSize(data, size); + } +@@ -1206,8 +1216,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + } + + if (value->typePtr == tkapp->ListType) { +- int size; +- int i, status; ++ Tcl_Size i, size; ++ int status; + PyObject *elem; + Tcl_Obj *tcl_elem; + +@@ -1263,9 +1273,9 @@ typedef struct Tkapp_CallEvent { + } Tkapp_CallEvent; + + static void +-Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) ++Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc) + { +- int i; ++ Tcl_Size i; + for (i = 0; i < objc; i++) + Tcl_DecrRefCount(objv[i]); + if (objv != objStore) +@@ -1276,7 +1286,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) + interpreter thread, which may or may not be the calling thread. */ + + static Tcl_Obj** +-Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) ++Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc) + { + Tcl_Obj **objv = objStore; + Py_ssize_t objc = 0, i; +@@ -1324,10 +1334,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) + Tcl_IncrRefCount(objv[i]); + } + } +- *pobjc = (int)objc; ++ *pobjc = (Tcl_Size)objc; + return objv; + finally: +- Tkapp_CallDeallocArgs(objv, objStore, (int)objc); ++ Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc); + return NULL; + } + +@@ -1370,7 +1380,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv; +- int objc; ++ Tcl_Size objc; + int i; + ENTER_PYTHON + objv = Tkapp_CallArgs(e->args, objStore, &objc); +@@ -1421,7 +1431,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv = NULL; +- int objc, i; ++ Tcl_Size objc; + PyObject *res = NULL; + TkappObject *self = (TkappObject*)selfptr; + int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; +@@ -1467,6 +1477,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + else + { + ++ int i; + objv = Tkapp_CallArgs(args, objStore, &objc); + if (!objv) + return NULL; +@@ -2152,13 +2163,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) + /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ + { + char *list; +- int argc; ++ Tcl_Size argc, i; + const char **argv; + PyObject *v; +- int i; + + if (PyTclObject_Check(arg)) { +- int objc; ++ Tcl_Size objc; + Tcl_Obj **objv; + if (Tcl_ListObjGetElements(Tkapp_Interp(self), + ((PyTclObject*)arg)->value, +-- +2.50.1 (Apple Git-155) + diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index e3f08fe4..9c32cf16 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -281,11 +281,28 @@ if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then patch -p1 -i ${ROOT}/patch-configure-crypt-no-modify-libs.patch fi -# CPython <3.12 expects an external libtommath. Backport -# https://github.com/python/cpython/pull/103842 to avoid this behavior. -# TODO(jjh): Other changes from https://github.com/python/cpython/issues/103194 +# Backport Tcl/Tk 9.0 support from 3.12 to Python 3.10 and 3.11 if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_11}" ]; then - patch -p1 -i ${ROOT}/patch-tkinter-for-no-libtommath.patch + if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then + # git checkout v3.10.19 + # git cherry-pick 625887e6df5dbebe48be172b424ba519e2ba2ddc + # git cherry-pick 27cbeb08b80138d093b9b08eb41744d249c386e6 + # git cherry-pick d4680b9e17815140b512a399069400794dae1f97 + # git cherry-pick ec139c8fae2064e5f1413dad0aadc1b83daf90d8 + # git format-patch -N --subject-prefix=3.10 --suffix=-310.patch v3.10.19 + patch -p1 -i ${ROOT}/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch + patch -p1 -i ${ROOT}/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch + patch -p1 -i ${ROOT}/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch + patch -p1 -i ${ROOT}/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch + else + # git checkout v3.11.15 + # + # git format-patch -N --subject-prefix=3.11 --suffix=-311.patch v3.11.14 + patch -p1 -i ${ROOT}/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch + patch -p1 -i ${ROOT}/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch + patch -p1 -i ${ROOT}/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch + patch -p1 -i ${ROOT}/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch + fi fi # BOLT instrumented binaries segfault in some test_embed tests for unknown reasons. From c3e15f9da791974f15f601645529ffc3987bc68e Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Thu, 18 Dec 2025 14:10:38 -0600 Subject: [PATCH 04/13] disable tcl zipfs feature when cross compiling --- cpython-unix/build-tcl.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index f619a08c..1407a97c 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -45,6 +45,14 @@ diff --git a/unix/Makefile.in b/unix/Makefile.in EOF fi +# When Zipfs support runs tclsh during the build which fails when +# cross-comiling. Disable the feature. +# An alternative is to first build a native tclsh to use during the build. +# https://core.tcl-lang.org/tcl/tktview/cb338c130b8fba479c28 +if [ -n "${CROSS_COMPILING}" ]; then + EXTRA_CONFIGURE="${EXTRA_CONFIGURE} --disable-zipfs" +fi + # Remove packages we don't care about and can pull in unwanted symbols. rm -rf pkgs/sqlite* pkgs/tdbc* From a2e3fbcb9cb6a4034d62d515a6ee5e11660d8bf3 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Thu, 18 Dec 2025 15:38:25 -0600 Subject: [PATCH 05/13] copy queue.h from container for musl --- cpython-unix/build-tcl.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index 1407a97c..0a039972 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -53,6 +53,14 @@ if [ -n "${CROSS_COMPILING}" ]; then EXTRA_CONFIGURE="${EXTRA_CONFIGURE} --disable-zipfs" fi +# musl does not include queue.h +# https://wiki.musl-libc.org/faq#Q:-Why-is-%3Ccode%3Esys/queue.h%3C/code%3E-not-included? +# It is a self contained header file, use a copy from the container. +# https://core.tcl-lang.org/tcl/tktview/3ff2d724d03ba7d6edb8 +if [ "${CC}" = "musl-clang" ]; then + cp /usr/include/x86_64-linux-gnu/sys/queue.h /tools/host/include/sys/ +fi + # Remove packages we don't care about and can pull in unwanted symbols. rm -rf pkgs/sqlite* pkgs/tdbc* From aef5c742b80cfc018f9d9f5e9a0d488470d43c4d Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Thu, 18 Dec 2025 16:53:19 -0600 Subject: [PATCH 06/13] copy queue.h from arch specific location --- cpython-unix/build-tcl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index 0a039972..3e24687f 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -58,7 +58,7 @@ fi # It is a self contained header file, use a copy from the container. # https://core.tcl-lang.org/tcl/tktview/3ff2d724d03ba7d6edb8 if [ "${CC}" = "musl-clang" ]; then - cp /usr/include/x86_64-linux-gnu/sys/queue.h /tools/host/include/sys/ + cp /usr/include/$(uname -m)-linux-gnu/sys/queue.h /tools/host/include/sys fi # Remove packages we don't care about and can pull in unwanted symbols. From ef74d341473a057313049891bf93f7fdce6137b7 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Thu, 18 Dec 2025 17:47:57 -0600 Subject: [PATCH 07/13] get static builds working --- cpython-unix/build-tcl.sh | 31 +++++++++++++++++++++---------- cpython-unix/build-tk.sh | 6 ++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index 3e24687f..8d0c48ac 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -22,23 +22,34 @@ pushd tcl${TCL_VERSION} EXTRA_CONFIGURE= if [ -n "${STATIC}" ]; then - if echo "${TARGET_TRIPLE}" | grep -q -- "-unknown-linux-musl"; then - # tcl will use an internal implementation of certain POSIX function when - # cross-compiling. The implementation of strtoul create multiple definitions - # when linked against the static musl libc. Exclude the internal implementation. - EXTRA_CONFIGURE="${EXTRA_CONFIGURE} tcl_cv_strtoul_unbroken=ok" - fi - patch -p1 << 'EOF' diff --git a/unix/Makefile.in b/unix/Makefile.in --- a/unix/Makefile.in +++ b/unix/Makefile.in -@@ -1813,7 +1813,7 @@ configure-packages: +@@ -831,7 +831,7 @@ objs: ${OBJS} + ${TCL_EXE}: ${TCLSH_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${TCL_ZIP_FILE} + ${CC} ${CFLAGS} ${LDFLAGS} ${TCLSH_OBJS} \ + @TCL_BUILD_LIB_SPEC@ ${TCL_STUB_LIB_FILE} ${LIBS} @EXTRA_TCLSH_LIBS@ \ +- ${CC_SEARCH_FLAGS} -o ${TCL_EXE} ++ ${CC_SEARCH_FLAGS} -static -o ${TCL_EXE} + @if test "${ZIPFS_BUILD}" = "2" ; then \ + if test "x$(MACHER)" = "x" ; then \ + cat ${TCL_ZIP_FILE} >> ${TCL_EXE}; \ +@@ -2062,7 +2062,7 @@ configure-packages: + $$i/configure --with-tcl8 --with-tcl=../.. \ + --with-tclinclude=$(GENERIC_DIR) \ + $(PKG_CFG_ARGS) --libdir=$(PACKAGE_DIR) \ +- --enable-shared; ) || exit $$?; \ ++ --enable-shared=no; ) || exit $$?; \ + fi; \ + mkdir -p $(PKG_DIR)/$$pkg; \ + if [ ! -f $(PKG_DIR)/$$pkg/Makefile ] ; then \ +@@ -2070,7 +2070,7 @@ configure-packages: $$i/configure --with-tcl=../.. \ --with-tclinclude=$(GENERIC_DIR) \ $(PKG_CFG_ARGS) --libdir=$(PACKAGE_DIR) \ -- --enable-shared --enable-threads; ) || exit $$?; \ -+ --enable-shared=no --enable-threads; ) || exit $$?; \ +- --enable-shared; ) || exit $$?; \ ++ --enable-shared=no; ) || exit $$?; \ fi; \ fi; \ fi; \ diff --git a/cpython-unix/build-tk.sh b/cpython-unix/build-tk.sh index d827d572..0ec86cd7 100755 --- a/cpython-unix/build-tk.sh +++ b/cpython-unix/build-tk.sh @@ -33,6 +33,12 @@ else EXTRA_CONFIGURE_FLAGS="--x-includes=${TOOLS_PATH}/deps/include --x-libraries=${TOOLS_PATH}/deps/lib" fi +# zipfs support when statically linked expects tclsh to be a zip file. +# It is not. Disable the feature. +if [ -n "${STATIC}" ]; then + EXTRA_CONFIGURE_FLAGS="${EXTRA_CONFIGURE_FLAGS} --disable-zipfs" +fi + CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \ --build=${BUILD_TRIPLE} \ --host=${TARGET_TRIPLE} \ From 40fa1577b69e07173777ebf59911261582ec44d4 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 19 Dec 2025 09:06:41 -0600 Subject: [PATCH 08/13] disable fts64_ functions on armv7 --- cpython-unix/build-tcl.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index 8d0c48ac..09b78b8a 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -64,6 +64,12 @@ if [ -n "${CROSS_COMPILING}" ]; then EXTRA_CONFIGURE="${EXTRA_CONFIGURE} --disable-zipfs" fi +# Disable the use of fts64_* functions on the 32-bit armv7 platform as these +# functions are not available in glibc 2.17 +if [[ ${TARGET_TRIPLE} = armv7* ]]; then + EXTRA_CONFIGURE="${EXTRA_CONFIGURE} tcl_cv_flag__file_offset_bits=no" +fi + # musl does not include queue.h # https://wiki.musl-libc.org/faq#Q:-Why-is-%3Ccode%3Esys/queue.h%3C/code%3E-not-included? # It is a self contained header file, use a copy from the container. From 0ff89bd6df6febbc129bb0c6f7f9780d24c1f43c Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 19 Dec 2025 09:41:01 -0600 Subject: [PATCH 09/13] use a single tkinter backport patch --- ...building-Tkinter-against-Tcl-8.7-310.patch | 37 --- ...building-Tkinter-against-Tcl-8.7-311.patch | 37 --- ...se-newer-libtommath-APIs-when-ne-310.patch | 83 ------ ...se-newer-libtommath-APIs-when-ne-311.patch | 29 -- ...ix-Tkinter-s-Tcl-value-type-hand-310.patch | 134 --------- ...ix-Tkinter-s-Tcl-value-type-hand-311.patch | 132 --------- ...ix-builtin-Tkinter-with-Tcl-9.0--310.patch | 165 ----------- ...ix-builtin-Tkinter-with-Tcl-9.0--311.patch | 163 ----------- cpython-unix/build-cpython.sh | 32 +- .../patch-tkinter-backport-tcl-9-310.patch | 277 ++++++++++++++++++ .../patch-tkinter-backport-tcl-9-311.patch | 235 +++++++++++++++ 11 files changed, 523 insertions(+), 801 deletions(-) delete mode 100644 cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch delete mode 100644 cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch delete mode 100644 cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch delete mode 100644 cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch delete mode 100644 cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch delete mode 100644 cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch delete mode 100644 cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch delete mode 100644 cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch create mode 100644 cpython-unix/patch-tkinter-backport-tcl-9-310.patch create mode 100644 cpython-unix/patch-tkinter-backport-tcl-9-311.patch diff --git a/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch b/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch deleted file mode 100644 index a1de5120..00000000 --- a/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch +++ /dev/null @@ -1,37 +0,0 @@ -From 5ea21ecc7ea3a8798be250566fe44fe11e8a98f8 Mon Sep 17 00:00:00 2001 -From: Christopher Chavez -Date: Fri, 19 May 2023 14:09:59 -0500 -Subject: [3.10] gh-103839: Allow building Tkinter against Tcl 8.7 without - external libtommath (GH-103842) - ---- - .../Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst | 2 ++ - Modules/_tkinter.c | 3 +++ - 2 files changed, 5 insertions(+) - create mode 100644 Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst - -diff --git a/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst -new file mode 100644 -index 00000000000..1d40a8fbcd3 ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst -@@ -0,0 +1,2 @@ -+Avoid compilation error due to tommath.h not being found when building -+Tkinter against Tcl 8.7 built with bundled libtommath. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index 2a3e65b6c97..6aa7e6d7da1 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -55,6 +55,9 @@ Copyright (C) 1994 Steen Lumholt. - #if TK_HEX_VERSION >= 0x08050208 && TK_HEX_VERSION < 0x08060000 || \ - TK_HEX_VERSION >= 0x08060200 - #define HAVE_LIBTOMMATH -+#ifndef TCL_WITH_EXTERNAL_TOMMATH -+#define TCL_NO_TOMMATH_H -+#endif - #include - #endif - --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch b/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch deleted file mode 100644 index f666bcd8..00000000 --- a/cpython-unix/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch +++ /dev/null @@ -1,37 +0,0 @@ -From e8111a757ceb83f6bf607912a55441ef3cdccb67 Mon Sep 17 00:00:00 2001 -From: Christopher Chavez -Date: Fri, 19 May 2023 14:09:59 -0500 -Subject: [3.11] gh-103839: Allow building Tkinter against Tcl 8.7 without - external libtommath (GH-103842) - ---- - .../Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst | 2 ++ - Modules/_tkinter.c | 3 +++ - 2 files changed, 5 insertions(+) - create mode 100644 Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst - -diff --git a/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst -new file mode 100644 -index 00000000000..1d40a8fbcd3 ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2023-04-25-16-31-00.gh-issue-103839.tpyLhI.rst -@@ -0,0 +1,2 @@ -+Avoid compilation error due to tommath.h not being found when building -+Tkinter against Tcl 8.7 built with bundled libtommath. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index 005036d3ff2..f58fd5b6764 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -58,6 +58,9 @@ Copyright (C) 1994 Steen Lumholt. - #error "Tk older than 8.5.12 not supported" - #endif - -+#ifndef TCL_WITH_EXTERNAL_TOMMATH -+#define TCL_NO_TOMMATH_H -+#endif - #include - - #if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch b/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch deleted file mode 100644 index 45892d5e..00000000 --- a/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch +++ /dev/null @@ -1,83 +0,0 @@ -From 519ea464f0bb64c6db3b11aca5a892c48a4f9627 Mon Sep 17 00:00:00 2001 -From: "Miss Islington (bot)" - <31488909+miss-islington@users.noreply.github.com> -Date: Tue, 6 Jun 2023 07:01:28 -0700 -Subject: [3.10] [3.12] gh-104399: Use newer libtommath APIs when necessary - (GH-104407) (#105343) - -gh-104399: Use newer libtommath APIs when necessary (GH-104407) -(cherry picked from commit 00d73caf804c0474980e471347d6385757af975f) - -Co-authored-by: Christopher Chavez ---- - ...-05-11-23-03-00.gh-issue-104399.MMatTP.rst | 4 ++++ - Modules/_tkinter.c | 23 +++++++++++++++++-- - 2 files changed, 25 insertions(+), 2 deletions(-) - create mode 100644 Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst - -diff --git a/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst -new file mode 100644 -index 00000000000..84cc888635b ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst -@@ -0,0 +1,4 @@ -+Prepare the ``_tkinter`` module for building with Tcl 9.0 and future -+libtommath by replacing usage of deprecated functions -+:c:func:`mp_to_unsigned_bin_n` and :c:func:`mp_unsigned_bin_size` -+when necessary. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index 6aa7e6d7da1..61296c8668a 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -61,6 +61,12 @@ Copyright (C) 1994 Steen Lumholt. - #include - #endif - -+#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) -+#define USE_DEPRECATED_TOMMATH_API 0 -+#else -+#define USE_DEPRECATED_TOMMATH_API 1 -+#endif -+ - #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) - #define HAVE_CREATEFILEHANDLER - #endif -@@ -1232,20 +1238,33 @@ static PyObject* - fromBignumObj(TkappObject *tkapp, Tcl_Obj *value) - { - mp_int bigValue; -+ mp_err err; -+#if USE_DEPRECATED_TOMMATH_API - unsigned long numBytes; -+#else -+ size_t numBytes; -+#endif - unsigned char *bytes; - PyObject *res; - - if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK) - return Tkinter_Error(tkapp); -+#if USE_DEPRECATED_TOMMATH_API - numBytes = mp_unsigned_bin_size(&bigValue); -+#else -+ numBytes = mp_ubin_size(&bigValue); -+#endif - bytes = PyMem_Malloc(numBytes); - if (bytes == NULL) { - mp_clear(&bigValue); - return PyErr_NoMemory(); - } -- if (mp_to_unsigned_bin_n(&bigValue, bytes, -- &numBytes) != MP_OKAY) { -+#if USE_DEPRECATED_TOMMATH_API -+ err = mp_to_unsigned_bin_n(&bigValue, bytes, &numBytes); -+#else -+ err = mp_to_ubin(&bigValue, bytes, numBytes, NULL); -+#endif -+ if (err != MP_OKAY) { - mp_clear(&bigValue); - PyMem_Free(bytes); - return PyErr_NoMemory(); --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch b/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch deleted file mode 100644 index a473fd1c..00000000 --- a/cpython-unix/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch +++ /dev/null @@ -1,29 +0,0 @@ -From 348e6959bc324550b5dafda24d69d1dbba9c1e5e Mon Sep 17 00:00:00 2001 -From: "Miss Islington (bot)" - <31488909+miss-islington@users.noreply.github.com> -Date: Tue, 6 Jun 2023 07:01:28 -0700 -Subject: [3.11] [3.12] gh-104399: Use newer libtommath APIs when necessary - (GH-104407) (#105343) - -gh-104399: Use newer libtommath APIs when necessary (GH-104407) -(cherry picked from commit 00d73caf804c0474980e471347d6385757af975f) - -Co-authored-by: Christopher Chavez ---- - .../Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst | 4 ++++ - 1 file changed, 4 insertions(+) - create mode 100644 Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst - -diff --git a/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst -new file mode 100644 -index 00000000000..84cc888635b ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst -@@ -0,0 +1,4 @@ -+Prepare the ``_tkinter`` module for building with Tcl 9.0 and future -+libtommath by replacing usage of deprecated functions -+:c:func:`mp_to_unsigned_bin_n` and :c:func:`mp_unsigned_bin_size` -+when necessary. --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch b/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch deleted file mode 100644 index dfe4d89d..00000000 --- a/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch +++ /dev/null @@ -1,134 +0,0 @@ -From c64d272d4ba410296a9b6df3a256b767c1d61c46 Mon Sep 17 00:00:00 2001 -From: Serhiy Storchaka -Date: Fri, 31 May 2024 12:15:53 +0300 -Subject: [3.10] =?UTF-8?q?[3.12]=20gh-103194:=20Fix=20Tkinter=E2=80=99s=20?= - =?UTF-8?q?Tcl=20value=20type=20handling=20for=20Tcl=208.7/9.0=20(GH-10384?= - =?UTF-8?q?6)=20(GH-119831)?= -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Some of standard Tcl types were renamed, removed, or no longer -registered in Tcl 8.7/9.0. This change fixes automatic conversion of Tcl -values to Python values to avoid returning a Tcl_Obj where the primary -Python types (int, bool, str, bytes) were returned in older Tcl. -(cherry picked from commit 94e9585e99abc2d060cedc77b3c03e06b4a0a9c4) - -Co-authored-by: Christopher Chavez ---- - ...-04-24-05-34-23.gh-issue-103194.GwBwWL.rst | 4 ++ - Modules/_tkinter.c | 56 +++++++++++-------- - 2 files changed, 36 insertions(+), 24 deletions(-) - create mode 100644 Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst - -diff --git a/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst -new file mode 100644 -index 00000000000..3f70168b810 ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst -@@ -0,0 +1,4 @@ -+Prepare Tkinter for C API changes in Tcl 8.7/9.0 to avoid -+:class:`_tkinter.Tcl_Obj` being unexpectedly returned -+instead of :class:`bool`, :class:`str`, -+:class:`bytearray`, or :class:`int`. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index 61296c8668a..dee90d6bc27 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -317,6 +317,7 @@ typedef struct { - const Tcl_ObjType *ListType; - const Tcl_ObjType *ProcBodyType; - const Tcl_ObjType *StringType; -+ const Tcl_ObjType *UTF32StringType; - } TkappObject; - - #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) -@@ -745,15 +746,41 @@ Tkapp_New(const char *screenName, const char *className, - } - - v->OldBooleanType = Tcl_GetObjType("boolean"); -- v->BooleanType = Tcl_GetObjType("booleanString"); -- v->ByteArrayType = Tcl_GetObjType("bytearray"); -+ { -+ Tcl_Obj *value; -+ int boolValue; -+ -+ /* Tcl 8.5 "booleanString" type is not registered -+ and is renamed to "boolean" in Tcl 9.0. -+ Based on approach suggested at -+ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */ -+ value = Tcl_NewStringObj("true", -1); -+ Tcl_GetBooleanFromObj(NULL, value, &boolValue); -+ v->BooleanType = value->typePtr; -+ Tcl_DecrRefCount(value); -+ -+ // "bytearray" type is not registered in Tcl 9.0 -+ value = Tcl_NewByteArrayObj(NULL, 0); -+ v->ByteArrayType = value->typePtr; -+ Tcl_DecrRefCount(value); -+ } - v->DoubleType = Tcl_GetObjType("double"); -+ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int") -+ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7 -+ only uses the "wideInt" type on platforms with 32-bit long, it still has -+ a registered "int" type, which FromObj() should recognize just in case. */ - v->IntType = Tcl_GetObjType("int"); -+ if (v->IntType == NULL) { -+ Tcl_Obj *value = Tcl_NewIntObj(0); -+ v->IntType = value->typePtr; -+ Tcl_DecrRefCount(value); -+ } - v->WideIntType = Tcl_GetObjType("wideInt"); - v->BignumType = Tcl_GetObjType("bignum"); - v->ListType = Tcl_GetObjType("list"); - v->ProcBodyType = Tcl_GetObjType("procbody"); - v->StringType = Tcl_GetObjType("string"); -+ v->UTF32StringType = Tcl_GetObjType("utf32string"); - - /* Delete the 'exit' command, which can screw things up */ - Tcl_DeleteCommand(v->interp, "exit"); -@@ -1308,14 +1335,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - return PyFloat_FromDouble(value->internalRep.doubleValue); - } - -- if (value->typePtr == tkapp->IntType) { -- long longValue; -- if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) -- return PyLong_FromLong(longValue); -- /* If there is an error in the long conversion, -- fall through to wideInt handling. */ -- } -- - if (value->typePtr == tkapp->IntType || - value->typePtr == tkapp->WideIntType) { - result = fromWideIntObj(tkapp, value); -@@ -1362,23 +1381,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - return result; - } - -- if (value->typePtr == tkapp->ProcBodyType) { -- /* fall through: return tcl object. */ -- } -- -- if (value->typePtr == tkapp->StringType) { -+ if (value->typePtr == tkapp->StringType || -+ value->typePtr == tkapp->UTF32StringType) -+ { - return unicodeFromTclObj(value); - } - --#if TK_HEX_VERSION >= 0x08050000 -- if (tkapp->BooleanType == NULL && -- strcmp(value->typePtr->name, "booleanString") == 0) { -- /* booleanString type is not registered in Tcl */ -- tkapp->BooleanType = value->typePtr; -- return fromBoolean(tkapp, value); -- } --#endif -- - #ifdef HAVE_LIBTOMMATH - if (tkapp->BignumType == NULL && - strcmp(value->typePtr->name, "bignum") == 0) { --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch b/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch deleted file mode 100644 index e4c09f84..00000000 --- a/cpython-unix/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch +++ /dev/null @@ -1,132 +0,0 @@ -From c47d167498e8c57e33d948f27227821fece31022 Mon Sep 17 00:00:00 2001 -From: Serhiy Storchaka -Date: Fri, 31 May 2024 12:15:53 +0300 -Subject: [3.11] =?UTF-8?q?[3.12]=20gh-103194:=20Fix=20Tkinter=E2=80=99s=20?= - =?UTF-8?q?Tcl=20value=20type=20handling=20for=20Tcl=208.7/9.0=20(GH-10384?= - =?UTF-8?q?6)=20(GH-119831)?= -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Some of standard Tcl types were renamed, removed, or no longer -registered in Tcl 8.7/9.0. This change fixes automatic conversion of Tcl -values to Python values to avoid returning a Tcl_Obj where the primary -Python types (int, bool, str, bytes) were returned in older Tcl. -(cherry picked from commit 94e9585e99abc2d060cedc77b3c03e06b4a0a9c4) - -Co-authored-by: Christopher Chavez ---- - ...-04-24-05-34-23.gh-issue-103194.GwBwWL.rst | 4 ++ - Modules/_tkinter.c | 54 +++++++++++-------- - 2 files changed, 36 insertions(+), 22 deletions(-) - create mode 100644 Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst - -diff --git a/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst -new file mode 100644 -index 00000000000..3f70168b810 ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2023-04-24-05-34-23.gh-issue-103194.GwBwWL.rst -@@ -0,0 +1,4 @@ -+Prepare Tkinter for C API changes in Tcl 8.7/9.0 to avoid -+:class:`_tkinter.Tcl_Obj` being unexpectedly returned -+instead of :class:`bool`, :class:`str`, -+:class:`bytearray`, or :class:`int`. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index f58fd5b6764..df8bc124926 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -319,6 +319,7 @@ typedef struct { - const Tcl_ObjType *ListType; - const Tcl_ObjType *ProcBodyType; - const Tcl_ObjType *StringType; -+ const Tcl_ObjType *UTF32StringType; - } TkappObject; - - #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) -@@ -604,15 +605,41 @@ Tkapp_New(const char *screenName, const char *className, - } - - v->OldBooleanType = Tcl_GetObjType("boolean"); -- v->BooleanType = Tcl_GetObjType("booleanString"); -- v->ByteArrayType = Tcl_GetObjType("bytearray"); -+ { -+ Tcl_Obj *value; -+ int boolValue; -+ -+ /* Tcl 8.5 "booleanString" type is not registered -+ and is renamed to "boolean" in Tcl 9.0. -+ Based on approach suggested at -+ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */ -+ value = Tcl_NewStringObj("true", -1); -+ Tcl_GetBooleanFromObj(NULL, value, &boolValue); -+ v->BooleanType = value->typePtr; -+ Tcl_DecrRefCount(value); -+ -+ // "bytearray" type is not registered in Tcl 9.0 -+ value = Tcl_NewByteArrayObj(NULL, 0); -+ v->ByteArrayType = value->typePtr; -+ Tcl_DecrRefCount(value); -+ } - v->DoubleType = Tcl_GetObjType("double"); -+ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int") -+ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7 -+ only uses the "wideInt" type on platforms with 32-bit long, it still has -+ a registered "int" type, which FromObj() should recognize just in case. */ - v->IntType = Tcl_GetObjType("int"); -+ if (v->IntType == NULL) { -+ Tcl_Obj *value = Tcl_NewIntObj(0); -+ v->IntType = value->typePtr; -+ Tcl_DecrRefCount(value); -+ } - v->WideIntType = Tcl_GetObjType("wideInt"); - v->BignumType = Tcl_GetObjType("bignum"); - v->ListType = Tcl_GetObjType("list"); - v->ProcBodyType = Tcl_GetObjType("procbody"); - v->StringType = Tcl_GetObjType("string"); -+ v->UTF32StringType = Tcl_GetObjType("utf32string"); - - /* Delete the 'exit' command, which can screw things up */ - Tcl_DeleteCommand(v->interp, "exit"); -@@ -1162,14 +1189,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - return PyFloat_FromDouble(value->internalRep.doubleValue); - } - -- if (value->typePtr == tkapp->IntType) { -- long longValue; -- if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) -- return PyLong_FromLong(longValue); -- /* If there is an error in the long conversion, -- fall through to wideInt handling. */ -- } -- - if (value->typePtr == tkapp->IntType || - value->typePtr == tkapp->WideIntType) { - result = fromWideIntObj(tkapp, value); -@@ -1214,21 +1233,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - return result; - } - -- if (value->typePtr == tkapp->ProcBodyType) { -- /* fall through: return tcl object. */ -- } -- -- if (value->typePtr == tkapp->StringType) { -+ if (value->typePtr == tkapp->StringType || -+ value->typePtr == tkapp->UTF32StringType) -+ { - return unicodeFromTclObj(value); - } - -- if (tkapp->BooleanType == NULL && -- strcmp(value->typePtr->name, "booleanString") == 0) { -- /* booleanString type is not registered in Tcl */ -- tkapp->BooleanType = value->typePtr; -- return fromBoolean(tkapp, value); -- } -- - if (tkapp->BignumType == NULL && - strcmp(value->typePtr->name, "bignum") == 0) { - /* bignum type is not registered in Tcl */ --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch b/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch deleted file mode 100644 index 285e12fc..00000000 --- a/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch +++ /dev/null @@ -1,165 +0,0 @@ -From 2a31c3a635da113dac20fe4e453e6ff5d7a7e02e Mon Sep 17 00:00:00 2001 -From: "Miss Islington (bot)" - <31488909+miss-islington@users.noreply.github.com> -Date: Fri, 7 Jun 2024 12:18:42 +0200 -Subject: [3.10] [3.12] gh-112672: Fix builtin Tkinter with Tcl 9.0 (GH-112681) - (GH-120209) - -* Add declaration of Tcl_AppInit(), missing in Tcl 9.0. -* Use Tcl_Size instead of int where needed. - -(cherry picked from commit e0799352823289fafb8131341abd751923ee9c08) - -Co-authored-by: Christopher Chavez -Co-authored-by: Serhiy Storchaka ---- - ...-06-04-19-03-25.gh-issue-112672.K2XfZH.rst | 1 + - Modules/_tkinter.c | 40 ++++++++++++------- - 2 files changed, 26 insertions(+), 15 deletions(-) - create mode 100644 Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst - -diff --git a/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst -new file mode 100644 -index 00000000000..46345bff117 ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst -@@ -0,0 +1 @@ -+Support building :mod:`tkinter` with Tcl 9.0. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index dee90d6bc27..8bed45f933d 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -67,6 +67,12 @@ Copyright (C) 1994 Steen Lumholt. - #define USE_DEPRECATED_TOMMATH_API 1 - #endif - -+// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9 -+#ifndef TCL_SIZE_MAX -+typedef int Tcl_Size; -+#define TCL_SIZE_MAX INT_MAX -+#endif -+ - #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) - #define HAVE_CREATEFILEHANDLER - #endif -@@ -498,7 +504,7 @@ unicodeFromTclString(const char *s) - static PyObject * - unicodeFromTclObj(Tcl_Obj *value) - { -- int len; -+ Tcl_Size len; - #if USE_TCL_UNICODE - int byteorder = NATIVE_BYTEORDER; - const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); -@@ -665,6 +671,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" - - /**** Tkapp Object ****/ - -+#if TK_MAJOR_VERSION >= 9 -+int Tcl_AppInit(Tcl_Interp *); -+#endif -+ - #ifndef WITH_APPINIT - int - Tcl_AppInit(Tcl_Interp *interp) -@@ -1326,7 +1336,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - } - - if (value->typePtr == tkapp->ByteArrayType) { -- int size; -+ Tcl_Size size; - char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); - return PyBytes_FromStringAndSize(data, size); - } -@@ -1354,8 +1364,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - #endif - - if (value->typePtr == tkapp->ListType) { -- int size; -- int i, status; -+ Tcl_Size i, size; -+ int status; - PyObject *elem; - Tcl_Obj *tcl_elem; - -@@ -1412,10 +1422,10 @@ typedef struct Tkapp_CallEvent { - Tcl_Condition *done; - } Tkapp_CallEvent; - --void --Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) -+static void -+Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc) - { -- int i; -+ Tcl_Size i; - for (i = 0; i < objc; i++) - Tcl_DecrRefCount(objv[i]); - if (objv != objStore) -@@ -1426,7 +1436,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) - interpreter thread, which may or may not be the calling thread. */ - - static Tcl_Obj** --Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) -+Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc) - { - Tcl_Obj **objv = objStore; - Py_ssize_t objc = 0, i; -@@ -1474,10 +1484,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) - Tcl_IncrRefCount(objv[i]); - } - } -- *pobjc = (int)objc; -+ *pobjc = (Tcl_Size)objc; - return objv; - finally: -- Tkapp_CallDeallocArgs(objv, objStore, (int)objc); -+ Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc); - return NULL; - } - -@@ -1520,7 +1530,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) - { - Tcl_Obj *objStore[ARGSZ]; - Tcl_Obj **objv; -- int objc; -+ Tcl_Size objc; - int i; - ENTER_PYTHON - objv = Tkapp_CallArgs(e->args, objStore, &objc); -@@ -1571,7 +1581,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) - { - Tcl_Obj *objStore[ARGSZ]; - Tcl_Obj **objv = NULL; -- int objc, i; -+ Tcl_Size objc; - PyObject *res = NULL; - TkappObject *self = (TkappObject*)selfptr; - int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; -@@ -1617,6 +1627,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) - else - { - -+ int i; - objv = Tkapp_CallArgs(args, objStore, &objc); - if (!objv) - return NULL; -@@ -2306,13 +2317,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) - /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ - { - char *list; -- int argc; -+ Tcl_Size argc, i; - const char **argv; - PyObject *v; -- int i; - - if (PyTclObject_Check(arg)) { -- int objc; -+ Tcl_Size objc; - Tcl_Obj **objv; - if (Tcl_ListObjGetElements(Tkapp_Interp(self), - ((PyTclObject*)arg)->value, --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch b/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch deleted file mode 100644 index bbb749b5..00000000 --- a/cpython-unix/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch +++ /dev/null @@ -1,163 +0,0 @@ -From 9ae60c0e74d71e13c13507227d8f15beb6058b7b Mon Sep 17 00:00:00 2001 -From: "Miss Islington (bot)" - <31488909+miss-islington@users.noreply.github.com> -Date: Fri, 7 Jun 2024 12:18:42 +0200 -Subject: [3.11] [3.12] gh-112672: Fix builtin Tkinter with Tcl 9.0 (GH-112681) - (GH-120209) - -* Add declaration of Tcl_AppInit(), missing in Tcl 9.0. -* Use Tcl_Size instead of int where needed. - -(cherry picked from commit e0799352823289fafb8131341abd751923ee9c08) - -Co-authored-by: Christopher Chavez -Co-authored-by: Serhiy Storchaka ---- - ...-06-04-19-03-25.gh-issue-112672.K2XfZH.rst | 1 + - Modules/_tkinter.c | 38 ++++++++++++------- - 2 files changed, 25 insertions(+), 14 deletions(-) - create mode 100644 Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst - -diff --git a/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst -new file mode 100644 -index 00000000000..46345bff117 ---- /dev/null -+++ b/Misc/NEWS.d/next/Library/2024-06-04-19-03-25.gh-issue-112672.K2XfZH.rst -@@ -0,0 +1 @@ -+Support building :mod:`tkinter` with Tcl 9.0. -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index df8bc124926..2bc963a4025 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -69,6 +69,12 @@ Copyright (C) 1994 Steen Lumholt. - #define USE_DEPRECATED_TOMMATH_API 1 - #endif - -+// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9 -+#ifndef TCL_SIZE_MAX -+typedef int Tcl_Size; -+#define TCL_SIZE_MAX INT_MAX -+#endif -+ - #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) - #define HAVE_CREATEFILEHANDLER - #endif -@@ -496,7 +502,7 @@ unicodeFromTclString(const char *s) - static PyObject * - unicodeFromTclObj(Tcl_Obj *value) - { -- int len; -+ Tcl_Size len; - #if USE_TCL_UNICODE - int byteorder = NATIVE_BYTEORDER; - const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); -@@ -524,6 +530,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" - - /**** Tkapp Object ****/ - -+#if TK_MAJOR_VERSION >= 9 -+int Tcl_AppInit(Tcl_Interp *); -+#endif -+ - #ifndef WITH_APPINIT - int - Tcl_AppInit(Tcl_Interp *interp) -@@ -1180,7 +1190,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - } - - if (value->typePtr == tkapp->ByteArrayType) { -- int size; -+ Tcl_Size size; - char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); - return PyBytes_FromStringAndSize(data, size); - } -@@ -1206,8 +1216,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) - } - - if (value->typePtr == tkapp->ListType) { -- int size; -- int i, status; -+ Tcl_Size i, size; -+ int status; - PyObject *elem; - Tcl_Obj *tcl_elem; - -@@ -1263,9 +1273,9 @@ typedef struct Tkapp_CallEvent { - } Tkapp_CallEvent; - - static void --Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) -+Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc) - { -- int i; -+ Tcl_Size i; - for (i = 0; i < objc; i++) - Tcl_DecrRefCount(objv[i]); - if (objv != objStore) -@@ -1276,7 +1286,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) - interpreter thread, which may or may not be the calling thread. */ - - static Tcl_Obj** --Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) -+Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc) - { - Tcl_Obj **objv = objStore; - Py_ssize_t objc = 0, i; -@@ -1324,10 +1334,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) - Tcl_IncrRefCount(objv[i]); - } - } -- *pobjc = (int)objc; -+ *pobjc = (Tcl_Size)objc; - return objv; - finally: -- Tkapp_CallDeallocArgs(objv, objStore, (int)objc); -+ Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc); - return NULL; - } - -@@ -1370,7 +1380,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) - { - Tcl_Obj *objStore[ARGSZ]; - Tcl_Obj **objv; -- int objc; -+ Tcl_Size objc; - int i; - ENTER_PYTHON - objv = Tkapp_CallArgs(e->args, objStore, &objc); -@@ -1421,7 +1431,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) - { - Tcl_Obj *objStore[ARGSZ]; - Tcl_Obj **objv = NULL; -- int objc, i; -+ Tcl_Size objc; - PyObject *res = NULL; - TkappObject *self = (TkappObject*)selfptr; - int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; -@@ -1467,6 +1477,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) - else - { - -+ int i; - objv = Tkapp_CallArgs(args, objStore, &objc); - if (!objv) - return NULL; -@@ -2152,13 +2163,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) - /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ - { - char *list; -- int argc; -+ Tcl_Size argc, i; - const char **argv; - PyObject *v; -- int i; - - if (PyTclObject_Check(arg)) { -- int objc; -+ Tcl_Size objc; - Tcl_Obj **objv; - if (Tcl_ListObjGetElements(Tkapp_Interp(self), - ((PyTclObject*)arg)->value, --- -2.50.1 (Apple Git-155) - diff --git a/cpython-unix/build-cpython.sh b/cpython-unix/build-cpython.sh index 9c32cf16..18536375 100755 --- a/cpython-unix/build-cpython.sh +++ b/cpython-unix/build-cpython.sh @@ -282,27 +282,17 @@ if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then fi # Backport Tcl/Tk 9.0 support from 3.12 to Python 3.10 and 3.11 -if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_11}" ]; then - if [ -n "${PYTHON_MEETS_MAXIMUM_VERSION_3_10}" ]; then - # git checkout v3.10.19 - # git cherry-pick 625887e6df5dbebe48be172b424ba519e2ba2ddc - # git cherry-pick 27cbeb08b80138d093b9b08eb41744d249c386e6 - # git cherry-pick d4680b9e17815140b512a399069400794dae1f97 - # git cherry-pick ec139c8fae2064e5f1413dad0aadc1b83daf90d8 - # git format-patch -N --subject-prefix=3.10 --suffix=-310.patch v3.10.19 - patch -p1 -i ${ROOT}/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-310.patch - patch -p1 -i ${ROOT}/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-310.patch - patch -p1 -i ${ROOT}/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-310.patch - patch -p1 -i ${ROOT}/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--310.patch - else - # git checkout v3.11.15 - # - # git format-patch -N --subject-prefix=3.11 --suffix=-311.patch v3.11.14 - patch -p1 -i ${ROOT}/0001-gh-103839-Allow-building-Tkinter-against-Tcl-8.7-311.patch - patch -p1 -i ${ROOT}/0002-3.12-gh-104399-Use-newer-libtommath-APIs-when-ne-311.patch - patch -p1 -i ${ROOT}/0003-3.12-gh-103194-Fix-Tkinter-s-Tcl-value-type-hand-311.patch - patch -p1 -i ${ROOT}/0004-3.12-gh-112672-Fix-builtin-Tkinter-with-Tcl-9.0--311.patch - fi +if [ "${PYTHON_MAJMIN_VERSION}" = "3.10" ]; then + # git checkout v3.10.19 + # git cherry-pick 625887e6 27cbeb08 d4680b9e ec139c8f + # git diff v3.10.19 Modules/_tkinter.c > patch-tkinter-backport-tcl-9-310.patch + patch -p1 -i ${ROOT}/patch-tkinter-backport-tcl-9-310.patch +fi +if [ "${PYTHON_MAJMIN_VERSION}" = "3.11" ]; then + # git checkout v3.11.14 + # git cherry-pick 625887e6 27cbeb08 d4680b9e ec139c8f + # git diff v3.11.14 Modules/_tkinter.c > patch-tkinter-backport-tcl-9-311.patch + patch -p1 -i ${ROOT}/patch-tkinter-backport-tcl-9-311.patch fi # BOLT instrumented binaries segfault in some test_embed tests for unknown reasons. diff --git a/cpython-unix/patch-tkinter-backport-tcl-9-310.patch b/cpython-unix/patch-tkinter-backport-tcl-9-310.patch new file mode 100644 index 00000000..85e22687 --- /dev/null +++ b/cpython-unix/patch-tkinter-backport-tcl-9-310.patch @@ -0,0 +1,277 @@ +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 2a3e65b6c97..8bed45f933d 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -55,9 +55,24 @@ Copyright (C) 1994 Steen Lumholt. + #if TK_HEX_VERSION >= 0x08050208 && TK_HEX_VERSION < 0x08060000 || \ + TK_HEX_VERSION >= 0x08060200 + #define HAVE_LIBTOMMATH ++#ifndef TCL_WITH_EXTERNAL_TOMMATH ++#define TCL_NO_TOMMATH_H ++#endif + #include + #endif + ++#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) ++#define USE_DEPRECATED_TOMMATH_API 0 ++#else ++#define USE_DEPRECATED_TOMMATH_API 1 ++#endif ++ ++// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9 ++#ifndef TCL_SIZE_MAX ++typedef int Tcl_Size; ++#define TCL_SIZE_MAX INT_MAX ++#endif ++ + #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) + #define HAVE_CREATEFILEHANDLER + #endif +@@ -308,6 +323,7 @@ typedef struct { + const Tcl_ObjType *ListType; + const Tcl_ObjType *ProcBodyType; + const Tcl_ObjType *StringType; ++ const Tcl_ObjType *UTF32StringType; + } TkappObject; + + #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) +@@ -488,7 +504,7 @@ unicodeFromTclString(const char *s) + static PyObject * + unicodeFromTclObj(Tcl_Obj *value) + { +- int len; ++ Tcl_Size len; + #if USE_TCL_UNICODE + int byteorder = NATIVE_BYTEORDER; + const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); +@@ -655,6 +671,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" + + /**** Tkapp Object ****/ + ++#if TK_MAJOR_VERSION >= 9 ++int Tcl_AppInit(Tcl_Interp *); ++#endif ++ + #ifndef WITH_APPINIT + int + Tcl_AppInit(Tcl_Interp *interp) +@@ -736,15 +756,41 @@ Tkapp_New(const char *screenName, const char *className, + } + + v->OldBooleanType = Tcl_GetObjType("boolean"); +- v->BooleanType = Tcl_GetObjType("booleanString"); +- v->ByteArrayType = Tcl_GetObjType("bytearray"); ++ { ++ Tcl_Obj *value; ++ int boolValue; ++ ++ /* Tcl 8.5 "booleanString" type is not registered ++ and is renamed to "boolean" in Tcl 9.0. ++ Based on approach suggested at ++ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */ ++ value = Tcl_NewStringObj("true", -1); ++ Tcl_GetBooleanFromObj(NULL, value, &boolValue); ++ v->BooleanType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ ++ // "bytearray" type is not registered in Tcl 9.0 ++ value = Tcl_NewByteArrayObj(NULL, 0); ++ v->ByteArrayType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->DoubleType = Tcl_GetObjType("double"); ++ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int") ++ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7 ++ only uses the "wideInt" type on platforms with 32-bit long, it still has ++ a registered "int" type, which FromObj() should recognize just in case. */ + v->IntType = Tcl_GetObjType("int"); ++ if (v->IntType == NULL) { ++ Tcl_Obj *value = Tcl_NewIntObj(0); ++ v->IntType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->WideIntType = Tcl_GetObjType("wideInt"); + v->BignumType = Tcl_GetObjType("bignum"); + v->ListType = Tcl_GetObjType("list"); + v->ProcBodyType = Tcl_GetObjType("procbody"); + v->StringType = Tcl_GetObjType("string"); ++ v->UTF32StringType = Tcl_GetObjType("utf32string"); + + /* Delete the 'exit' command, which can screw things up */ + Tcl_DeleteCommand(v->interp, "exit"); +@@ -1229,20 +1275,33 @@ static PyObject* + fromBignumObj(TkappObject *tkapp, Tcl_Obj *value) + { + mp_int bigValue; ++ mp_err err; ++#if USE_DEPRECATED_TOMMATH_API + unsigned long numBytes; ++#else ++ size_t numBytes; ++#endif + unsigned char *bytes; + PyObject *res; + + if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK) + return Tkinter_Error(tkapp); ++#if USE_DEPRECATED_TOMMATH_API + numBytes = mp_unsigned_bin_size(&bigValue); ++#else ++ numBytes = mp_ubin_size(&bigValue); ++#endif + bytes = PyMem_Malloc(numBytes); + if (bytes == NULL) { + mp_clear(&bigValue); + return PyErr_NoMemory(); + } +- if (mp_to_unsigned_bin_n(&bigValue, bytes, +- &numBytes) != MP_OKAY) { ++#if USE_DEPRECATED_TOMMATH_API ++ err = mp_to_unsigned_bin_n(&bigValue, bytes, &numBytes); ++#else ++ err = mp_to_ubin(&bigValue, bytes, numBytes, NULL); ++#endif ++ if (err != MP_OKAY) { + mp_clear(&bigValue); + PyMem_Free(bytes); + return PyErr_NoMemory(); +@@ -1277,7 +1336,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + } + + if (value->typePtr == tkapp->ByteArrayType) { +- int size; ++ Tcl_Size size; + char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); + return PyBytes_FromStringAndSize(data, size); + } +@@ -1286,14 +1345,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return PyFloat_FromDouble(value->internalRep.doubleValue); + } + +- if (value->typePtr == tkapp->IntType) { +- long longValue; +- if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) +- return PyLong_FromLong(longValue); +- /* If there is an error in the long conversion, +- fall through to wideInt handling. */ +- } +- + if (value->typePtr == tkapp->IntType || + value->typePtr == tkapp->WideIntType) { + result = fromWideIntObj(tkapp, value); +@@ -1313,8 +1364,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + #endif + + if (value->typePtr == tkapp->ListType) { +- int size; +- int i, status; ++ Tcl_Size i, size; ++ int status; + PyObject *elem; + Tcl_Obj *tcl_elem; + +@@ -1340,23 +1391,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return result; + } + +- if (value->typePtr == tkapp->ProcBodyType) { +- /* fall through: return tcl object. */ +- } +- +- if (value->typePtr == tkapp->StringType) { ++ if (value->typePtr == tkapp->StringType || ++ value->typePtr == tkapp->UTF32StringType) ++ { + return unicodeFromTclObj(value); + } + +-#if TK_HEX_VERSION >= 0x08050000 +- if (tkapp->BooleanType == NULL && +- strcmp(value->typePtr->name, "booleanString") == 0) { +- /* booleanString type is not registered in Tcl */ +- tkapp->BooleanType = value->typePtr; +- return fromBoolean(tkapp, value); +- } +-#endif +- + #ifdef HAVE_LIBTOMMATH + if (tkapp->BignumType == NULL && + strcmp(value->typePtr->name, "bignum") == 0) { +@@ -1382,10 +1422,10 @@ typedef struct Tkapp_CallEvent { + Tcl_Condition *done; + } Tkapp_CallEvent; + +-void +-Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) ++static void ++Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc) + { +- int i; ++ Tcl_Size i; + for (i = 0; i < objc; i++) + Tcl_DecrRefCount(objv[i]); + if (objv != objStore) +@@ -1396,7 +1436,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) + interpreter thread, which may or may not be the calling thread. */ + + static Tcl_Obj** +-Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) ++Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc) + { + Tcl_Obj **objv = objStore; + Py_ssize_t objc = 0, i; +@@ -1444,10 +1484,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) + Tcl_IncrRefCount(objv[i]); + } + } +- *pobjc = (int)objc; ++ *pobjc = (Tcl_Size)objc; + return objv; + finally: +- Tkapp_CallDeallocArgs(objv, objStore, (int)objc); ++ Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc); + return NULL; + } + +@@ -1490,7 +1530,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv; +- int objc; ++ Tcl_Size objc; + int i; + ENTER_PYTHON + objv = Tkapp_CallArgs(e->args, objStore, &objc); +@@ -1541,7 +1581,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv = NULL; +- int objc, i; ++ Tcl_Size objc; + PyObject *res = NULL; + TkappObject *self = (TkappObject*)selfptr; + int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; +@@ -1587,6 +1627,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + else + { + ++ int i; + objv = Tkapp_CallArgs(args, objStore, &objc); + if (!objv) + return NULL; +@@ -2276,13 +2317,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) + /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ + { + char *list; +- int argc; ++ Tcl_Size argc, i; + const char **argv; + PyObject *v; +- int i; + + if (PyTclObject_Check(arg)) { +- int objc; ++ Tcl_Size objc; + Tcl_Obj **objv; + if (Tcl_ListObjGetElements(Tkapp_Interp(self), + ((PyTclObject*)arg)->value, diff --git a/cpython-unix/patch-tkinter-backport-tcl-9-311.patch b/cpython-unix/patch-tkinter-backport-tcl-9-311.patch new file mode 100644 index 00000000..819948d9 --- /dev/null +++ b/cpython-unix/patch-tkinter-backport-tcl-9-311.patch @@ -0,0 +1,235 @@ +diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c +index 005036d3ff2..2bc963a4025 100644 +--- a/Modules/_tkinter.c ++++ b/Modules/_tkinter.c +@@ -58,6 +58,9 @@ Copyright (C) 1994 Steen Lumholt. + #error "Tk older than 8.5.12 not supported" + #endif + ++#ifndef TCL_WITH_EXTERNAL_TOMMATH ++#define TCL_NO_TOMMATH_H ++#endif + #include + + #if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) +@@ -66,6 +69,12 @@ Copyright (C) 1994 Steen Lumholt. + #define USE_DEPRECATED_TOMMATH_API 1 + #endif + ++// As suggested by https://core.tcl-lang.org/tcl/wiki?name=Migrating+C+extensions+to+Tcl+9 ++#ifndef TCL_SIZE_MAX ++typedef int Tcl_Size; ++#define TCL_SIZE_MAX INT_MAX ++#endif ++ + #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) + #define HAVE_CREATEFILEHANDLER + #endif +@@ -316,6 +325,7 @@ typedef struct { + const Tcl_ObjType *ListType; + const Tcl_ObjType *ProcBodyType; + const Tcl_ObjType *StringType; ++ const Tcl_ObjType *UTF32StringType; + } TkappObject; + + #define Tkapp_Interp(v) (((TkappObject *) (v))->interp) +@@ -492,7 +502,7 @@ unicodeFromTclString(const char *s) + static PyObject * + unicodeFromTclObj(Tcl_Obj *value) + { +- int len; ++ Tcl_Size len; + #if USE_TCL_UNICODE + int byteorder = NATIVE_BYTEORDER; + const Tcl_UniChar *u = Tcl_GetUnicodeFromObj(value, &len); +@@ -520,6 +530,10 @@ class _tkinter.tktimertoken "TkttObject *" "&Tktt_Type_spec" + + /**** Tkapp Object ****/ + ++#if TK_MAJOR_VERSION >= 9 ++int Tcl_AppInit(Tcl_Interp *); ++#endif ++ + #ifndef WITH_APPINIT + int + Tcl_AppInit(Tcl_Interp *interp) +@@ -601,15 +615,41 @@ Tkapp_New(const char *screenName, const char *className, + } + + v->OldBooleanType = Tcl_GetObjType("boolean"); +- v->BooleanType = Tcl_GetObjType("booleanString"); +- v->ByteArrayType = Tcl_GetObjType("bytearray"); ++ { ++ Tcl_Obj *value; ++ int boolValue; ++ ++ /* Tcl 8.5 "booleanString" type is not registered ++ and is renamed to "boolean" in Tcl 9.0. ++ Based on approach suggested at ++ https://core.tcl-lang.org/tcl/info/3bb3bcf2da5b */ ++ value = Tcl_NewStringObj("true", -1); ++ Tcl_GetBooleanFromObj(NULL, value, &boolValue); ++ v->BooleanType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ ++ // "bytearray" type is not registered in Tcl 9.0 ++ value = Tcl_NewByteArrayObj(NULL, 0); ++ v->ByteArrayType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->DoubleType = Tcl_GetObjType("double"); ++ /* TIP 484 suggests retrieving the "int" type without Tcl_GetObjType("int") ++ since it is no longer registered in Tcl 9.0. But even though Tcl 8.7 ++ only uses the "wideInt" type on platforms with 32-bit long, it still has ++ a registered "int" type, which FromObj() should recognize just in case. */ + v->IntType = Tcl_GetObjType("int"); ++ if (v->IntType == NULL) { ++ Tcl_Obj *value = Tcl_NewIntObj(0); ++ v->IntType = value->typePtr; ++ Tcl_DecrRefCount(value); ++ } + v->WideIntType = Tcl_GetObjType("wideInt"); + v->BignumType = Tcl_GetObjType("bignum"); + v->ListType = Tcl_GetObjType("list"); + v->ProcBodyType = Tcl_GetObjType("procbody"); + v->StringType = Tcl_GetObjType("string"); ++ v->UTF32StringType = Tcl_GetObjType("utf32string"); + + /* Delete the 'exit' command, which can screw things up */ + Tcl_DeleteCommand(v->interp, "exit"); +@@ -1150,7 +1190,7 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + } + + if (value->typePtr == tkapp->ByteArrayType) { +- int size; ++ Tcl_Size size; + char *data = (char*)Tcl_GetByteArrayFromObj(value, &size); + return PyBytes_FromStringAndSize(data, size); + } +@@ -1159,14 +1199,6 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return PyFloat_FromDouble(value->internalRep.doubleValue); + } + +- if (value->typePtr == tkapp->IntType) { +- long longValue; +- if (Tcl_GetLongFromObj(interp, value, &longValue) == TCL_OK) +- return PyLong_FromLong(longValue); +- /* If there is an error in the long conversion, +- fall through to wideInt handling. */ +- } +- + if (value->typePtr == tkapp->IntType || + value->typePtr == tkapp->WideIntType) { + result = fromWideIntObj(tkapp, value); +@@ -1184,8 +1216,8 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + } + + if (value->typePtr == tkapp->ListType) { +- int size; +- int i, status; ++ Tcl_Size i, size; ++ int status; + PyObject *elem; + Tcl_Obj *tcl_elem; + +@@ -1211,21 +1243,12 @@ FromObj(TkappObject *tkapp, Tcl_Obj *value) + return result; + } + +- if (value->typePtr == tkapp->ProcBodyType) { +- /* fall through: return tcl object. */ +- } +- +- if (value->typePtr == tkapp->StringType) { ++ if (value->typePtr == tkapp->StringType || ++ value->typePtr == tkapp->UTF32StringType) ++ { + return unicodeFromTclObj(value); + } + +- if (tkapp->BooleanType == NULL && +- strcmp(value->typePtr->name, "booleanString") == 0) { +- /* booleanString type is not registered in Tcl */ +- tkapp->BooleanType = value->typePtr; +- return fromBoolean(tkapp, value); +- } +- + if (tkapp->BignumType == NULL && + strcmp(value->typePtr->name, "bignum") == 0) { + /* bignum type is not registered in Tcl */ +@@ -1250,9 +1273,9 @@ typedef struct Tkapp_CallEvent { + } Tkapp_CallEvent; + + static void +-Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) ++Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, Tcl_Size objc) + { +- int i; ++ Tcl_Size i; + for (i = 0; i < objc; i++) + Tcl_DecrRefCount(objv[i]); + if (objv != objStore) +@@ -1263,7 +1286,7 @@ Tkapp_CallDeallocArgs(Tcl_Obj** objv, Tcl_Obj** objStore, int objc) + interpreter thread, which may or may not be the calling thread. */ + + static Tcl_Obj** +-Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) ++Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, Tcl_Size *pobjc) + { + Tcl_Obj **objv = objStore; + Py_ssize_t objc = 0, i; +@@ -1311,10 +1334,10 @@ Tkapp_CallArgs(PyObject *args, Tcl_Obj** objStore, int *pobjc) + Tcl_IncrRefCount(objv[i]); + } + } +- *pobjc = (int)objc; ++ *pobjc = (Tcl_Size)objc; + return objv; + finally: +- Tkapp_CallDeallocArgs(objv, objStore, (int)objc); ++ Tkapp_CallDeallocArgs(objv, objStore, (Tcl_Size)objc); + return NULL; + } + +@@ -1357,7 +1380,7 @@ Tkapp_CallProc(Tkapp_CallEvent *e, int flags) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv; +- int objc; ++ Tcl_Size objc; + int i; + ENTER_PYTHON + objv = Tkapp_CallArgs(e->args, objStore, &objc); +@@ -1408,7 +1431,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + { + Tcl_Obj *objStore[ARGSZ]; + Tcl_Obj **objv = NULL; +- int objc, i; ++ Tcl_Size objc; + PyObject *res = NULL; + TkappObject *self = (TkappObject*)selfptr; + int flags = TCL_EVAL_DIRECT | TCL_EVAL_GLOBAL; +@@ -1454,6 +1477,7 @@ Tkapp_Call(PyObject *selfptr, PyObject *args) + else + { + ++ int i; + objv = Tkapp_CallArgs(args, objStore, &objc); + if (!objv) + return NULL; +@@ -2139,13 +2163,12 @@ _tkinter_tkapp_splitlist(TkappObject *self, PyObject *arg) + /*[clinic end generated code: output=13b51d34386d36fb input=2b2e13351e3c0b53]*/ + { + char *list; +- int argc; ++ Tcl_Size argc, i; + const char **argv; + PyObject *v; +- int i; + + if (PyTclObject_Check(arg)) { +- int objc; ++ Tcl_Size objc; + Tcl_Obj **objv; + if (Tcl_ListObjGetElements(Tkapp_Interp(self), + ((PyTclObject*)arg)->value, From cfda52996594de06d27b7c2c9bf93aca388158c6 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 19 Dec 2025 09:43:01 -0600 Subject: [PATCH 10/13] fixup comment --- cpython-unix/build-tcl.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index 09b78b8a..89939b44 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -56,8 +56,8 @@ diff --git a/unix/Makefile.in b/unix/Makefile.in EOF fi -# When Zipfs support runs tclsh during the build which fails when -# cross-comiling. Disable the feature. +# zipfs support runs tclsh during the build which fails when cross-compiling. +# Disable the feature. # An alternative is to first build a native tclsh to use during the build. # https://core.tcl-lang.org/tcl/tktview/cb338c130b8fba479c28 if [ -n "${CROSS_COMPILING}" ]; then From d89458b091a474ad11eb3dd8e3ec808a39999b1a Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 19 Dec 2025 09:43:49 -0600 Subject: [PATCH 11/13] remove unused tcl,tk-86 downloads targets --- pythonbuild/downloads.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pythonbuild/downloads.py b/pythonbuild/downloads.py index 269fe5a6..c3acead3 100644 --- a/pythonbuild/downloads.py +++ b/pythonbuild/downloads.py @@ -317,15 +317,6 @@ "sha256": "ea451686065d6338d7e4d4a04c9af49f17951d15aa4c2e19ab8cb56fa2373440", "version": "5.38.2.2", }, - "tcl-86": { - "url": "https://prdownloads.sourceforge.net/tcl/tcl8.6.14-src.tar.gz", - "size": 11627322, - "sha256": "5880225babf7954c58d4fb0f5cf6279104ce1cd6aa9b71e9a6322540e1c4de66", - "version": "8.6.14", - "library_names": ["tcl8.6"], - "licenses": ["TCL"], - "license_file": "LICENSE.tcl.txt", - }, "tcl": { "url": "https://prdownloads.sourceforge.net/tcl/tcl9.0.3-src.tar.gz", "size": 11922915, @@ -343,15 +334,6 @@ "licenses": ["TCL"], "license_file": "LICENSE.tix.txt", }, - "tk-86": { - "url": "https://prdownloads.sourceforge.net/tcl/tk8.6.14-src.tar.gz", - "size": 4510695, - "sha256": "8ffdb720f47a6ca6107eac2dd877e30b0ef7fac14f3a84ebbd0b3612cee41a94", - "version": "8.6.14", - "library_names": ["tk8.6"], - "licenses": ["TCL"], - "license_file": "LICENSE.tcl.txt", - }, "tk": { "url": "https://prdownloads.sourceforge.net/tcl/tk9.0.3-src.tar.gz", "size": 4644835, From b9f6011115aa5f28cb023863721e02df1989ea46 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 19 Dec 2025 10:36:07 -0600 Subject: [PATCH 12/13] disable zipfs for all builds --- cpython-unix/build-tcl.sh | 18 +----------------- cpython-unix/build-tk.sh | 7 +------ 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/cpython-unix/build-tcl.sh b/cpython-unix/build-tcl.sh index 89939b44..c41c4403 100755 --- a/cpython-unix/build-tcl.sh +++ b/cpython-unix/build-tcl.sh @@ -26,15 +26,6 @@ if [ -n "${STATIC}" ]; then diff --git a/unix/Makefile.in b/unix/Makefile.in --- a/unix/Makefile.in +++ b/unix/Makefile.in -@@ -831,7 +831,7 @@ objs: ${OBJS} - ${TCL_EXE}: ${TCLSH_OBJS} ${TCL_LIB_FILE} ${TCL_STUB_LIB_FILE} ${TCL_ZIP_FILE} - ${CC} ${CFLAGS} ${LDFLAGS} ${TCLSH_OBJS} \ - @TCL_BUILD_LIB_SPEC@ ${TCL_STUB_LIB_FILE} ${LIBS} @EXTRA_TCLSH_LIBS@ \ -- ${CC_SEARCH_FLAGS} -o ${TCL_EXE} -+ ${CC_SEARCH_FLAGS} -static -o ${TCL_EXE} - @if test "${ZIPFS_BUILD}" = "2" ; then \ - if test "x$(MACHER)" = "x" ; then \ - cat ${TCL_ZIP_FILE} >> ${TCL_EXE}; \ @@ -2062,7 +2062,7 @@ configure-packages: $$i/configure --with-tcl8 --with-tcl=../.. \ --with-tclinclude=$(GENERIC_DIR) \ @@ -56,14 +47,6 @@ diff --git a/unix/Makefile.in b/unix/Makefile.in EOF fi -# zipfs support runs tclsh during the build which fails when cross-compiling. -# Disable the feature. -# An alternative is to first build a native tclsh to use during the build. -# https://core.tcl-lang.org/tcl/tktview/cb338c130b8fba479c28 -if [ -n "${CROSS_COMPILING}" ]; then - EXTRA_CONFIGURE="${EXTRA_CONFIGURE} --disable-zipfs" -fi - # Disable the use of fts64_* functions on the 32-bit armv7 platform as these # functions are not available in glibc 2.17 if [[ ${TARGET_TRIPLE} = armv7* ]]; then @@ -95,6 +78,7 @@ CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \ --prefix=/tools/deps \ --enable-shared"${STATIC:+=no}" \ --enable-threads \ + --disable-zipfs \ ${EXTRA_CONFIGURE} make -j ${NUM_CPUS} DYLIB_INSTALL_DIR=@rpath diff --git a/cpython-unix/build-tk.sh b/cpython-unix/build-tk.sh index 0ec86cd7..77d35ec5 100755 --- a/cpython-unix/build-tk.sh +++ b/cpython-unix/build-tk.sh @@ -33,12 +33,6 @@ else EXTRA_CONFIGURE_FLAGS="--x-includes=${TOOLS_PATH}/deps/include --x-libraries=${TOOLS_PATH}/deps/lib" fi -# zipfs support when statically linked expects tclsh to be a zip file. -# It is not. Disable the feature. -if [ -n "${STATIC}" ]; then - EXTRA_CONFIGURE_FLAGS="${EXTRA_CONFIGURE_FLAGS} --disable-zipfs" -fi - CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \ --build=${BUILD_TRIPLE} \ --host=${TARGET_TRIPLE} \ @@ -46,6 +40,7 @@ CFLAGS="${CFLAGS}" CPPFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure \ --with-tcl=${TOOLS_PATH}/deps/lib \ --enable-shared"${STATIC:+=no}" \ --enable-threads \ + --disable-zipfs \ ${EXTRA_CONFIGURE_FLAGS} # Remove wish, since we don't need it. From 754072e12139285c5c1706e47fad468bab793423 Mon Sep 17 00:00:00 2001 From: Jonathan Helmus Date: Fri, 19 Dec 2025 11:01:27 -0600 Subject: [PATCH 13/13] remove usused patch --- cpython-unix/patch-tkinter-for-no-libtommath.patch | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 cpython-unix/patch-tkinter-for-no-libtommath.patch diff --git a/cpython-unix/patch-tkinter-for-no-libtommath.patch b/cpython-unix/patch-tkinter-for-no-libtommath.patch deleted file mode 100644 index 7da62545..00000000 --- a/cpython-unix/patch-tkinter-for-no-libtommath.patch +++ /dev/null @@ -1,14 +0,0 @@ -diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c -index 005036d3ff2..f58fd5b6764 100644 ---- a/Modules/_tkinter.c -+++ b/Modules/_tkinter.c -@@ -58,6 +58,9 @@ Copyright (C) 1994 Steen Lumholt. - #error "Tk older than 8.5.12 not supported" - #endif - -+#ifndef TCL_WITH_EXTERNAL_TOMMATH -+#define TCL_NO_TOMMATH_H -+#endif - #include - - #if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000)