Subject: [e663138a06] Fix the new INST_NUM_TYPE instruction so that the boundary cases of [string is] on integral values are computed right. Code is now correct, though still suffers from a large amount of ugly.

From: dgp <[email-masked]>
Date: Mon, 14 Apr 2014 18:45:04 +0000

---
 generic/tclExecute.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 6394a60..2c136d7 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -5989,16 +5989,32 @@ TEBCresume(
     case INST_NUM_TYPE:
 	if (GetNumberFromObj(NULL, OBJ_AT_TOS, &ptr1, &type1) != TCL_OK) {
 	    type1 = 0;
-	}
+	} else if (type1 == TCL_NUMBER_LONG) {
+	    /* value is between LONG_MIN and LONG_MAX */
+	    /* [string is integer] is -UINT_MAX to UINT_MAX range */
+	    int i;
+
+	    if (Tcl_GetIntFromObj(NULL, OBJ_AT_TOS, &i) != TCL_OK) {
+		type1 = TCL_NUMBER_WIDE;
+	    }
 #ifndef TCL_WIDE_INT_IS_LONG
-	else if (type1 == TCL_NUMBER_WIDE) {
-		/** See bug [e663138a06] */
-	    Tcl_WideInt value = (OBJ_AT_TOS)->internalRep.wideValue;
-	    if ((-value <= ULONG_MAX) && (value <= ULONG_MAX)) {
+	} else if (type1 == TCL_NUMBER_WIDE) {
+	    /* value is between WIDE_MIN and WIDE_MAX */
+	    /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */
+	    int i;
+	    if (Tcl_GetIntFromObj(NULL, OBJ_AT_TOS, &i) == TCL_OK) {
 		type1 = TCL_NUMBER_LONG;
 	    }
-	}
 #endif
+	} else if (type1 == TCL_NUMBER_BIG) {
+	    /* value is an integer outside the WIDE_MIN to WIDE_MAX range */
+	    /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */
+	    Tcl_WideInt w;
+
+	    if (Tcl_GetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) {
+		type1 = TCL_NUMBER_WIDE;
+	    }
+	}
 	TclNewIntObj(objResultPtr, type1);
 	TRACE(("\"%.20s\" => %d\n", O2S(OBJ_AT_TOS), type1));
 	NEXT_INST_F(1, 1, 1);
-- 
cgit v0.12