From 6efacb10a4482095d896f99b79a1aee436ca5214 Mon Sep 17 00:00:00 2001 From: Christopher Chavez Date: Thu, 11 May 2023 18:03:10 -0500 Subject: [PATCH 1/3] gh-104399: Use newer libtommath APIs if needed --- ...-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 00000000000000..d510fcf1d81fc0 --- /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. \ No newline at end of file diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 4dada0b28f0559..3fcd74a331225f 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -62,6 +62,12 @@ Copyright (C) 1994 Steen Lumholt. #include +#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TCL_MAJOR_VERSION >= 9) +#define USE_DEPRECATED_TOMMATH_API 0 +#else +#define USE_DEPRECATED_TOMMATH_API 1 +#endif + #if !(defined(MS_WINDOWS) || defined(__CYGWIN__)) #define HAVE_CREATEFILEHANDLER #endif @@ -1050,20 +1056,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(); From 813eff2aac9b159ef0fd2273fc27b93a5c962416 Mon Sep 17 00:00:00 2001 From: Christopher Chavez Date: Wed, 17 May 2023 15:18:03 -0500 Subject: [PATCH 2/3] Add missing newline at end of NEWS --- .../next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index d510fcf1d81fc0..84cc888635b415 100644 --- 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 @@ -1,4 +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. \ No newline at end of file +when necessary. From ac9f00baa5ff0cacca280ab3f00c278b25d048d5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 2 Jun 2023 10:56:23 +0300 Subject: [PATCH 3/3] Update Modules/_tkinter.c --- Modules/_tkinter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 800f59c572be07..15f9c0465fb043 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -65,7 +65,7 @@ Copyright (C) 1994 Steen Lumholt. #endif #include -#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TCL_MAJOR_VERSION >= 9) +#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000) #define USE_DEPRECATED_TOMMATH_API 0 #else #define USE_DEPRECATED_TOMMATH_API 1