[Python-checkins] [3.12] gh-104399: Use newer libtommath APIs when necessary (GH-104407) (#105343)
terryjreedy
webhook-mailer at python.org
Tue Jun 6 10:01:45 EDT 2023
https://github.com/python/cpython/commit/27cbeb08b80138d093b9b08eb41744d249c386e6
commit: 27cbeb08b80138d093b9b08eb41744d249c386e6
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: terryjreedy <tjreedy at udel.edu>
date: 2023-06-06T10:01:28-04:00
summary:
[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 <chrischavez at gmx.us>
files:
A Misc/NEWS.d/next/Library/2023-05-11-23-03-00.gh-issue-104399.MMatTP.rst
M Modules/_tkinter.c
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 000000000000..84cc888635b4
--- /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 49c94447c723..15f9c0465fb0 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -65,6 +65,12 @@ Copyright (C) 1994 Steen Lumholt.
#endif
#include <tclTomMath.h>
+#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
@@ -1053,20 +1059,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();
More information about the Python-checkins
mailing list