From c6135def08ea1be2a47763a2877362b258cc3b90 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 13 Jan 2020 21:46:18 +0000 Subject: Attempt to resolve a conflict between (unmodified) tommath.h and tcl.h in the definition of mp_int. See: [https://github.com/libtom/libtommath/pull/473] --- generic/tcl.decls | 12 ++++++------ generic/tcl.h | 11 ++++++++++- generic/tclDecls.h | 24 ++++++++++++------------ generic/tclInt.h | 12 ++++++------ generic/tclObj.c | 22 ++++++++++++---------- generic/tclStrToD.c | 12 ++++++++---- 6 files changed, 54 insertions(+), 39 deletions(-) diff --git a/generic/tcl.decls b/generic/tcl.decls index 528938d..df7572b 100644 --- a/generic/tcl.decls +++ b/generic/tcl.decls @@ -2009,19 +2009,19 @@ declare 554 { # TIP#237 (arbitrary-precision integers) kbk declare 555 { - Tcl_Obj *Tcl_NewBignumObj(mp_int *value) + Tcl_Obj *Tcl_NewBignumObj(void *value) } declare 556 { - Tcl_Obj *Tcl_DbNewBignumObj(mp_int *value, const char *file, int line) + Tcl_Obj *Tcl_DbNewBignumObj(void *value, const char *file, int line) } declare 557 { - void Tcl_SetBignumObj(Tcl_Obj *obj, mp_int *value) + void Tcl_SetBignumObj(Tcl_Obj *obj, void *value) } declare 558 { - int Tcl_GetBignumFromObj(Tcl_Interp *interp, Tcl_Obj *obj, mp_int *value) + int Tcl_GetBignumFromObj(Tcl_Interp *interp, Tcl_Obj *obj, void *value) } declare 559 { - int Tcl_TakeBignumFromObj(Tcl_Interp *interp, Tcl_Obj *obj, mp_int *value) + int Tcl_TakeBignumFromObj(Tcl_Interp *interp, Tcl_Obj *obj, void *value) } # TIP #208 ('chan' command) jeffh @@ -2050,7 +2050,7 @@ declare 565 { # TIP #237 (additional conversion functions for bignum support) kbk/dgp declare 566 { int Tcl_InitBignumFromDouble(Tcl_Interp *interp, double initval, - mp_int *toInit) + void *toInit) } # TIP#181 (namespace unknown command) dgp for Neil Madden diff --git a/generic/tcl.h b/generic/tcl.h index 8a81d9e..73d13ad 100644 --- a/generic/tcl.h +++ b/generic/tcl.h @@ -2168,9 +2168,16 @@ typedef struct Tcl_Config { typedef void (Tcl_LimitHandlerProc) (ClientData clientData, Tcl_Interp *interp); typedef void (Tcl_LimitHandlerDeleteProc) (ClientData clientData); +#if 0 /* *---------------------------------------------------------------------------- - * Override definitions for libtommath. + * We would like to provide an anonymous structure "mp_int" here, which is + * compatible with libtommath's "mp_int", but without duplicating anything + * from or including here. But the libtommath project + * didn't honor our request. See: + * + * That's why this part is commented out, and we are using (void *) in + * various API's in stead of the more correct (mp_int *). */ #ifndef MP_INT_DECLARED @@ -2178,6 +2185,8 @@ typedef void (Tcl_LimitHandlerDeleteProc) (ClientData clientData); typedef struct mp_int mp_int; #endif +#endif + /* *---------------------------------------------------------------------------- * Definitions needed for Tcl_ParseArgvObj routines. diff --git a/generic/tclDecls.h b/generic/tclDecls.h index ed1da85..bbb108f 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -1644,18 +1644,18 @@ EXTERN void Tcl_QueryTimeProc(Tcl_GetTimeProc **getProc, EXTERN Tcl_DriverThreadActionProc * Tcl_ChannelThreadActionProc( const Tcl_ChannelType *chanTypePtr); /* 555 */ -EXTERN Tcl_Obj * Tcl_NewBignumObj(mp_int *value); +EXTERN Tcl_Obj * Tcl_NewBignumObj(void *value); /* 556 */ -EXTERN Tcl_Obj * Tcl_DbNewBignumObj(mp_int *value, const char *file, +EXTERN Tcl_Obj * Tcl_DbNewBignumObj(void *value, const char *file, int line); /* 557 */ -EXTERN void Tcl_SetBignumObj(Tcl_Obj *obj, mp_int *value); +EXTERN void Tcl_SetBignumObj(Tcl_Obj *obj, void *value); /* 558 */ EXTERN int Tcl_GetBignumFromObj(Tcl_Interp *interp, - Tcl_Obj *obj, mp_int *value); + Tcl_Obj *obj, void *value); /* 559 */ EXTERN int Tcl_TakeBignumFromObj(Tcl_Interp *interp, - Tcl_Obj *obj, mp_int *value); + Tcl_Obj *obj, void *value); /* 560 */ EXTERN int Tcl_TruncateChannel(Tcl_Channel chan, Tcl_WideInt length); @@ -1674,7 +1674,7 @@ EXTERN void Tcl_SetChannelError(Tcl_Channel chan, Tcl_Obj *msg); EXTERN void Tcl_GetChannelError(Tcl_Channel chan, Tcl_Obj **msg); /* 566 */ EXTERN int Tcl_InitBignumFromDouble(Tcl_Interp *interp, - double initval, mp_int *toInit); + double initval, void *toInit); /* 567 */ EXTERN Tcl_Obj * Tcl_GetNamespaceUnknownHandler(Tcl_Interp *interp, Tcl_Namespace *nsPtr); @@ -2503,18 +2503,18 @@ typedef struct TclStubs { void (*tcl_SetTimeProc) (Tcl_GetTimeProc *getProc, Tcl_ScaleTimeProc *scaleProc, ClientData clientData); /* 552 */ void (*tcl_QueryTimeProc) (Tcl_GetTimeProc **getProc, Tcl_ScaleTimeProc **scaleProc, ClientData *clientData); /* 553 */ Tcl_DriverThreadActionProc * (*tcl_ChannelThreadActionProc) (const Tcl_ChannelType *chanTypePtr); /* 554 */ - Tcl_Obj * (*tcl_NewBignumObj) (mp_int *value); /* 555 */ - Tcl_Obj * (*tcl_DbNewBignumObj) (mp_int *value, const char *file, int line); /* 556 */ - void (*tcl_SetBignumObj) (Tcl_Obj *obj, mp_int *value); /* 557 */ - int (*tcl_GetBignumFromObj) (Tcl_Interp *interp, Tcl_Obj *obj, mp_int *value); /* 558 */ - int (*tcl_TakeBignumFromObj) (Tcl_Interp *interp, Tcl_Obj *obj, mp_int *value); /* 559 */ + Tcl_Obj * (*tcl_NewBignumObj) (void *value); /* 555 */ + Tcl_Obj * (*tcl_DbNewBignumObj) (void *value, const char *file, int line); /* 556 */ + void (*tcl_SetBignumObj) (Tcl_Obj *obj, void *value); /* 557 */ + int (*tcl_GetBignumFromObj) (Tcl_Interp *interp, Tcl_Obj *obj, void *value); /* 558 */ + int (*tcl_TakeBignumFromObj) (Tcl_Interp *interp, Tcl_Obj *obj, void *value); /* 559 */ int (*tcl_TruncateChannel) (Tcl_Channel chan, Tcl_WideInt length); /* 560 */ Tcl_DriverTruncateProc * (*tcl_ChannelTruncateProc) (const Tcl_ChannelType *chanTypePtr); /* 561 */ void (*tcl_SetChannelErrorInterp) (Tcl_Interp *interp, Tcl_Obj *msg); /* 562 */ void (*tcl_GetChannelErrorInterp) (Tcl_Interp *interp, Tcl_Obj **msg); /* 563 */ void (*tcl_SetChannelError) (Tcl_Channel chan, Tcl_Obj *msg); /* 564 */ void (*tcl_GetChannelError) (Tcl_Channel chan, Tcl_Obj **msg); /* 565 */ - int (*tcl_InitBignumFromDouble) (Tcl_Interp *interp, double initval, mp_int *toInit); /* 566 */ + int (*tcl_InitBignumFromDouble) (Tcl_Interp *interp, double initval, void *toInit); /* 566 */ Tcl_Obj * (*tcl_GetNamespaceUnknownHandler) (Tcl_Interp *interp, Tcl_Namespace *nsPtr); /* 567 */ int (*tcl_SetNamespaceUnknownHandler) (Tcl_Interp *interp, Tcl_Namespace *nsPtr, Tcl_Obj *handlerPtr); /* 568 */ int (*tcl_GetEncodingFromObj) (Tcl_Interp *interp, Tcl_Obj *objPtr, Tcl_Encoding *encodingPtr); /* 569 */ diff --git a/generic/tclInt.h b/generic/tclInt.h index 8b150db..aa695a5 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -2914,11 +2914,11 @@ MODULE_SCOPE void TclArgumentBCRelease(Tcl_Interp *interp, CmdFrame *cfPtr); MODULE_SCOPE void TclArgumentGet(Tcl_Interp *interp, Tcl_Obj *obj, CmdFrame **cfPtrPtr, int *wordPtr); -MODULE_SCOPE double TclBignumToDouble(const mp_int *bignum); +MODULE_SCOPE double TclBignumToDouble(const void *bignum); MODULE_SCOPE int TclByteArrayMatch(const unsigned char *string, int strLen, const unsigned char *pattern, int ptnLen, int flags); -MODULE_SCOPE double TclCeil(const mp_int *a); +MODULE_SCOPE double TclCeil(const void *a); MODULE_SCOPE void TclChannelPreserve(Tcl_Channel chan); MODULE_SCOPE void TclChannelRelease(Tcl_Channel chan); MODULE_SCOPE int TclCheckArrayTraces(Tcl_Interp *interp, Var *varPtr, @@ -3001,7 +3001,7 @@ MODULE_SCOPE void TclFinalizeThreadAlloc(void); MODULE_SCOPE void TclFinalizeThreadAllocThread(void); MODULE_SCOPE void TclFinalizeThreadData(int quick); MODULE_SCOPE void TclFinalizeThreadObjects(void); -MODULE_SCOPE double TclFloor(const mp_int *a); +MODULE_SCOPE double TclFloor(const void *a); MODULE_SCOPE void TclFormatNaN(double value, char *buffer); MODULE_SCOPE int TclFSFileAttrIndex(Tcl_Obj *pathPtr, const char *attributeName, int *indexPtr); @@ -3058,8 +3058,8 @@ MODULE_SCOPE int TclInfoLocalsCmd(ClientData dummy, Tcl_Interp *interp, MODULE_SCOPE int TclInfoVarsCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]); MODULE_SCOPE void TclInitAlloc(void); -MODULE_SCOPE void TclInitBignumFromWideInt(mp_int *, Tcl_WideInt); -MODULE_SCOPE void TclInitBignumFromWideUInt(mp_int *, Tcl_WideUInt); +MODULE_SCOPE void TclInitBignumFromWideInt(void *, Tcl_WideInt); +MODULE_SCOPE void TclInitBignumFromWideUInt(void *, Tcl_WideUInt); MODULE_SCOPE void TclInitDbCkalloc(void); MODULE_SCOPE void TclInitDoubleConversion(void); MODULE_SCOPE void TclInitEmbeddedConfigurationInformation( @@ -3194,7 +3194,7 @@ MODULE_SCOPE int TclScanElement(const char *string, int length, MODULE_SCOPE void TclSetBgErrorHandler(Tcl_Interp *interp, Tcl_Obj *cmdPrefix); MODULE_SCOPE void TclSetBignumIntRep(Tcl_Obj *objPtr, - mp_int *bignumValue); + void *bignumValue); MODULE_SCOPE int TclSetBooleanFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); MODULE_SCOPE void TclSetCmdNameObj(Tcl_Interp *interp, Tcl_Obj *objPtr, diff --git a/generic/tclObj.c b/generic/tclObj.c index eb9334e..a5797eb 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -3492,14 +3492,14 @@ UpdateStringOfBignum( Tcl_Obj * Tcl_NewBignumObj( - mp_int *bignumValue) + void *bignumValue) { return Tcl_DbNewBignumObj(bignumValue, "unknown", 0); } #else Tcl_Obj * Tcl_NewBignumObj( - mp_int *bignumValue) + void *bignumValue) { Tcl_Obj *objPtr; @@ -3530,7 +3530,7 @@ Tcl_NewBignumObj( #ifdef TCL_MEM_DEBUG Tcl_Obj * Tcl_DbNewBignumObj( - mp_int *bignumValue, + void *bignumValue, const char *file, int line) { @@ -3543,7 +3543,7 @@ Tcl_DbNewBignumObj( #else Tcl_Obj * Tcl_DbNewBignumObj( - mp_int *bignumValue, + void *bignumValue, const char *file, int line) { @@ -3651,9 +3651,9 @@ int Tcl_GetBignumFromObj( Tcl_Interp *interp, /* Tcl interpreter for error reporting */ Tcl_Obj *objPtr, /* Object to read */ - mp_int *bignumValue) /* Returned bignum value. */ + void *bignumValue) /* Returned bignum value. */ { - return GetBignumFromObj(interp, objPtr, 1, bignumValue); + return GetBignumFromObj(interp, objPtr, 1, (mp_int *)bignumValue); } /* @@ -3686,9 +3686,9 @@ int Tcl_TakeBignumFromObj( Tcl_Interp *interp, /* Tcl interpreter for error reporting */ Tcl_Obj *objPtr, /* Object to read */ - mp_int *bignumValue) /* Returned bignum value. */ + void *bignumValue) /* Returned bignum value. */ { - return GetBignumFromObj(interp, objPtr, 0, bignumValue); + return GetBignumFromObj(interp, objPtr, 0, (mp_int *)bignumValue); } /* @@ -3711,12 +3711,13 @@ Tcl_TakeBignumFromObj( void Tcl_SetBignumObj( Tcl_Obj *objPtr, /* Object to set */ - mp_int *bignumValue) /* Value to store */ + void *big) /* Value to store */ { Tcl_WideUInt value = 0; size_t numBytes; Tcl_WideUInt scratch; unsigned char *bytes = (unsigned char *) &scratch; + mp_int *bignumValue = (mp_int *) big; if (Tcl_IsShared(objPtr)) { Tcl_Panic("%s called with shared object", "Tcl_SetBignumObj"); @@ -3764,8 +3765,9 @@ Tcl_SetBignumObj( void TclSetBignumIntRep( Tcl_Obj *objPtr, - mp_int *bignumValue) + void *big) { + mp_int *bignumValue = (mp_int *)big; objPtr->typePtr = &tclBignumType; PACK_BIGNUM(*bignumValue, objPtr); diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c index 8939fa0..3c80afc 100644 --- a/generic/tclStrToD.c +++ b/generic/tclStrToD.c @@ -4553,10 +4553,11 @@ int Tcl_InitBignumFromDouble( Tcl_Interp *interp, /* For error message. */ double d, /* Number to convert. */ - mp_int *b) /* Place to store the result. */ + void *big) /* Place to store the result. */ { double fract; int expt; + mp_int *b = (mp_int *)big; /* * Infinite values can't convert to bignum. @@ -4607,11 +4608,12 @@ Tcl_InitBignumFromDouble( double TclBignumToDouble( - const mp_int *a) /* Integer to convert. */ + const void *big) /* Integer to convert. */ { mp_int b; int bits, shift, i, lsb; double r; + const mp_int *a = (const mp_int *)big; /* @@ -4720,10 +4722,11 @@ TclBignumToDouble( double TclCeil( - const mp_int *a) /* Integer to convert. */ + const void *big) /* Integer to convert. */ { double r = 0.0; mp_int b; + const mp_int *a = (const mp_int *)big; mp_init(&b); if (mp_isneg(a)) { @@ -4777,10 +4780,11 @@ TclCeil( double TclFloor( - const mp_int *a) /* Integer to convert. */ + const void *big) /* Integer to convert. */ { double r = 0.0; mp_int b; + const mp_int *a = (const mp_int *)big; mp_init(&b); if (mp_isneg(a)) { -- cgit v0.12