summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2017-09-14 13:17:42 (GMT)
committerdgp <dgp@users.sourceforge.net>2017-09-14 13:17:42 (GMT)
commit0defcea4a009cd9824488e6ae39dce57a3e0d8ba (patch)
tree5dba4d0b40c738d0c833ecd983d7aba8f569f4f5 /generic
parent9aa98a74a1932fb4fce741e954c6e7da1b8b4388 (diff)
parenta82dbfea9fc1ba0657969ffc32386b6d3133e8ac (diff)
downloadtcl-0defcea4a009cd9824488e6ae39dce57a3e0d8ba.zip
tcl-0defcea4a009cd9824488e6ae39dce57a3e0d8ba.tar.gz
tcl-0defcea4a009cd9824488e6ae39dce57a3e0d8ba.tar.bz2
merge novem
Diffstat (limited to 'generic')
-rw-r--r--generic/tclBasic.c4
-rw-r--r--generic/tclBinary.c2
-rw-r--r--generic/tclDecls.h8
-rw-r--r--generic/tclExecute.c6
-rw-r--r--generic/tclHash.c13
-rw-r--r--generic/tclInt.h4
-rw-r--r--generic/tclObj.c6
-rw-r--r--generic/tclStrToD.c32
-rw-r--r--generic/tclStubInit.c8
-rw-r--r--generic/tclTomMath.decls29
-rw-r--r--generic/tclTomMath.h2
-rw-r--r--generic/tclTomMathDecls.h38
-rw-r--r--generic/tclTomMathInterface.c166
13 files changed, 105 insertions, 213 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index b0058f3..1b54e10 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -6688,7 +6688,7 @@ ExprAbsFunc(
}
goto unChanged;
} else if (l == LONG_MIN) {
- TclBNInitBignumFromLong(&big, l);
+ TclInitBignumFromLong(&big, l);
goto tooLarge;
}
Tcl_SetObjResult(interp, Tcl_NewLongObj(-l));
@@ -6723,7 +6723,7 @@ ExprAbsFunc(
goto unChanged;
}
if (w == LLONG_MIN) {
- TclBNInitBignumFromWideInt(&big, w);
+ TclInitBignumFromWideInt(&big, w);
goto tooLarge;
}
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(-w));
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index e736cfb..8edbd0a 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -2322,7 +2322,7 @@ ScanNumber(
Tcl_Obj *bigObj = NULL;
mp_int big;
- TclBNInitBignumFromWideUInt(&big, uwvalue);
+ TclInitBignumFromWideUInt(&big, uwvalue);
bigObj = Tcl_NewBignumObj(&big);
return bigObj;
}
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index deb2a21..cb8f8c1 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -12,6 +12,14 @@
#ifndef _TCLDECLS
#define _TCLDECLS
+#if !defined(BUILD_tcl)
+# define TCL_DEPRECATED(msg) EXTERN TCL_DEPRECATED_API(msg)
+#elif defined(TCL_NO_DEPRECATED)
+# define TCL_DEPRECATED(msg) MODULE_SCOPE
+#else
+# define TCL_DEPRECATED(msg) EXTERN
+#endif
+
/*
* WARNING: This file is automatically generated by the tools/genStubs.tcl
* script. Any modifications to the function declarations below should be made
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 7f040bc..e881c8c 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -8076,7 +8076,7 @@ ExecuteExtendedBinaryMathOp(
* Arguments are opposite sign; remainder is sum.
*/
- TclBNInitBignumFromWideInt(&big1, w1);
+ TclInitBignumFromWideInt(&big1, w1);
mp_add(&big2, &big1, &big2);
mp_clear(&big1);
BIG_RESULT(&big2);
@@ -9042,7 +9042,7 @@ ExecuteExtendedUnaryMathOp(
if (w != LLONG_MIN) {
WIDE_RESULT(-w);
}
- TclBNInitBignumFromLong(&big, *(const long *) ptr);
+ TclInitBignumFromLong(&big, *(const long *) ptr);
break;
#ifndef TCL_WIDE_INT_IS_LONG
case TCL_NUMBER_WIDE:
@@ -9050,7 +9050,7 @@ ExecuteExtendedUnaryMathOp(
if (w != LLONG_MIN) {
WIDE_RESULT(-w);
}
- TclBNInitBignumFromWideInt(&big, w);
+ TclInitBignumFromWideInt(&big, w);
break;
#endif
default:
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 5f7908e..bb899de 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -39,19 +39,6 @@ static int CompareArrayKeys(void *keyPtr, Tcl_HashEntry *hPtr);
static TCL_HASH_TYPE HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr);
/*
- * Prototypes for the one word hash key methods. Not actually declared because
- * this is a critical path that is implemented in the core hash table access
- * function.
- */
-
-#if 0
-static Tcl_HashEntry * AllocOneWordEntry(Tcl_HashTable *tablePtr,
- void *keyPtr);
-static int CompareOneWordKeys(void *keyPtr, Tcl_HashEntry *hPtr);
-static unsigned int HashOneWordKey(Tcl_HashTable *tablePtr, void *keyPtr);
-#endif
-
-/*
* Prototypes for the string hash key methods.
*/
diff --git a/generic/tclInt.h b/generic/tclInt.h
index f2ef4ae..35b4019 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -2691,6 +2691,10 @@ MODULE_SCOPE long tclObjsShared[TCL_MAX_SHARED_OBJ_STATS];
MODULE_SCOPE char tclEmptyString;
+MODULE_SCOPE void TclInitBignumFromLong(mp_int *, long);
+MODULE_SCOPE void TclInitBignumFromWideInt(mp_int *, Tcl_WideInt);
+MODULE_SCOPE void TclInitBignumFromWideUInt(mp_int *, Tcl_WideUInt);
+
/*
*----------------------------------------------------------------
* Procedures shared among Tcl modules but not used by the outside world,
diff --git a/generic/tclObj.c b/generic/tclObj.c
index fbc5767..9d44bb2 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -2899,7 +2899,7 @@ Tcl_SetWideIntObj(
#else
mp_int big;
- TclBNInitBignumFromWideInt(&big, wideValue);
+ TclInitBignumFromWideInt(&big, wideValue);
Tcl_SetBignumObj(objPtr, &big);
#endif
}
@@ -3263,12 +3263,12 @@ GetBignumFromObj(
return TCL_OK;
}
if (objPtr->typePtr == &tclIntType) {
- TclBNInitBignumFromLong(bignumValue, objPtr->internalRep.longValue);
+ TclInitBignumFromLong(bignumValue, objPtr->internalRep.longValue);
return TCL_OK;
}
#ifndef TCL_WIDE_INT_IS_LONG
if (objPtr->typePtr == &tclWideIntType) {
- TclBNInitBignumFromWideInt(bignumValue,
+ TclInitBignumFromWideInt(bignumValue,
objPtr->internalRep.wideValue);
return TCL_OK;
}
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index 65eba2b..6502733 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -706,7 +706,7 @@ TclParseNumber(
|| (octalSignificandWide >
(~(Tcl_WideUInt)0 >> shift)))) {
octalSignificandOverflow = 1;
- TclBNInitBignumFromWideUInt(&octalSignificandBig,
+ TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
}
}
@@ -771,7 +771,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (~(Tcl_WideUInt)0 >> shift))) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig,
+ TclInitBignumFromWideUInt(&significandBig,
significandWide);
}
}
@@ -812,7 +812,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (~(Tcl_WideUInt)0 >> shift))) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig,
+ TclInitBignumFromWideUInt(&significandBig,
significandWide);
}
}
@@ -1154,7 +1154,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (MOST_BITS + signum) >> shift)) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig, significandWide);
+ TclInitBignumFromWideUInt(&significandBig, significandWide);
}
if (shift) {
if (!significandOverflow) {
@@ -1175,7 +1175,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (MOST_BITS + signum) >> shift)) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig, significandWide);
+ TclInitBignumFromWideUInt(&significandBig, significandWide);
}
if (shift) {
if (!significandOverflow) {
@@ -1196,7 +1196,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
octalSignificandWide > (MOST_BITS + signum) >> shift)) {
octalSignificandOverflow = 1;
- TclBNInitBignumFromWideUInt(&octalSignificandBig,
+ TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
}
if (shift) {
@@ -1223,7 +1223,7 @@ TclParseNumber(
break;
}
#endif
- TclBNInitBignumFromWideUInt(&octalSignificandBig,
+ TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
octalSignificandOverflow = 1;
} else {
@@ -1251,7 +1251,7 @@ TclParseNumber(
&significandWide, &significandBig, significandOverflow);
if (!significandOverflow && (significandWide > MOST_BITS+signum)){
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig, significandWide);
+ TclInitBignumFromWideUInt(&significandBig, significandWide);
}
returnInteger:
if (!significandOverflow) {
@@ -1270,7 +1270,7 @@ TclParseNumber(
break;
}
#endif
- TclBNInitBignumFromWideUInt(&significandBig,
+ TclInitBignumFromWideUInt(&significandBig,
significandWide);
significandOverflow = 1;
} else {
@@ -1422,7 +1422,7 @@ AccumulateDecimalDigit(
* bignum and fall through into the bignum case.
*/
- TclBNInitBignumFromWideUInt(bignumRepPtr, w);
+ TclInitBignumFromWideUInt(bignumRepPtr, w);
} else {
/*
* Wide multiplication.
@@ -1565,7 +1565,7 @@ MakeLowPrecisionDouble(
* call MakeHighPrecisionDouble to do it the hard way.
*/
- TclBNInitBignumFromWideUInt(&significandBig, significand);
+ TclInitBignumFromWideUInt(&significandBig, significand);
retval = MakeHighPrecisionDouble(0, &significandBig, numSigDigs,
exponent);
mp_clear(&significandBig);
@@ -3252,7 +3252,7 @@ ShorteningBignumConversionPowD(
* mminus = 5**m5
*/
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
mp_init_set_int(&mminus, 1);
MulPow5(&b, b5, &b);
mp_mul_2d(&b, b2, &b);
@@ -3439,7 +3439,7 @@ StrictBignumConversionPowD(
* b = bw * 2**b2 * 5**b5
*/
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
MulPow5(&b, b5, &b);
mp_mul_2d(&b, b2, &b);
@@ -3647,7 +3647,7 @@ ShorteningBignumConversion(
* S = 2**s2 * 5*s5
*/
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
mp_mul_2d(&b, b2, &b);
mp_init_set_int(&S, 1);
MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S);
@@ -3860,7 +3860,7 @@ StrictBignumConversion(
*/
mp_init_multi(&temp, &dig, NULL);
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
mp_mul_2d(&b, b2, &b);
mp_init_set_int(&S, 1);
MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S);
@@ -4516,7 +4516,7 @@ Tcl_InitBignumFromDouble(
Tcl_WideInt w = (Tcl_WideInt) ldexp(fract, mantBits);
int shift = expt - mantBits;
- TclBNInitBignumFromWideInt(b, w);
+ TclInitBignumFromWideInt(b, w);
if (shift < 0) {
mp_div_2d(b, -shift, b, NULL);
} else if (shift > 0) {
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 3eca073..ed401d6 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -683,12 +683,14 @@ const TclTomMathStubs tclTomMathStubs = {
TclBN_mp_init_set_int, /* 61 */
TclBN_mp_set_int, /* 62 */
TclBN_mp_cnt_lsb, /* 63 */
- TclBNInitBignumFromLong, /* 64 */
- TclBNInitBignumFromWideInt, /* 65 */
- TclBNInitBignumFromWideUInt, /* 66 */
+ 0, /* 64 */
+ 0, /* 65 */
+ 0, /* 66 */
TclBN_mp_expt_d_ex, /* 67 */
TclBN_mp_set_long_long, /* 68 */
TclBN_mp_get_long_long, /* 69 */
+ TclBN_mp_set_long, /* 70 */
+ TclBN_mp_get_long, /* 71 */
};
static const TclStubHooks tclStubHooks = {
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 2e62130..6595cc0 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -221,17 +221,18 @@ declare 63 {
int TclBN_mp_cnt_lsb(const mp_int *a)
}
-# Formerly internal API to allow initialisation of bignums without knowing the
-# typedefs of how a bignum works internally.
-declare 64 {
- void TclBNInitBignumFromLong(mp_int *bignum, long initVal)
-}
-declare 65 {
- void TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
-}
-declare 66 {
- void TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
-}
+# Removed in Tcl 9.0
+#declare 64 {
+# void TclBNInitBignumFromLong(mp_int *bignum, long initVal)
+#}
+# Removed in Tcl 9.0
+#declare 65 {
+# void TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
+#}
+# Removed in Tcl 9.0
+#declare 66 {
+# void TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
+#}
# Added in libtommath 1.0
declare 67 {
@@ -244,6 +245,12 @@ declare 68 {
declare 69 {
Tcl_WideUInt TclBN_mp_get_long_long(const mp_int *a)
}
+declare 70 {
+ int TclBN_mp_set_long(mp_int *a, unsigned long i)
+}
+declare 71 {
+ unsigned long TclBN_mp_get_long(const mp_int *a)
+}
# Local Variables:
# mode: tcl
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index 2ce8194..f110490 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -27,7 +27,7 @@ extern "C" {
#endif
/* detect 64-bit mode if possible */
-#if defined(NEVER)
+#if defined(NEVER) /* 128-bit ints fail in too many places */
#if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
#define MP_64BIT
#endif
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 795bcbe..7b9e3a7 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -75,6 +75,7 @@
#define mp_expt_d TclBN_mp_expt_d
#define mp_expt_d_ex TclBN_mp_expt_d_ex
#define mp_get_int TclBN_mp_get_int
+#define mp_get_long TclBN_mp_get_long
#define mp_get_long_long TclBN_mp_get_long_long
#define mp_grow TclBN_mp_grow
#define mp_init TclBN_mp_init
@@ -100,6 +101,7 @@
#define mp_s_rmap TclBNMpSRmap
#define mp_set TclBN_mp_set
#define mp_set_int TclBN_mp_set_int
+#define mp_set_long TclBN_mp_set_long
#define mp_set_long_long TclBN_mp_set_long_long
#define mp_shrink TclBN_mp_shrink
#define mp_sqr TclBN_mp_sqr
@@ -286,14 +288,9 @@ TCLAPI int TclBN_mp_init_set_int(mp_int *a, unsigned long i);
TCLAPI int TclBN_mp_set_int(mp_int *a, unsigned long i);
/* 63 */
TCLAPI int TclBN_mp_cnt_lsb(const mp_int *a);
-/* 64 */
-TCLAPI void TclBNInitBignumFromLong(mp_int *bignum, long initVal);
-/* 65 */
-TCLAPI void TclBNInitBignumFromWideInt(mp_int *bignum,
- Tcl_WideInt initVal);
-/* 66 */
-TCLAPI void TclBNInitBignumFromWideUInt(mp_int *bignum,
- Tcl_WideUInt initVal);
+/* Slot 64 is reserved */
+/* Slot 65 is reserved */
+/* Slot 66 is reserved */
/* 67 */
TCLAPI int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
mp_int *c, int fast);
@@ -301,6 +298,10 @@ TCLAPI int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
TCLAPI int TclBN_mp_set_long_long(mp_int *a, Tcl_WideUInt i);
/* 69 */
TCLAPI Tcl_WideUInt TclBN_mp_get_long_long(const mp_int *a);
+/* 70 */
+TCLAPI int TclBN_mp_set_long(mp_int *a, unsigned long i);
+/* 71 */
+TCLAPI unsigned long TclBN_mp_get_long(const mp_int *a);
typedef struct TclTomMathStubs {
int magic;
@@ -370,12 +371,14 @@ typedef struct TclTomMathStubs {
int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
- void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
- void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
- void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
+ void (*reserved64)(void);
+ void (*reserved65)(void);
+ void (*reserved66)(void);
int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
int (*tclBN_mp_set_long_long) (mp_int *a, Tcl_WideUInt i); /* 68 */
Tcl_WideUInt (*tclBN_mp_get_long_long) (const mp_int *a); /* 69 */
+ int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */
+ unsigned long (*tclBN_mp_get_long) (const mp_int *a); /* 71 */
} TclTomMathStubs;
extern const TclTomMathStubs *tclTomMathStubsPtr;
@@ -518,18 +521,19 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_set_int) /* 62 */
#define TclBN_mp_cnt_lsb \
(tclTomMathStubsPtr->tclBN_mp_cnt_lsb) /* 63 */
-#define TclBNInitBignumFromLong \
- (tclTomMathStubsPtr->tclBNInitBignumFromLong) /* 64 */
-#define TclBNInitBignumFromWideInt \
- (tclTomMathStubsPtr->tclBNInitBignumFromWideInt) /* 65 */
-#define TclBNInitBignumFromWideUInt \
- (tclTomMathStubsPtr->tclBNInitBignumFromWideUInt) /* 66 */
+/* Slot 64 is reserved */
+/* Slot 65 is reserved */
+/* Slot 66 is reserved */
#define TclBN_mp_expt_d_ex \
(tclTomMathStubsPtr->tclBN_mp_expt_d_ex) /* 67 */
#define TclBN_mp_set_long_long \
(tclTomMathStubsPtr->tclBN_mp_set_long_long) /* 68 */
#define TclBN_mp_get_long_long \
(tclTomMathStubsPtr->tclBN_mp_get_long_long) /* 69 */
+#define TclBN_mp_set_long \
+ (tclTomMathStubsPtr->tclBN_mp_set_long) /* 70 */
+#define TclBN_mp_get_long \
+ (tclTomMathStubsPtr->tclBN_mp_get_long) /* 71 */
#endif /* defined(USE_TCL_STUBS) */
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index 48db8c3..9e7bf4b 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -89,86 +89,11 @@ TclBN_revision(void)
{
return TCLTOMMATH_REVISION;
}
-#if 0
/*
*----------------------------------------------------------------------
*
- * TclBNAlloc --
- *
- * Allocate memory for libtommath.
- *
- * Results:
- * Returns a pointer to the allocated block.
- *
- * This procedure is a wrapper around Tcl_Alloc, needed because of a
- * mismatched type signature between Tcl_Alloc and malloc.
- *
- *----------------------------------------------------------------------
- */
-
-extern void *
-TclBNAlloc(
- size_t x)
-{
- return (void *) ckalloc((unsigned int) x);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNRealloc --
- *
- * Change the size of an allocated block of memory in libtommath
- *
- * Results:
- * Returns a pointer to the allocated block.
- *
- * This procedure is a wrapper around Tcl_Realloc, needed because of a
- * mismatched type signature between Tcl_Realloc and realloc.
- *
- *----------------------------------------------------------------------
- */
-
-void *
-TclBNRealloc(
- void *p,
- size_t s)
-{
- return (void *) ckrealloc((char *) p, (unsigned int) s);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNFree --
- *
- * Free allocated memory in libtommath.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Memory is freed.
- *
- * This function is simply a wrapper around Tcl_Free, needed in libtommath
- * because of a type mismatch between free and Tcl_Free.
- *
- *----------------------------------------------------------------------
- */
-
-extern void
-TclBNFree(
- void *p)
-{
- ckree((char *) p);
-}
-#endif
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNInitBignumFromLong --
+ * TclInitBignumFromLong --
*
* Allocate and initialize a 'bignum' from a native 'long'.
*
@@ -181,47 +106,20 @@ TclBNFree(
*----------------------------------------------------------------------
*/
-extern void
-TclBNInitBignumFromLong(
+void
+TclInitBignumFromLong(
mp_int *a,
- long initVal)
+ long v)
{
- int status;
- unsigned long v;
- mp_digit *p;
-
- /*
- * Allocate enough memory to hold the largest possible long
- */
-
- status = mp_init_size(a,
- (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT);
- if (status != MP_OKAY) {
- Tcl_Panic("initialization failure in TclBNInitBignumFromLong");
+ if (mp_init_size(a, (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) {
+ Tcl_Panic("initialization failure in TclInitBignumFromLong");
}
-
- /*
- * Convert arg to sign and magnitude.
- */
-
- if (initVal < 0) {
- a->sign = MP_NEG;
- v = -initVal;
+ if (v < (long)0) {
+ mp_set_long_long(a, (Tcl_WideUInt)(-(Tcl_WideInt)v));
+ mp_neg(a, a);
} else {
- a->sign = MP_ZPOS;
- v = initVal;
- }
-
- /*
- * Store the magnitude in the bignum.
- */
-
- p = a->dp;
- while (v) {
- *p++ = (mp_digit) (v & MP_MASK);
- v >>= MP_DIGIT_BIT;
+ mp_set_long_long(a, (Tcl_WideUInt)v);
}
- a->used = p - a->dp;
}
/*
@@ -240,16 +138,19 @@ TclBNInitBignumFromLong(
*----------------------------------------------------------------------
*/
-extern void
-TclBNInitBignumFromWideInt(
+void
+TclInitBignumFromWideInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideInt v) /* Initial value */
{
+ if (mp_init_size(a, (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) {
+ Tcl_Panic("initialization failure in TclInitBignumFromWideInt");
+ }
if (v < (Tcl_WideInt)0) {
- TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)(-v));
+ mp_set_long_long(a, (Tcl_WideUInt)(-v));
mp_neg(a, a);
} else {
- TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)v);
+ mp_set_long_long(a, (Tcl_WideUInt)v);
}
}
@@ -269,36 +170,15 @@ TclBNInitBignumFromWideInt(
*----------------------------------------------------------------------
*/
-extern void
-TclBNInitBignumFromWideUInt(
+void
+TclInitBignumFromWideUInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideUInt v) /* Initial value */
{
- int status;
- mp_digit *p;
-
- /*
- * Allocate enough memory to hold the largest possible Tcl_WideUInt.
- */
-
- status = mp_init_size(a,
- (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT);
- if (status != MP_OKAY) {
- Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt");
- }
-
- a->sign = MP_ZPOS;
-
- /*
- * Store the magnitude in the bignum.
- */
-
- p = a->dp;
- while (v) {
- *p++ = (mp_digit) (v & MP_MASK);
- v >>= MP_DIGIT_BIT;
- }
- a->used = p - a->dp;
+ if (mp_init_size(a, (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) {
+ Tcl_Panic("initialization failure in TclInitBignumFromWideUInt");
+ }
+ mp_set_long_long(a, v);
}
/*