summaryrefslogtreecommitdiffstats
path: root/generic/tclObj.c
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2019-03-05 18:23:26 (GMT)
committersebres <sebres@users.sourceforge.net>2019-03-05 18:23:26 (GMT)
commitf456cd9b3e6743bf15cd756bfc116153fa95605c (patch)
tree85e4e3121d93802d9d5df50157ead27f68ff7a43 /generic/tclObj.c
parent8c315fd31ff823b217374dd32577e04c42674249 (diff)
parentb930511d5b774c13f2cd22d7820ad0acf7069c39 (diff)
downloadtcl-f456cd9b3e6743bf15cd756bfc116153fa95605c.zip
tcl-f456cd9b3e6743bf15cd756bfc116153fa95605c.tar.gz
tcl-f456cd9b3e6743bf15cd756bfc116153fa95605c.tar.bz2
merge 8.7 (TIP#527, New measurement facilities in TCL: New command timerate, performance test suite)
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r--generic/tclObj.c109
1 files changed, 49 insertions, 60 deletions
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 5cf35b4..089945e 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -2711,27 +2711,23 @@ Tcl_GetLongFromObj(
*/
mp_int big;
+ unsigned long scratch, value = 0, numBytes = sizeof(unsigned long);
+ unsigned char *bytes = (unsigned char *) &scratch;
UNPACK_BIGNUM(objPtr, big);
- if ((size_t) big.used <= (CHAR_BIT * sizeof(unsigned long) + DIGIT_BIT - 1)
- / DIGIT_BIT) {
- unsigned long scratch, value = 0, numBytes = sizeof(unsigned long);
- unsigned char *bytes = (unsigned char *) &scratch;
-
- if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
- while (numBytes-- > 0) {
+ if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
+ while (numBytes-- > 0) {
value = (value << CHAR_BIT) | *bytes++;
+ }
+ if (big.sign) {
+ if (value <= 1 + (unsigned long)LONG_MAX) {
+ *longPtr = - (long) value;
+ return TCL_OK;
}
- if (big.sign) {
- if (value <= 1 + (unsigned long)LONG_MAX) {
- *longPtr = - (long) value;
- return TCL_OK;
- }
- } else {
- if (value <= (unsigned long)ULONG_MAX) {
- *longPtr = (long) value;
- return TCL_OK;
- }
+ } else {
+ if (value <= (unsigned long)ULONG_MAX) {
+ *longPtr = (long) value;
+ return TCL_OK;
}
}
}
@@ -2953,29 +2949,25 @@ Tcl_GetWideIntFromObj(
*/
mp_int big;
+ Tcl_WideUInt value = 0;
+ unsigned long numBytes = sizeof(Tcl_WideInt);
+ Tcl_WideInt scratch;
+ unsigned char *bytes = (unsigned char *) &scratch;
UNPACK_BIGNUM(objPtr, big);
- if ((size_t) big.used <= (CHAR_BIT * sizeof(Tcl_WideInt)
- + DIGIT_BIT - 1) / DIGIT_BIT) {
- Tcl_WideUInt value = 0;
- unsigned long numBytes = sizeof(Tcl_WideInt);
- Tcl_WideInt scratch;
- unsigned char *bytes = (unsigned char *) &scratch;
-
- if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
+ if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
+ while (numBytes-- > 0) {
+ value = (value << CHAR_BIT) | *bytes++;
+ }
+ if (big.sign) {
+ if (value <= 1 + ~(Tcl_WideUInt)WIDE_MIN) {
+ *wideIntPtr = - (Tcl_WideInt) value;
+ return TCL_OK;
}
- if (big.sign) {
- if (value <= 1 + ~(Tcl_WideUInt)WIDE_MIN) {
- *wideIntPtr = - (Tcl_WideInt) value;
- return TCL_OK;
- }
- } else {
- if (value <= (Tcl_WideUInt)WIDE_MAX) {
- *wideIntPtr = (Tcl_WideInt) value;
- return TCL_OK;
- }
+ } else {
+ if (value <= (Tcl_WideUInt)WIDE_MAX) {
+ *wideIntPtr = (Tcl_WideInt) value;
+ return TCL_OK;
}
}
}
@@ -3412,33 +3404,30 @@ Tcl_SetBignumObj(
Tcl_Obj *objPtr, /* Object to set */
mp_int *bignumValue) /* Value to store */
{
+ Tcl_WideUInt value = 0;
+ unsigned long numBytes = sizeof(Tcl_WideUInt);
+ Tcl_WideUInt scratch;
+ unsigned char *bytes = (unsigned char *) &scratch;
+
if (Tcl_IsShared(objPtr)) {
Tcl_Panic("%s called with shared object", "Tcl_SetBignumObj");
}
- if ((size_t) bignumValue->used
- <= (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT) {
- Tcl_WideUInt value = 0;
- unsigned long numBytes = sizeof(Tcl_WideUInt);
- Tcl_WideUInt scratch;
- unsigned char *bytes = (unsigned char *) &scratch;
-
- if (mp_to_unsigned_bin_n(bignumValue, bytes, &numBytes) != MP_OKAY) {
- goto tooLargeForWide;
- }
- while (numBytes-- > 0) {
- value = (value << CHAR_BIT) | *bytes++;
- }
- if (value > ((Tcl_WideUInt)WIDE_MAX + bignumValue->sign)) {
- goto tooLargeForWide;
- }
- if (bignumValue->sign) {
- TclSetIntObj(objPtr, -(Tcl_WideInt)value);
- } else {
- TclSetIntObj(objPtr, (Tcl_WideInt)value);
- }
- mp_clear(bignumValue);
- return;
+ if (mp_to_unsigned_bin_n(bignumValue, bytes, &numBytes) != MP_OKAY) {
+ goto tooLargeForWide;
+ }
+ while (numBytes-- > 0) {
+ value = (value << CHAR_BIT) | *bytes++;
+ }
+ if (value > ((Tcl_WideUInt)WIDE_MAX + bignumValue->sign)) {
+ goto tooLargeForWide;
+ }
+ if (bignumValue->sign) {
+ TclSetIntObj(objPtr, -(Tcl_WideInt)value);
+ } else {
+ TclSetIntObj(objPtr, (Tcl_WideInt)value);
}
+ mp_clear(bignumValue);
+ return;
tooLargeForWide:
TclInvalidateStringRep(objPtr);
TclFreeIntRep(objPtr);