summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-03-15 20:52:25 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-03-15 20:52:25 (GMT)
commit2ff70c01f60ef1dbb586489d97b1f36368ad6741 (patch)
tree818e1ae3cdf91deda3a567394b28a643beebaba6 /generic
parentd7fe4af6212051638be9eb9f6912e844e51fb22c (diff)
downloadtcl-2ff70c01f60ef1dbb586489d97b1f36368ad6741.zip
tcl-2ff70c01f60ef1dbb586489d97b1f36368ad6741.tar.gz
tcl-2ff70c01f60ef1dbb586489d97b1f36368ad6741.tar.bz2
Eliminate usage of mp_isneg(), just check bignum->sign directly (as libtommath itself does)
Make TclInitBugnumFromLong() a static function in stubtable only, as it isn't used by Tcl anymore.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclBasic.c8
-rw-r--r--generic/tclExecute.c30
-rw-r--r--generic/tclInt.h1
-rw-r--r--generic/tclPipe.c2
-rw-r--r--generic/tclScan.c2
-rw-r--r--generic/tclStrToD.c16
-rw-r--r--generic/tclStubInit.c8
-rw-r--r--generic/tclTomMathDecls.h19
-rw-r--r--generic/tclTomMathInterface.c38
-rw-r--r--generic/tclUtil.c6
10 files changed, 47 insertions, 83 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index d914690..1806557 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -7560,7 +7560,7 @@ ExprIsqrtFunc(
if (Tcl_GetBignumFromObj(interp, objv[1], &big) != TCL_OK) {
return TCL_ERROR;
}
- if (mp_isneg(&big)) {
+ if (big.sign != MP_ZPOS) {
mp_clear(&big);
goto negarg;
}
@@ -7789,9 +7789,9 @@ ExprAbsFunc(
if (type == TCL_NUMBER_INT) {
Tcl_WideInt l = *((const Tcl_WideInt *) ptr);
- if (l > (Tcl_WideInt)0) {
+ if (l > 0) {
goto unChanged;
- } else if (l == (Tcl_WideInt)0) {
+ } else if (l == 0) {
if (TclHasStringRep(objv[1])) {
int numBytes;
const char *bytes = TclGetStringFromObj(objv[1], &numBytes);
@@ -7834,7 +7834,7 @@ ExprAbsFunc(
}
if (type == TCL_NUMBER_BIG) {
- if (mp_isneg((const mp_int *) ptr)) {
+ if (((const mp_int *) ptr)->sign != MP_ZPOS) {
Tcl_GetBignumFromObj(NULL, objv[1], &big);
tooLarge:
mp_neg(&big, &big);
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index dfb1140..7693fd2 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -7985,8 +7985,8 @@ ExecuteExtendedBinaryMathOp(
if (((wQuotient < (Tcl_WideInt) 0)
|| ((wQuotient == (Tcl_WideInt) 0)
- && ((w1 < (Tcl_WideInt)0 && w2 > (Tcl_WideInt)0)
- || (w1 > (Tcl_WideInt)0 && w2 < (Tcl_WideInt)0))))
+ && ((w1 < 0 && w2 > 0)
+ || (w1 > 0 && w2 < 0))))
&& (wQuotient * w2 != w1)) {
wQuotient -= (Tcl_WideInt) 1;
}
@@ -8020,7 +8020,7 @@ ExecuteExtendedBinaryMathOp(
mp_init(&bigResult);
mp_init(&bigRemainder);
mp_div(&big1, &big2, &bigResult, &bigRemainder);
- if (!mp_iszero(&bigRemainder) && (bigRemainder.sign != big2.sign)) {
+ if ((bigRemainder.used != 0) && (bigRemainder.sign != big2.sign)) {
/*
* Convert to Tcl's integer division rules.
*/
@@ -8042,11 +8042,11 @@ ExecuteExtendedBinaryMathOp(
switch (type2) {
case TCL_NUMBER_INT:
- invalid = (*((const Tcl_WideInt *)ptr2) < (Tcl_WideInt)0);
+ invalid = (*((const Tcl_WideInt *)ptr2) < 0);
break;
case TCL_NUMBER_BIG:
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
- invalid = mp_isneg(&big2);
+ invalid = big2.sign != MP_ZPOS;
mp_clear(&big2);
break;
default:
@@ -8063,7 +8063,7 @@ ExecuteExtendedBinaryMathOp(
* Zero shifted any number of bits is still zero.
*/
- if ((type1==TCL_NUMBER_INT) && (*((const Tcl_WideInt *)ptr1) == (Tcl_WideInt)0)) {
+ if ((type1==TCL_NUMBER_INT) && (*((const Tcl_WideInt *)ptr1) == 0)) {
return constants[0];
}
@@ -8121,11 +8121,11 @@ ExecuteExtendedBinaryMathOp(
switch (type1) {
case TCL_NUMBER_INT:
- zero = (*(const Tcl_WideInt *)ptr1 > (Tcl_WideInt)0);
+ zero = (*(const Tcl_WideInt *)ptr1 > 0);
break;
case TCL_NUMBER_BIG:
Tcl_TakeBignumFromObj(NULL, valuePtr, &big1);
- zero = (!mp_isneg(&big1));
+ zero = (big1.sign == MP_ZPOS);
mp_clear(&big1);
break;
default:
@@ -8146,7 +8146,7 @@ ExecuteExtendedBinaryMathOp(
if (type1 == TCL_NUMBER_INT) {
w1 = *(const Tcl_WideInt *)ptr1;
if ((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideInt)) {
- if (w1 >= (Tcl_WideInt)0) {
+ if (w1 >= 0) {
return constants[0];
}
WIDE_RESULT(-1);
@@ -8249,9 +8249,9 @@ ExecuteExtendedBinaryMathOp(
oddExponent = (int) (w2 & (Tcl_WideInt)1);
} else {
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
- negativeExponent = mp_isneg(&big2);
+ negativeExponent = big2.sign != MP_ZPOS;
mp_mod_2d(&big2, 1, &big2);
- oddExponent = !mp_iszero(&big2);
+ oddExponent = big2.used != 0;
mp_clear(&big2);
}
@@ -8568,7 +8568,7 @@ ExecuteExtendedBinaryMathOp(
mp_mul(&big1, &big2, &bigResult);
break;
case INST_DIV:
- if (mp_iszero(&big2)) {
+ if (big2.used == 0) {
mp_clear(&big1);
mp_clear(&big2);
mp_clear(&bigResult);
@@ -8577,7 +8577,7 @@ ExecuteExtendedBinaryMathOp(
mp_init(&bigRemainder);
mp_div(&big1, &big2, &bigResult, &bigRemainder);
/* TODO: internals intrusion */
- if (!mp_iszero(&bigRemainder)
+ if ((bigRemainder.used != 0)
&& (bigRemainder.sign != big2.sign)) {
/*
* Convert to Tcl's integer division rules.
@@ -8724,7 +8724,7 @@ TclCompareTwoNumbers(
goto wideCompare;
case TCL_NUMBER_BIG:
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
- if (mp_isneg(&big2)) {
+ if (big2.sign != MP_ZPOS) {
compare = MP_GT;
} else {
compare = MP_LT;
@@ -8761,7 +8761,7 @@ TclCompareTwoNumbers(
}
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
if ((d1 < (double)WIDE_MAX) && (d1 > (double)WIDE_MIN)) {
- if (mp_isneg(&big2)) {
+ if (big2.sign != MP_ZPOS) {
compare = MP_GT;
} else {
compare = MP_LT;
diff --git a/generic/tclInt.h b/generic/tclInt.h
index beb7a35..9fc778b 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3060,7 +3060,6 @@ 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 TclInitBignumFromLong(mp_int *, long);
MODULE_SCOPE void TclInitBignumFromWideInt(mp_int *, Tcl_WideInt);
MODULE_SCOPE void TclInitBignumFromWideUInt(mp_int *, Tcl_WideUInt);
MODULE_SCOPE void TclInitDbCkalloc(void);
diff --git a/generic/tclPipe.c b/generic/tclPipe.c
index f94fe5c..63fd2fa 100644
--- a/generic/tclPipe.c
+++ b/generic/tclPipe.c
@@ -333,7 +333,7 @@ TclCleanupChildren(
int count;
Tcl_Obj *objPtr;
- Tcl_Seek(errorChan, (Tcl_WideInt)0, SEEK_SET);
+ Tcl_Seek(errorChan, 0, SEEK_SET);
objPtr = Tcl_NewObj();
count = Tcl_ReadChars(errorChan, objPtr, -1, 0);
if (count < 0) {
diff --git a/generic/tclScan.c b/generic/tclScan.c
index 0f578d8..0736cfb 100644
--- a/generic/tclScan.c
+++ b/generic/tclScan.c
@@ -943,7 +943,7 @@ Tcl_ScanObjCmd(
int code = Tcl_GetBignumFromObj(interp, objPtr, &big);
if (code == TCL_OK) {
- if (mp_isneg(&big)) {
+ if (big.sign != MP_ZPOS) {
code = TCL_ERROR;
}
mp_clear(&big);
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index b7f35e6..e7cb2c5 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -530,7 +530,7 @@ TclParseNumber(
int shift = 0; /* Amount to shift when accumulating binary */
int explicitOctal = 0;
-#define ALL_BITS (~(Tcl_WideUInt)0)
+#define ALL_BITS ((Tcl_WideUInt)-1)
#define MOST_BITS (ALL_BITS >> 1)
/*
@@ -709,7 +709,7 @@ TclParseNumber(
&& (((size_t)shift >=
CHAR_BIT*sizeof(Tcl_WideUInt))
|| (octalSignificandWide >
- (~(Tcl_WideUInt)0 >> shift)))) {
+ ((Tcl_WideUInt)-1 >> shift)))) {
octalSignificandOverflow = 1;
TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
@@ -826,7 +826,7 @@ TclParseNumber(
if (significandWide != 0 &&
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
- significandWide > (~(Tcl_WideUInt)0 >> shift))) {
+ significandWide > ((Tcl_WideUInt)-1 >> shift))) {
significandOverflow = 1;
TclInitBignumFromWideUInt(&significandBig,
significandWide);
@@ -867,7 +867,7 @@ TclParseNumber(
if (significandWide != 0 &&
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
- significandWide > (~(Tcl_WideUInt)0 >> shift))) {
+ significandWide > ((Tcl_WideUInt)-1 >> shift))) {
significandOverflow = 1;
TclInitBignumFromWideUInt(&significandBig,
significandWide);
@@ -1451,7 +1451,7 @@ AccumulateDecimalDigit(
*wideRepPtr = digit;
return 0;
} else if (numZeros >= maxpow10_wide
- || w > ((~(Tcl_WideUInt)0)-digit)/pow10_wide[numZeros+1]) {
+ || w > ((Tcl_WideUInt)-1-digit)/pow10_wide[numZeros+1]) {
/*
* Wide multiplication will overflow. Expand the number to a
* bignum and fall through into the bignum case.
@@ -4649,7 +4649,7 @@ TclCeil(
mp_int b;
mp_init(&b);
- if (mp_isneg(a)) {
+ if (a->sign != MP_ZPOS) {
mp_neg(a, &b);
r = -TclFloor(&b);
} else {
@@ -4666,7 +4666,7 @@ TclCeil(
mp_int d;
mp_init(&d);
mp_div_2d(a, -shift, &b, &d);
- exact = mp_iszero(&d);
+ exact = d.used == 0;
mp_clear(&d);
} else {
mp_copy(a, &b);
@@ -4706,7 +4706,7 @@ TclFloor(
mp_int b;
mp_init(&b);
- if (mp_isneg(a)) {
+ if (a->sign != MP_ZPOS) {
mp_neg(a, &b);
r = -TclCeil(&b);
} else {
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index ce5ebd1..b1a1cee 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -57,6 +57,7 @@
#undef TclWinSetSockOpt
#undef TclWinNToHS
#undef TclStaticPackage
+#undef TclBNInitBignumFromLong
#undef Tcl_BackgroundError
#define TclStaticPackage Tcl_StaticPackage
@@ -102,8 +103,12 @@ static int TclSockMinimumBuffersOld(int sock, int size)
# define Tcl_NewLongObj 0
# define Tcl_DbNewLongObj 0
# define Tcl_BackgroundError 0
-
#else
+#define TclBNInitBignumFromLong initBignumFromLong
+static void TclBNInitBignumFromLong(mp_int *a, long b)
+{
+ TclInitBignumFromWideInt(a, b);
+}
#define TclSetStartupScriptPath setStartupScriptPath
static void TclSetStartupScriptPath(Tcl_Obj *path)
{
@@ -154,7 +159,6 @@ TclWinGetPlatformId(void)
#endif
# define TclBNInitBignumFromWideUInt TclInitBignumFromWideUInt
# define TclBNInitBignumFromWideInt TclInitBignumFromWideInt
-# define TclBNInitBignumFromLong TclInitBignumFromLong
#endif /* TCL_NO_DEPRECATED */
#ifdef _WIN32
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index b7cf97f..cb99df7 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -30,19 +30,12 @@
/* Define custom memory allocation for libtommath */
-/* MODULE_SCOPE void* TclBNAlloc( size_t ); */
-#define TclBNAlloc(s) ((void*)ckalloc((size_t)(s)))
-/* MODULE_SCOPE void* TclBNRealloc( void*, size_t ); */
-#define TclBNRealloc(x,s) ((void*)ckrealloc((char*)(x),(size_t)(s)))
-/* MODULE_SCOPE void TclBNFree( void* ); */
-#define TclBNFree(x) (ckfree((char*)(x)))
-/* MODULE_SCOPE void* TclBNCalloc( size_t, size_t ); */
-/* unused - no macro */
-
-#define XMALLOC(x) TclBNAlloc(x)
-#define XFREE(x) TclBNFree(x)
-#define XREALLOC(x,n) TclBNRealloc(x,n)
-#define XCALLOC(n,x) TclBNCalloc(n,x)
+/* MODULE_SCOPE void* XMALLOC( size_t ); */
+#define XMALLOC(s) ((void*)ckalloc((size_t)(s)))
+/* MODULE_SCOPE void* XREALLOC( void*, size_t ); */
+#define XREALLOC(x,s) ((void*)ckrealloc((char*)(x),(size_t)(s)))
+/* MODULE_SCOPE void XFREE( void* ); */
+#define XFREE(x) (ckfree((char*)(x)))
/* Rename the global symbols in libtommath to avoid linkage conflicts */
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index 9e7bf4b..236a8cf 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -93,39 +93,7 @@ TclBN_revision(void)
/*
*----------------------------------------------------------------------
*
- * TclInitBignumFromLong --
- *
- * Allocate and initialize a 'bignum' from a native 'long'.
- *
- * Results:
- * None.
- *
- * Side effects:
- * The 'bignum' is constructed.
- *
- *----------------------------------------------------------------------
- */
-
-void
-TclInitBignumFromLong(
- mp_int *a,
- long v)
-{
- if (mp_init_size(a, (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) {
- Tcl_Panic("initialization failure in TclInitBignumFromLong");
- }
- if (v < (long)0) {
- mp_set_long_long(a, (Tcl_WideUInt)(-(Tcl_WideInt)v));
- mp_neg(a, a);
- } else {
- mp_set_long_long(a, (Tcl_WideUInt)v);
- }
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNInitBignumFromWideInt --
+ * TclInitBignumFromWideInt --
*
* Allocate and initialize a 'bignum' from a Tcl_WideInt
*
@@ -146,7 +114,7 @@ TclInitBignumFromWideInt(
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) {
+ if (v < 0) {
mp_set_long_long(a, (Tcl_WideUInt)(-v));
mp_neg(a, a);
} else {
@@ -157,7 +125,7 @@ TclInitBignumFromWideInt(
/*
*----------------------------------------------------------------------
*
- * TclBNInitBignumFromWideUInt --
+ * TclInitBignumFromWideUInt --
*
* Allocate and initialize a 'bignum' from a Tcl_WideUInt
*
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index e6576a5..eb77dd1 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -3726,7 +3726,7 @@ GetWideForIndex(
/* objPtr holds an integer outside the signed wide range */
/* Truncate to the signed wide range. */
- *widePtr = mp_isneg((mp_int *)cd) ? WIDE_MIN : WIDE_MAX;
+ *widePtr = (((mp_int *)cd)->sign != MP_ZPOS) ? WIDE_MIN : WIDE_MAX;
return TCL_OK;
}
@@ -3839,7 +3839,7 @@ GetWideForIndex(
} else {
/* sum holds an integer outside the signed wide range */
/* Truncate to the signed wide range. */
- if (mp_isneg((mp_int *)cd)) {
+ if (((mp_int *)cd)->sign != MP_ZPOS) {
*widePtr = WIDE_MIN;
} else {
*widePtr = WIDE_MAX;
@@ -3986,7 +3986,7 @@ GetEndOffsetFromObj(
if (t == TCL_NUMBER_BIG) {
/* Truncate to the signed wide range. */
- if (mp_isneg((mp_int *)cd)) {
+ if (((mp_int *)cd)->sign != MP_ZPOS) {
offset = (bytes[3] == '-') ? WIDE_MAX : WIDE_MIN;
} else {
offset = (bytes[3] == '-') ? WIDE_MIN : WIDE_MAX;