mirror of https://github.com/python/cpython
gh-104399: Use newer libtommath APIs when necessary (GH-104407)
This commit is contained in:
parent
852348ab65
commit
00d73caf80
|
@ -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.
|
|
@ -65,6 +65,12 @@ Copyright (C) 1994 Steen Lumholt.
|
||||||
#endif
|
#endif
|
||||||
#include <tclTomMath.h>
|
#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__))
|
#if !(defined(MS_WINDOWS) || defined(__CYGWIN__))
|
||||||
#define HAVE_CREATEFILEHANDLER
|
#define HAVE_CREATEFILEHANDLER
|
||||||
#endif
|
#endif
|
||||||
|
@ -1049,20 +1055,33 @@ static PyObject*
|
||||||
fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
|
fromBignumObj(TkappObject *tkapp, Tcl_Obj *value)
|
||||||
{
|
{
|
||||||
mp_int bigValue;
|
mp_int bigValue;
|
||||||
|
mp_err err;
|
||||||
|
#if USE_DEPRECATED_TOMMATH_API
|
||||||
unsigned long numBytes;
|
unsigned long numBytes;
|
||||||
|
#else
|
||||||
|
size_t numBytes;
|
||||||
|
#endif
|
||||||
unsigned char *bytes;
|
unsigned char *bytes;
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
|
|
||||||
if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
|
if (Tcl_GetBignumFromObj(Tkapp_Interp(tkapp), value, &bigValue) != TCL_OK)
|
||||||
return Tkinter_Error(tkapp);
|
return Tkinter_Error(tkapp);
|
||||||
|
#if USE_DEPRECATED_TOMMATH_API
|
||||||
numBytes = mp_unsigned_bin_size(&bigValue);
|
numBytes = mp_unsigned_bin_size(&bigValue);
|
||||||
|
#else
|
||||||
|
numBytes = mp_ubin_size(&bigValue);
|
||||||
|
#endif
|
||||||
bytes = PyMem_Malloc(numBytes);
|
bytes = PyMem_Malloc(numBytes);
|
||||||
if (bytes == NULL) {
|
if (bytes == NULL) {
|
||||||
mp_clear(&bigValue);
|
mp_clear(&bigValue);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
}
|
}
|
||||||
if (mp_to_unsigned_bin_n(&bigValue, bytes,
|
#if USE_DEPRECATED_TOMMATH_API
|
||||||
&numBytes) != MP_OKAY) {
|
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);
|
mp_clear(&bigValue);
|
||||||
PyMem_Free(bytes);
|
PyMem_Free(bytes);
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
|
Loading…
Reference in New Issue