Skip to content

Commit 27cbeb0

Browse files
[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 00d73ca) Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
1 parent 82ab13c commit 27cbeb0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Prepare the ``_tkinter`` module for building with Tcl 9.0 and future
2+
libtommath by replacing usage of deprecated functions
3+
:c:func:`mp_to_unsigned_bin_n` and :c:func:`mp_unsigned_bin_size`
4+
when necessary.

Modules/_tkinter.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ Copyright (C) 1994 Steen Lumholt.
6565
#endif
6666
#include <tclTomMath.h>
6767

68+
#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000)
69+
#define USE_DEPRECATED_TOMMATH_API 0
70+
#else
71+
#define USE_DEPRECATED_TOMMATH_API 1
72+
#endif
73+
6874
#if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
6975
#define HAVE_CREATEFILEHANDLER
7076
#endif
@@ -1053,20 +1059,33 @@ static PyObject*
10531059
fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
10541060
{
10551061
mp_int bigValue;
1062+
mp_err err;
1063+
#if USE_DEPRECATED_TOMMATH_API
10561064
unsigned long numBytes;
1065+
#else
1066+
size_t numBytes;
1067+
#endif
10571068
unsigned char *bytes;
10581069
PyObject *res;
10591070

10601071
if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
10611072
return Tkinter_Error(tkapp);
1073+
#if USE_DEPRECATED_TOMMATH_API
10621074
numBytes = mp_unsigned_bin_size(&bigValue);
1075+
#else
1076+
numBytes = mp_ubin_size(&bigValue);
1077+
#endif
10631078
bytes = PyMem_Malloc(numBytes);
10641079
if (bytes == NULL) {
10651080
mp_clear(&bigValue);
10661081
return PyErr_NoMemory();
10671082
}
1068-
if (mp_to_unsigned_bin_n(&bigValue, bytes,
1069-
&numBytes) != MP_OKAY) {
1083+
#if USE_DEPRECATED_TOMMATH_API
1084+
err = mp_to_unsigned_bin_n(&bigValue, bytes, &numBytes);
1085+
#else
1086+
err = mp_to_ubin(&bigValue, bytes, numBytes, NULL);
1087+
#endif
1088+
if (err != MP_OKAY) {
10701089
mp_clear(&bigValue);
10711090
PyMem_Free(bytes);
10721091
return PyErr_NoMemory();

0 commit comments

Comments
 (0)