summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-11-15 14:41:03 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-11-15 14:41:03 (GMT)
commitba25919a60b33720617b9f5c8fd1ef4a1a92d0c7 (patch)
tree2354a7bd4cd21a58bc66fd4bc3127e0540d96fd7 /generic
parentc7ea989512ae5da9dbbad648d0c0b39158b97404 (diff)
parent9d2a40a82608f1e3d87aac7de2190dfcd92470da (diff)
downloadtcl-ba25919a60b33720617b9f5c8fd1ef4a1a92d0c7.zip
tcl-ba25919a60b33720617b9f5c8fd1ef4a1a92d0c7.tar.gz
tcl-ba25919a60b33720617b9f5c8fd1ef4a1a92d0c7.tar.bz2
Merge 8.7
Diffstat (limited to 'generic')
-rw-r--r--generic/tcl.decls9
-rw-r--r--generic/tclLink.c19
-rw-r--r--generic/tclObj.c34
-rw-r--r--generic/tclStubInit.c6
-rw-r--r--generic/tclTomMath.decls7
-rw-r--r--generic/tclTomMathDecls.h22
6 files changed, 47 insertions, 50 deletions
diff --git a/generic/tcl.decls b/generic/tcl.decls
index 85fe54f..567d0c5 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -2560,7 +2560,14 @@ declare 685 {
void Tcl_SetWideUIntObj(Tcl_Obj *objPtr, Tcl_WideUInt uwideValue)
}
-# ----- BASELINE -- FOR -- 8.7.0 ----- #
+# TIP #650 (reserved)
+#declare 686 {
+# int Tcl_GetWideUIntFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr,
+# Tcl_WideUInt *uwidePtr)
+#}
+
+
+# ----- BASELINE -- FOR -- 8.7.0 / 9.0.0 ----- #
##############################################################################
diff --git a/generic/tclLink.c b/generic/tclLink.c
index 1973067..397c9bc 100644
--- a/generic/tclLink.c
+++ b/generic/tclLink.c
@@ -537,15 +537,10 @@ GetUWide(
} else if (type == TCL_NUMBER_BIG) {
mp_int *numPtr = (mp_int *)clientData;
Tcl_WideUInt value = 0;
- union {
- Tcl_WideUInt value;
- unsigned char bytes[sizeof(Tcl_WideUInt)];
- } scratch;
size_t numBytes;
- unsigned char *bytes = scratch.bytes;
- if (numPtr->sign || (MP_OKAY != mp_to_ubin(numPtr,
- bytes, sizeof(Tcl_WideUInt), &numBytes))) {
+ if (numPtr->sign || (MP_OKAY != mp_pack(&value, 1,
+ &numBytes, 0, sizeof(Tcl_WideUInt), 0, 0, numPtr))) {
/*
* If the sign bit is set (a negative value) or if the value
* can't possibly fit in the bits of an unsigned wide, there's
@@ -553,16 +548,6 @@ GetUWide(
*/
return 1;
}
-#ifndef WORDS_BIGENDIAN
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
- }
-#else /* WORDS_BIGENDIAN */
- /*
- * Big-endian can read the value directly.
- */
- value = scratch.value;
-#endif /* WORDS_BIGENDIAN */
*uwidePtr = value;
return 0;
}
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 4639731..d512b52 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -3124,15 +3124,12 @@ Tcl_GetLongFromObj(
{
mp_int big;
- unsigned long scratch, value = 0;
- unsigned char *bytes = (unsigned char *) &scratch;
+ unsigned long value = 0;
size_t numBytes;
TclUnpackBignum(objPtr, big);
- if (mp_to_ubin(&big, bytes, sizeof(long), &numBytes) == MP_OKAY) {
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
- }
+ if (mp_pack(&value, 1,
+ &numBytes, 0, sizeof(Tcl_WideUInt), 0, 0, &big) == MP_OKAY) {
if (big.sign) {
if (value <= 1 + (unsigned long)LONG_MAX) {
*longPtr = (long)(-value);
@@ -3431,14 +3428,10 @@ Tcl_GetWideIntFromObj(
mp_int big;
Tcl_WideUInt value = 0;
size_t numBytes;
- Tcl_WideInt scratch;
- unsigned char *bytes = (unsigned char *) &scratch;
TclUnpackBignum(objPtr, big);
- if (mp_to_ubin(&big, bytes, sizeof(Tcl_WideInt), &numBytes) == MP_OKAY) {
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
- }
+ if (mp_pack(&value, 1,
+ &numBytes, 0, sizeof(Tcl_WideUInt), 0, 0, &big) == MP_OKAY) {
if (big.sign) {
if (value <= 1 + ~(Tcl_WideUInt)WIDE_MIN) {
*wideIntPtr = (Tcl_WideInt)(-value);
@@ -3511,21 +3504,18 @@ TclGetWideBitsFromObj(
mp_int big;
mp_err err;
- Tcl_WideUInt value = 0, scratch;
+ Tcl_WideUInt value = 0;
size_t numBytes;
- unsigned char *bytes = (unsigned char *) &scratch;
Tcl_GetBignumFromObj(NULL, objPtr, &big);
err = mp_mod_2d(&big, (int) (CHAR_BIT * sizeof(Tcl_WideInt)), &big);
if (err == MP_OKAY) {
- err = mp_to_ubin(&big, bytes, sizeof(Tcl_WideInt), &numBytes);
+ err = mp_pack(&value, 1,
+ &numBytes, 0, sizeof(Tcl_WideUInt), 0, 0, &big);
}
if (err != MP_OKAY) {
return TCL_ERROR;
}
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
- }
*wideIntPtr = !big.sign ? (Tcl_WideInt)value : -(Tcl_WideInt)value;
mp_clear(&big);
return TCL_OK;
@@ -3895,19 +3885,15 @@ Tcl_SetBignumObj(
{
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");
}
- if (mp_to_ubin(bignumValue, bytes, sizeof(Tcl_WideUInt), &numBytes) != MP_OKAY) {
+ if (mp_pack(&value, 1,
+ &numBytes, 0, sizeof(Tcl_WideUInt), 0, 0, bignumValue) != MP_OKAY) {
goto tooLargeForWide;
}
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
- }
if (value > ((Tcl_WideUInt)WIDE_MAX + bignumValue->sign)) {
goto tooLargeForWide;
}
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 12e5e38..8ec16ae 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -232,6 +232,8 @@ int TclParseArgsObjv(Tcl_Interp *interp,
#define TclBN_mp_mul_2d mp_mul_2d
#define TclBN_mp_neg mp_neg
#define TclBN_mp_or mp_or
+#define TclBN_mp_pack mp_pack
+#define TclBN_mp_pack_count mp_pack_count
#define TclBN_mp_radix_size mp_radix_size
#define TclBN_mp_reverse mp_reverse
#define TclBN_mp_read_radix mp_read_radix
@@ -1325,12 +1327,12 @@ const TclTomMathStubs tclTomMathStubs = {
TclBN_mp_get_mag_u64, /* 69 */
TclBN_mp_set_i64, /* 70 */
TclBN_mp_unpack, /* 71 */
- 0, /* 72 */
+ TclBN_mp_pack, /* 72 */
TclBN_mp_tc_and, /* 73 */
TclBN_mp_tc_or, /* 74 */
TclBN_mp_tc_xor, /* 75 */
TclBN_mp_signed_rsh, /* 76 */
- 0, /* 77 */
+ TclBN_mp_pack_count, /* 77 */
TclBN_mp_to_ubin, /* 78 */
TclBN_mp_div_ld, /* 79 */
TclBN_mp_to_radix, /* 80 */
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 3a3b9a8..27c4f98 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -247,6 +247,10 @@ declare 71 {
mp_err MP_WUR TclBN_mp_unpack(mp_int *rop, size_t count, mp_order order, size_t size,
mp_endian endian, size_t nails, const void *op)
}
+declare 72 {
+ mp_err MP_WUR TclBN_mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order,
+ size_t size, mp_endian endian, size_t nails, const mp_int *op)
+}
# Added in libtommath 1.1.0
declare 73 {deprecated {merged with mp_and}} {
@@ -261,6 +265,9 @@ declare 75 {deprecated {merged with mp_xor}} {
declare 76 {
mp_err MP_WUR TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c)
}
+declare 77 {
+ size_t MP_WUR TclBN_mp_pack_count(const mp_int *a, size_t nails, size_t size)
+}
# Added in libtommath 1.2.0
declare 78 {
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 8d12adf..009f914 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -125,6 +125,8 @@ MODULE_SCOPE mp_err TclBN_mp_set_int(mp_int *a, unsigned long b);
#define mp_mul_2d TclBN_mp_mul_2d
#define mp_neg TclBN_mp_neg
#define mp_or TclBN_mp_or
+#define mp_pack TclBN_mp_pack
+#define mp_pack_count TclBN_mp_pack_count
#define mp_radix_size TclBN_mp_radix_size
#define mp_read_radix TclBN_mp_read_radix
#define mp_rshd TclBN_mp_rshd
@@ -394,7 +396,11 @@ EXTERN mp_err TclBN_mp_unpack(mp_int *rop, size_t count,
mp_order order, size_t size,
mp_endian endian, size_t nails,
const void *op) MP_WUR;
-/* Slot 72 is reserved */
+/* 72 */
+EXTERN mp_err TclBN_mp_pack(void *rop, size_t maxcount,
+ size_t *written, mp_order order, size_t size,
+ mp_endian endian, size_t nails,
+ const mp_int *op) MP_WUR;
/* 73 */
TCL_DEPRECATED("merged with mp_and")
mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b,
@@ -410,7 +416,9 @@ mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
/* 76 */
EXTERN mp_err TclBN_mp_signed_rsh(const mp_int *a, int b,
mp_int *c) MP_WUR;
-/* Slot 77 is reserved */
+/* 77 */
+EXTERN size_t TclBN_mp_pack_count(const mp_int *a, size_t nails,
+ size_t size) MP_WUR;
/* 78 */
EXTERN int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf,
size_t maxlen, size_t *written) MP_WUR;
@@ -497,12 +505,12 @@ typedef struct TclTomMathStubs {
uint64_t (*tclBN_mp_get_mag_u64) (const mp_int *a) MP_WUR; /* 69 */
void (*tclBN_mp_set_i64) (mp_int *a, int64_t i); /* 70 */
mp_err (*tclBN_mp_unpack) (mp_int *rop, size_t count, mp_order order, size_t size, mp_endian endian, size_t nails, const void *op) MP_WUR; /* 71 */
- void (*reserved72)(void);
+ mp_err (*tclBN_mp_pack) (void *rop, size_t maxcount, size_t *written, mp_order order, size_t size, mp_endian endian, size_t nails, const mp_int *op) MP_WUR; /* 72 */
TCL_DEPRECATED_API("merged with mp_and") mp_err (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
TCL_DEPRECATED_API("merged with mp_or") mp_err (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
TCL_DEPRECATED_API("merged with mp_xor") mp_err (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
mp_err (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c) MP_WUR; /* 76 */
- void (*reserved77)(void);
+ size_t (*tclBN_mp_pack_count) (const mp_int *a, size_t nails, size_t size) MP_WUR; /* 77 */
int (*tclBN_mp_to_ubin) (const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written) MP_WUR; /* 78 */
mp_err (*tclBN_mp_div_ld) (const mp_int *a, uint64_t b, mp_int *q, uint64_t *r) MP_WUR; /* 79 */
int (*tclBN_mp_to_radix) (const mp_int *a, char *str, size_t maxlen, size_t *written, int radix) MP_WUR; /* 80 */
@@ -664,7 +672,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_set_i64) /* 70 */
#define TclBN_mp_unpack \
(tclTomMathStubsPtr->tclBN_mp_unpack) /* 71 */
-/* Slot 72 is reserved */
+#define TclBN_mp_pack \
+ (tclTomMathStubsPtr->tclBN_mp_pack) /* 72 */
#define TclBN_mp_tc_and \
(tclTomMathStubsPtr->tclBN_mp_tc_and) /* 73 */
#define TclBN_mp_tc_or \
@@ -673,7 +682,8 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */
#define TclBN_mp_signed_rsh \
(tclTomMathStubsPtr->tclBN_mp_signed_rsh) /* 76 */
-/* Slot 77 is reserved */
+#define TclBN_mp_pack_count \
+ (tclTomMathStubsPtr->tclBN_mp_pack_count) /* 77 */
#define TclBN_mp_to_ubin \
(tclTomMathStubsPtr->tclBN_mp_to_ubin) /* 78 */
#define TclBN_mp_div_ld \