Subject: Implement %ll (WideInt) handling for Tcl_ObjPrintf(). Use it in some places.

From: "jan.nijtmans" <[email-masked]>
Date: Fri, 2 Dec 2016 13:50:29 +0000

Moved to feature branch temporarily.  Breaks build.
---
 generic/tcl.h          |  2 +-
 generic/tclStringObj.c | 20 ++++++++++++--------
 generic/tclStringRep.h |  8 ++++----
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/generic/tcl.h b/generic/tcl.h
index a8c68a6..0ddf52a 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -417,7 +417,7 @@ typedef long LONG;
 #endif /* !TCL_WIDE_INT_TYPE & !TCL_WIDE_INT_IS_LONG */
 #ifdef TCL_WIDE_INT_IS_LONG
 #   undef TCL_WIDE_INT_TYPE
-#   define TCL_WIDE_INT_TYPE	long
+#   define cd	long long
 #endif /* TCL_WIDE_INT_IS_LONG */
 
 typedef TCL_WIDE_INT_TYPE		Tcl_WideInt;
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 7008db0..4b171f3 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -2472,6 +2472,10 @@ AppendPrintfToObjVA(
 		    Tcl_ListObjAppendElement(NULL, list, Tcl_NewLongObj(
 			    va_arg(argList, long)));
 		    break;
+		case 2:
+		    Tcl_ListObjAppendElement(NULL, list, Tcl_NewWideIntObj(
+			    va_arg(argList, Tcl_WideInt)));
+		    break;
 		}
 		break;
 	    case 'e':
@@ -2500,9 +2504,9 @@ AppendPrintfToObjVA(
 		gotPrecision = 1;
 		p++;
 		break;
-	    /* TODO: support for wide (and bignum?) arguments */
+	    /* TODO: support for bignum arguments */
 	    case 'l':
-		size = 1;
+		++size;
 		p++;
 		break;
 	    case 'h':
@@ -2708,8 +2712,8 @@ TclStringRepeat(
         if (0 == Tcl_AttemptSetObjLength(objResultPtr, count*length)) {
 	    if (interp) {
 		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
-			"string size overflow: unable to alloc %lu bytes",
-			STRING_SIZE(count*length)));
+			"string size overflow: unable to alloc %llu bytes",
+			(Tcl_WideUInt)STRING_SIZE(count*length)));
 		Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
 	    }
 	    return TCL_ERROR;
@@ -2931,8 +2935,8 @@ TclStringCatObjv(
 	    if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
 		if (interp) {
 		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
-		    	"concatenation failed: unable to alloc %lu bytes",
-			STRING_SIZE(length)));
+		    	"concatenation failed: unable to alloc %llu bytes",
+			(Tcl_WideUInt)STRING_SIZE(length)));
 		    Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
 		}
 		return TCL_ERROR;
@@ -2946,8 +2950,8 @@ TclStringCatObjv(
 	    if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
 		if (interp) {
 		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
-		    	"concatenation failed: unable to alloc %lu bytes",
-			STRING_SIZE(length)));
+		    	"concatenation failed: unable to alloc %llu bytes",
+			(Tcl_WideUInt)STRING_SIZE(length)));
 		    Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
 		}
 		return TCL_ERROR;
diff --git a/generic/tclStringRep.h b/generic/tclStringRep.h
index db6f7e4..5148f97 100644
--- a/generic/tclStringRep.h
+++ b/generic/tclStringRep.h
@@ -76,13 +76,13 @@ typedef struct {
 	}								\
     } while (0)
 #define stringAttemptAlloc(numChars) \
-    (String *) attemptckalloc((unsigned) STRING_SIZE(numChars))
+    (String *) attemptckalloc(STRING_SIZE(numChars))
 #define stringAlloc(numChars) \
-    (String *) ckalloc((unsigned) STRING_SIZE(numChars))
+    (String *) ckalloc(STRING_SIZE(numChars))
 #define stringRealloc(ptr, numChars) \
-    (String *) ckrealloc((ptr), (unsigned) STRING_SIZE(numChars))
+    (String *) ckrealloc((ptr), STRING_SIZE(numChars))
 #define stringAttemptRealloc(ptr, numChars) \
-    (String *) attemptckrealloc((ptr), (unsigned) STRING_SIZE(numChars))
+    (String *) attemptckrealloc((ptr), STRING_SIZE(numChars))
 #define GET_STRING(objPtr) \
     ((String *) (objPtr)->internalRep.twoPtrValue.ptr1)
 #define SET_STRING(objPtr, stringPtr) \
-- 
cgit v0.12