summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclBinary.c6
-rw-r--r--generic/tclScan.c31
-rw-r--r--generic/tclStubInit.c3
-rw-r--r--generic/tclTomMath.decls3
-rw-r--r--generic/tclTomMath.h20
-rw-r--r--generic/tclTomMathDecls.h9
-rw-r--r--generic/tclTomMathInterface.c20
7 files changed, 56 insertions, 36 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index e28535e..3f263bc 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -2349,8 +2349,10 @@ ScanNumber(
Tcl_Obj *bigObj = NULL;
mp_int big;
- TclBNInitBignumFromWideUInt(&big, uwvalue);
- bigObj = Tcl_NewBignumObj(&big);
+ if (mp_init(&big) == MP_OKAY) {
+ mp_set_ull(&big, uwvalue);
+ bigObj = Tcl_NewBignumObj(&big);
+ }
return bigObj;
}
return Tcl_NewWideIntObj((Tcl_WideInt) uwvalue);
diff --git a/generic/tclScan.c b/generic/tclScan.c
index f481cc9..5edbffa 100644
--- a/generic/tclScan.c
+++ b/generic/tclScan.c
@@ -579,9 +579,6 @@ Tcl_ScanObjCmd(
Tcl_UniChar ch = 0, sch = 0;
Tcl_Obj **objs = NULL, *objPtr = NULL;
int flags;
- char buf[513]; /* Temporary buffer to hold scanned number
- * strings before they are passed to
- * strtoul. */
if (objc < 3) {
Tcl_WrongNumArgs(interp, 1, objv,
@@ -931,8 +928,16 @@ Tcl_ScanObjCmd(
}
}
if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
- sprintf(buf, "%" TCL_LL_MODIFIER "u", wideValue);
- Tcl_SetStringObj(objPtr, buf, -1);
+ mp_int big;
+ if (mp_init(&big) != MP_OKAY) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "insufficient memory to create bignum", -1));
+ Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
+ return TCL_ERROR;
+ } else {
+ mp_set_ull(&big, (Tcl_WideUInt)wideValue);
+ Tcl_SetBignumObj(objPtr, &big);
+ }
} else {
TclSetIntObj(objPtr, wideValue);
}
@@ -969,8 +974,20 @@ Tcl_ScanObjCmd(
}
}
if ((flags & SCAN_UNSIGNED) && (value < 0)) {
- sprintf(buf, "%lu", value); /* INTL: ISO digit */
- Tcl_SetStringObj(objPtr, buf, -1);
+#ifdef TCL_WIDE_INT_IS_LONG
+ mp_int big;
+ if (mp_init(&big) != MP_OKAY) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "insufficient memory to create bignum", -1));
+ Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
+ return TCL_ERROR;
+ } else {
+ mp_set_ull(&big, (unsigned long)value);
+ Tcl_SetBignumObj(objPtr, &big);
+ }
+#else
+ Tcl_SetWideIntObj(objPtr, (unsigned long)value);
+#endif
} else {
TclSetIntObj(objPtr, value);
}
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 54cd83c..6f3b2e9 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -83,6 +83,7 @@ static int TclSockMinimumBuffersOld(int sock, int size)
#endif
MP_SET_UNSIGNED(mp_set_ull, Tcl_WideUInt)
+MP_SET_SIGNED(mp_set_ll, mp_set_ull, Tcl_WideInt, Tcl_WideUInt)
MP_GET_MAG(mp_get_mag_ull, Tcl_WideUInt)
mp_err TclBN_mp_set_int(mp_int *a, unsigned long i)
@@ -1053,7 +1054,7 @@ const TclTomMathStubs tclTomMathStubs = {
TclBN_mp_expt_d_ex, /* 67 */
TclBN_mp_set_ull, /* 68 */
TclBN_mp_get_mag_ull, /* 69 */
- 0, /* 70 */
+ TclBN_mp_set_ll, /* 70 */
TclBN_mp_get_mag_ul, /* 71 */
0, /* 72 */
TclBN_mp_tc_and, /* 73 */
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 723bb0a..b83059e 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -244,6 +244,9 @@ declare 68 {
declare 69 {
Tcl_WideUInt MP_WUR TclBN_mp_get_mag_ull(const mp_int *a)
}
+declare 70 {
+ void TclBN_mp_set_ll(mp_int *a, Tcl_WideInt i)
+}
declare 71 {
unsigned long MP_WUR TclBN_mp_get_mag_ul(const mp_int *a)
}
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index 557eff1..1ecd5be 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -368,7 +368,7 @@ uint64_t mp_get_mag_u64(const mp_int *a) MP_WUR;
unsigned long mp_get_mag_ul(const mp_int *a) MP_WUR;
*/
/*
-Tcl_WideUInt mp_get_mag_ull(const mp_int *a) MP_WUR;
+unsigned long long mp_get_mag_ull(const mp_int *a) MP_WUR;
*/
/* get integer, set integer (long) */
@@ -391,24 +391,24 @@ void mp_set_ul(mp_int *a, unsigned long b);
mp_err mp_init_ul(mp_int *a, unsigned long b) MP_WUR;
*/
-/* get integer, set integer (Tcl_WideInt) */
+/* get integer, set integer (long long) */
/*
-Tcl_WideInt mp_get_ll(const mp_int *a) MP_WUR;
+long long mp_get_ll(const mp_int *a) MP_WUR;
*/
/*
-void mp_set_ll(mp_int *a, Tcl_WideInt b);
+void mp_set_ll(mp_int *a, long long b);
*/
/*
-mp_err mp_init_ll(mp_int *a, Tcl_WideInt b) MP_WUR;
+mp_err mp_init_ll(mp_int *a, long long b) MP_WUR;
*/
-/* get integer, set integer (Tcl_WideUInt) */
+/* get integer, set integer (unsigned long long) */
#define mp_get_ull(a) ((Tcl_WideUInt)mp_get_ll(a))
/*
-void mp_set_ull(mp_int *a, Tcl_WideUInt b);
+void mp_set_ull(mp_int *a, unsigned long long b);
*/
/*
-mp_err mp_init_ull(mp_int *a, Tcl_WideUInt b) MP_WUR;
+mp_err mp_init_ull(mp_int *a, unsigned long long b) MP_WUR;
*/
/* set to single unsigned digit, up to MP_DIGIT_MAX */
@@ -427,7 +427,7 @@ MP_DEPRECATED(mp_get_mag_u32/mp_get_u32) unsigned long mp_get_int(const mp_int *
MP_DEPRECATED(mp_get_mag_ul/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR;
*/
/*
-MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) Tcl_WideUInt mp_get_long_long(const mp_int *a) MP_WUR;
+MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) unsigned long long mp_get_long_long(const mp_int *a) MP_WUR;
*/
/*
MP_DEPRECATED(mp_set_ul) mp_err mp_set_int(mp_int *a, unsigned long b);
@@ -436,7 +436,7 @@ MP_DEPRECATED(mp_set_ul) mp_err mp_set_int(mp_int *a, unsigned long b);
MP_DEPRECATED(mp_set_ul) mp_err mp_set_long(mp_int *a, unsigned long b);
*/
/*
-MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, Tcl_WideUInt b);
+MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, unsigned long long b);
*/
/*
MP_DEPRECATED(mp_init_ul) mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR;
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index cead9ad..a7b8dcd 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -101,6 +101,7 @@ MODULE_SCOPE mp_err TclBN_s_mp_expt_u32(const mp_int *a, unsigned int b, mp_int
#define mp_read_radix TclBN_mp_read_radix
#define mp_rshd TclBN_mp_rshd
#define mp_set_int(a,b) (MP_DEPRECATED_PRAGMA("replaced by mp_set_ul") (TclBN_mp_set_ul((a),((unsigned int)(b))),MP_OKAY))
+#define mp_set_ll TclBN_mp_set_ll
#define mp_set_long(a,b) (MP_DEPRECATED_PRAGMA("replaced by mp_set_ul") (TclBN_mp_set_ul((a),(b)),MP_OKAY))
#define mp_set_long_long(a,b) (MP_DEPRECATED_PRAGMA("replaced by mp_set_ull") (TclBN_mp_set_ull((a),(b)),MP_OKAY))
#define mp_set_ul TclBN_mp_set_ul
@@ -351,7 +352,8 @@ mp_err TclBN_mp_expt_d_ex(const mp_int *a, unsigned int b,
EXTERN void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i);
/* 69 */
EXTERN Tcl_WideUInt TclBN_mp_get_mag_ull(const mp_int *a) MP_WUR;
-/* Slot 70 is reserved */
+/* 70 */
+EXTERN void TclBN_mp_set_ll(mp_int *a, Tcl_WideInt i);
/* 71 */
EXTERN unsigned long TclBN_mp_get_mag_ul(const mp_int *a) MP_WUR;
/* Slot 72 is reserved */
@@ -452,7 +454,7 @@ typedef struct TclTomMathStubs {
TCL_DEPRECATED_API("Use mp_expt_u32") mp_err (*tclBN_mp_expt_d_ex) (const mp_int *a, unsigned int b, mp_int *c, int fast); /* 67 */
void (*tclBN_mp_set_ull) (mp_int *a, Tcl_WideUInt i); /* 68 */
Tcl_WideUInt (*tclBN_mp_get_mag_ull) (const mp_int *a) MP_WUR; /* 69 */
- void (*reserved70)(void);
+ void (*tclBN_mp_set_ll) (mp_int *a, Tcl_WideInt i); /* 70 */
unsigned long (*tclBN_mp_get_mag_ul) (const mp_int *a) MP_WUR; /* 71 */
void (*reserved72)(void);
mp_err (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c) MP_WUR; /* 73 */
@@ -617,7 +619,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_set_ull) /* 68 */
#define TclBN_mp_get_mag_ull \
(tclTomMathStubsPtr->tclBN_mp_get_mag_ull) /* 69 */
-/* Slot 70 is reserved */
+#define TclBN_mp_set_ll \
+ (tclTomMathStubsPtr->tclBN_mp_set_ll) /* 70 */
#define TclBN_mp_get_mag_ul \
(tclTomMathStubsPtr->tclBN_mp_get_mag_ul) /* 71 */
/* Slot 72 is reserved */
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index 589599e..9cb5c37 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -111,16 +111,10 @@ TclBNInitBignumFromWideInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideInt v) /* Initial value */
{
- if (mp_init(a) != MP_OKAY) {
- wipanic:
- Tcl_Panic("initialization failure in TclBNInitBignumFromWideInt");
- }
- if (v < 0) {
- mp_set_ull(a, (Tcl_WideUInt)(-v));
- if (mp_neg(a, a) != MP_OKAY) goto wipanic;
- } else {
- mp_set_ull(a, (Tcl_WideUInt)v);
+ if (mp_init(a) != MP_OKAY) {
+ Tcl_Panic("insufficient memory to create bignum");
}
+ mp_set_ll(a, v);
}
/*
@@ -144,10 +138,10 @@ TclBNInitBignumFromWideUInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideUInt v) /* Initial value */
{
- if (mp_init(a) != MP_OKAY) {
- Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt");
- }
- mp_set_ull(a, v);
+ if (mp_init(a) != MP_OKAY) {
+ Tcl_Panic("insufficient memory to create bignum");
+ }
+ mp_set_ull(a, v);
}
/*