Skip to content

Commit 6efacb1

Browse files
authored
pythongh-104399: Use newer libtommath APIs if needed
1 parent 0449ffe commit 6efacb1

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 4 additions & 0 deletions
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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ Copyright (C) 1994 Steen Lumholt.
6262

6363
#include <tclTomMath.h>
6464

65+
#if defined(TCL_WITH_EXTERNAL_TOMMATH) || (TCL_MAJOR_VERSION >= 9)
66+
#define USE_DEPRECATED_TOMMATH_API 0
67+
#else
68+
#define USE_DEPRECATED_TOMMATH_API 1
69+
#endif
70+
6571
#if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
6672
#define HAVE_CREATEFILEHANDLER
6773
#endif
@@ -1050,20 +1056,33 @@ static PyObject*
10501056
fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
10511057
{
10521058
mp_int bigValue;
1059+
mp_err err;
1060+
#if USE_DEPRECATED_TOMMATH_API
10531061
unsigned long numBytes;
1062+
#else
1063+
size_t numBytes;
1064+
#endif
10541065
unsigned char *bytes;
10551066
PyObject *res;
10561067

10571068
if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
10581069
return Tkinter_Error(tkapp);
1070+
#if USE_DEPRECATED_TOMMATH_API
10591071
numBytes = mp_unsigned_bin_size(&bigValue);
1072+
#else
1073+
numBytes = mp_ubin_size(&bigValue);
1074+
#endif
10601075
bytes = PyMem_Malloc(numBytes);
10611076
if (bytes == NULL) {
10621077
mp_clear(&bigValue);
10631078
return PyErr_NoMemory();
10641079
}
1065-
if (mp_to_unsigned_bin_n(&bigValue, bytes,
1066-
&numBytes) != MP_OKAY) {
1080+
#if USE_DEPRECATED_TOMMATH_API
1081+
err = mp_to_unsigned_bin_n(&bigValue, bytes, &numBytes);
1082+
#else
1083+
err = mp_to_ubin(&bigValue, bytes, numBytes, NULL);
1084+
#endif
1085+
if (err != MP_OKAY) {
10671086
mp_clear(&bigValue);
10681087
PyMem_Free(bytes);
10691088
return PyErr_NoMemory();

0 commit comments

Comments
 (0)