Skip to content

Commit c644fe4

Browse files
[3.11] gh-104399: Use newer libtommath APIs when necessary (GH-104407) (#105344)
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 b8d3bb7 commit c644fe4

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
@@ -60,6 +60,12 @@ Copyright (C) 1994 Steen Lumholt.
6060

6161
#include <tclTomMath.h>
6262

63+
#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TK_HEX_VERSION >= 0x08070000)
64+
#define USE_DEPRECATED_TOMMATH_API 0
65+
#else
66+
#define USE_DEPRECATED_TOMMATH_API 1
67+
#endif
68+
6369
#if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
6470
#define HAVE_CREATEFILEHANDLER
6571
#endif
@@ -1083,20 +1089,33 @@ static PyObject*
10831089
fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
10841090
{
10851091
mp_int bigValue;
1092+
mp_err err;
1093+
#if USE_DEPRECATED_TOMMATH_API
10861094
unsigned long numBytes;
1095+
#else
1096+
size_t numBytes;
1097+
#endif
10871098
unsigned char *bytes;
10881099
PyObject *res;
10891100

10901101
if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
10911102
return Tkinter_Error(tkapp);
1103+
#if USE_DEPRECATED_TOMMATH_API
10921104
numBytes = mp_unsigned_bin_size(&bigValue);
1105+
#else
1106+
numBytes = mp_ubin_size(&bigValue);
1107+
#endif
10931108
bytes = PyMem_Malloc(numBytes);
10941109
if (bytes == NULL) {
10951110
mp_clear(&bigValue);
10961111
return PyErr_NoMemory();
10971112
}
1098-
if (mp_to_unsigned_bin_n(&bigValue, bytes,
1099-
&numBytes) != MP_OKAY) {
1113+
#if USE_DEPRECATED_TOMMATH_API
1114+
err = mp_to_unsigned_bin_n(&bigValue, bytes, &numBytes);
1115+
#else
1116+
err = mp_to_ubin(&bigValue, bytes, numBytes, NULL);
1117+
#endif
1118+
if (err != MP_OKAY) {
11001119
mp_clear(&bigValue);
11011120
PyMem_Free(bytes);
11021121
return PyErr_NoMemory();

0 commit comments

Comments
 (0)