summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-08-22 13:55:35 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-08-22 13:55:35 (GMT)
commite2928c8a2636a4ad0ebe9b07eb692415ef698fd5 (patch)
tree5535b08d61d86573b946229a238a42237e4cf438
parenta0294a71225920d0fbe961abdc5e5f0886214fe8 (diff)
downloadtcl-e2928c8a2636a4ad0ebe9b07eb692415ef698fd5.zip
tcl-e2928c8a2636a4ad0ebe9b07eb692415ef698fd5.tar.gz
tcl-e2928c8a2636a4ad0ebe9b07eb692415ef698fd5.tar.bz2
[kennykb_numerics_branch]
* generic/tclInt.h: New internal routine TclSetBignumIntRep * generic/tclObj.c: consolidates packing of bignum value into * generic/tclStrToD.c: a Tcl_Obj within one source code file.
-rw-r--r--ChangeLog4
-rw-r--r--generic/tclInt.h4
-rw-r--r--generic/tclObj.c22
-rwxr-xr-xgeneric/tclStrToD.c41
4 files changed, 25 insertions, 46 deletions
diff --git a/ChangeLog b/ChangeLog
index 494152f..2c1b603 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
[kennykb_numerics_branch]
+ * generic/tclInt.h: New internal routine TclSetBignumIntRep
+ * generic/tclObj.c: consolidates packing of bignum value into
+ * generic/tclStrToD.c: a Tcl_Obj within one source code file.
+
* tests/expr.test: Corrected the wideIs64bit constraint.
* tests/format.test:
* tests/scan.test:
diff --git a/generic/tclInt.h b/generic/tclInt.h
index c50b760..4a8413e 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclInt.h,v 1.202.2.25 2005/08/22 03:49:39 dgp Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.202.2.26 2005/08/22 13:55:36 dgp Exp $
*/
#ifndef _TCLINT
@@ -2147,6 +2147,8 @@ MODULE_SCOPE void TclRemoveScriptLimitCallbacks _ANSI_ARGS_((
Tcl_Interp *interp));
MODULE_SCOPE void TclSetBgErrorHandler _ANSI_ARGS_((Tcl_Interp *interp,
Tcl_Obj *cmdPrefix));
+MODULE_SCOPE void TclSetBignumIntRep _ANSI_ARGS_((Tcl_Obj *objPtr,
+ mp_int *bignumValue));
MODULE_SCOPE void TclSetProcessGlobalValue _ANSI_ARGS_ ((
ProcessGlobalValue *pgvPtr, Tcl_Obj *newValue,
Tcl_Encoding encoding));
diff --git a/generic/tclObj.c b/generic/tclObj.c
index e8f7ed9..558f1df 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclObj.c,v 1.72.2.26 2005/08/19 21:55:21 dgp Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.72.2.27 2005/08/22 13:55:36 dgp Exp $
*/
#include "tclInt.h"
@@ -2792,12 +2792,6 @@ Tcl_SetBignumObj(
if (Tcl_IsShared(objPtr)) {
Tcl_Panic("Tcl_SetBignumObj called with shared object");
}
- if (bignumValue->used > 0x7fff) {
- Tcl_Panic("Tcl_SetBignumObj: too large for packed bignum");
- }
- if (bignumValue->alloc > 0x7fff) {
- mp_shrink(bignumValue);
- }
#ifdef BIGNUM_AUTO_NARROW
if (bignumValue->used
<= (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT) {
@@ -2853,6 +2847,20 @@ Tcl_SetBignumObj(
#endif
TclInvalidateStringRep(objPtr);
TclFreeIntRep(objPtr);
+ TclSetBignumIntRep(objPtr, bignumValue);
+}
+
+void
+TclSetBignumIntRep(objPtr, bignumValue)
+ Tcl_Obj *objPtr;
+ mp_int *bignumValue;
+{
+ if (bignumValue->used > 0x7fff) {
+ Tcl_Panic("TclSetBignumIntRep: too large for packed bignum");
+ }
+ if (bignumValue->alloc > 0x7fff) {
+ mp_shrink(bignumValue);
+ }
objPtr->typePtr = &tclBignumType;
PACK_BIGNUM(*bignumValue, objPtr);
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index 658177f..7ed590d 100755
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -15,7 +15,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStrToD.c,v 1.1.2.22 2005/08/22 03:49:40 dgp Exp $
+ * RCS: @(#) $Id: tclStrToD.c,v 1.1.2.23 2005/08/22 13:55:36 dgp Exp $
*
*----------------------------------------------------------------------
*/
@@ -166,27 +166,6 @@ static double Pow10TimesFrExp _ANSI_ARGS_(( int exponent,
int* machexp ));
static double SafeLdExp _ANSI_ARGS_(( double fraction, int exponent ));
-/*
- * Macros to pack/unpack a bignum's fields in a Tcl_Obj internal rep
- */
-
-#define PACK_BIGNUM( bignum, objPtr ) \
- do { \
- (objPtr)->internalRep.bignumValue.digits = (void*) (bignum).dp; \
- (objPtr)->internalRep.bignumValue.misc = ( \
- ( (bignum).sign << 30 ) \
- | ( (bignum).alloc << 15 ) \
- | ( (bignum).used ) ); \
- } while ( 0 )
-
-#define UNPACK_BIGNUM( objPtr, bignum ) \
- do { \
- (bignum).dp = (mp_digit*) (objPtr)->internalRep.bignumValue.digits; \
- (bignum).sign = (objPtr)->internalRep.bignumValue.misc >> 30; \
- (bignum).alloc = ( (objPtr)->internalRep.bignumValue.misc >> 15 ) \
- & 0x7fff; \
- (bignum).used = (objPtr)->internalRep.bignumValue.misc & 0x7fff; \
- } while ( 0 )
/*
*----------------------------------------------------------------------
@@ -911,19 +890,12 @@ TclParseNumber( Tcl_Interp* interp,
}
}
if (octalSignificandOverflow) {
- if (octalSignificandBig.used > 0x7fff) {
- Tcl_Panic("TclParseNumber: too large for packed bignum");
- }
- if (octalSignificandBig.alloc > 0x7fff) {
- mp_shrink(&octalSignificandBig);
- }
if (signum) {
octalSignificandBig.sign = MP_NEG;
} else {
octalSignificandBig.sign = MP_ZPOS;
}
- objPtr->typePtr = &tclBignumType;
- PACK_BIGNUM(octalSignificandBig,objPtr);
+ TclSetBignumIntRep(objPtr, &octalSignificandBig);
octalSignificandOverflow = 0;
}
break;
@@ -976,19 +948,12 @@ TclParseNumber( Tcl_Interp* interp,
}
}
if (significandOverflow) {
- if (significandBig.used > 0x7fff) {
- Tcl_Panic("TclParseNumber: too large for packed bignum");
- }
- if (significandBig.alloc > 0x7fff) {
- mp_shrink(&significandBig);
- }
if (signum) {
significandBig.sign = MP_NEG;
} else {
significandBig.sign = MP_ZPOS;
}
- objPtr->typePtr = &tclBignumType;
- PACK_BIGNUM(significandBig,objPtr);
+ TclSetBignumIntRep(objPtr, &significandBig);
significandOverflow = 0;
}
break;