From e18d096bd7da649d46f77e1fde7631375590daa7 Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Sun, 21 May 2023 21:19:22 +0000
Subject: Unbreak windows symbols build. More int -> Tcl_Size backported from
 9.0

---
 generic/tclExecute.c | 126 ++++++++++++++++++++++++++-------------------------
 1 file changed, 64 insertions(+), 62 deletions(-)

diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 31926a9..3f7e209 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -438,7 +438,7 @@ VarHashCreateVar(
 #ifdef TCL_COMPILE_DEBUG
 #   define TRACE(a) \
     while (traceInstructions) {					\
-	fprintf(stdout, "%2d: %2" TCL_T_MODIFIER "d (%" TCL_T_MODIFIER "d) %s ", iPtr->numLevels,	\
+	fprintf(stdout, "%2" TCL_SIZE_MODIFIER "d: %2" TCL_T_MODIFIER "d (%" TCL_T_MODIFIER "d) %s ", iPtr->numLevels,	\
 		CURR_DEPTH,				\
 		(pc - codePtr->codeStart),		\
 		GetOpcodeName(pc));				\
@@ -454,7 +454,7 @@ VarHashCreateVar(
     TRACE_APPEND(("ERROR: %.30s\n", O2S(Tcl_GetObjResult(interp))));
 #   define TRACE_WITH_OBJ(a, objPtr) \
     while (traceInstructions) {					\
-	fprintf(stdout, "%2d: %2" TCL_T_MODIFIER "d (%" TCL_T_MODIFIER "d) %s ", iPtr->numLevels,	\
+	fprintf(stdout, "%2" TCL_SIZE_MODIFIER "d: %2" TCL_T_MODIFIER "d (%" TCL_T_MODIFIER "d) %s ", iPtr->numLevels,	\
 		CURR_DEPTH,				\
 		(pc - codePtr->codeStart),		\
 		GetOpcodeName(pc));				\
@@ -850,7 +850,7 @@ ExecEnv *
 TclCreateExecEnv(
     Tcl_Interp *interp,		/* Interpreter for which the execution
 				 * environment is being created. */
-    int size)			/* The initial stack size, in number of words
+    Tcl_Size size)			/* The initial stack size, in number of words
 				 * [sizeof(Tcl_Obj*)] */
 {
     ExecEnv *eePtr = (ExecEnv *)ckalloc(sizeof(ExecEnv));
@@ -1037,10 +1037,10 @@ GrowEvaluationStack(
     int move)			/* 1 if move words since last marker. */
 {
     ExecStack *esPtr = eePtr->execStackPtr, *oldPtr = NULL;
-    int newBytes, newElems, currElems;
-    int needed = growth - (esPtr->endPtr - esPtr->tosPtr);
+    TCL_HASH_TYPE newBytes;
+    Tcl_Size newElems, currElems, needed = growth - (esPtr->endPtr - esPtr->tosPtr);
     Tcl_Obj **markerPtr = esPtr->markerPtr, **memStart;
-    int moveWords = 0;
+    Tcl_Size moveWords = 0;
 
     if (move) {
 	if (!markerPtr) {
@@ -1286,10 +1286,10 @@ TclStackAlloc(
     TCL_HASH_TYPE numWords;
 
     if (iPtr == NULL || iPtr->execEnvPtr == NULL) {
-	return (void *) ckalloc(numBytes);
+	return ckalloc(numBytes);
     }
     numWords = (numBytes + (sizeof(Tcl_Obj *) - 1))/sizeof(Tcl_Obj *);
-    return (void *) StackAllocWords(interp, numWords);
+    return StackAllocWords(interp, numWords);
 }
 
 void *
@@ -1302,10 +1302,10 @@ TclStackRealloc(
     ExecEnv *eePtr;
     ExecStack *esPtr;
     Tcl_Obj **markerPtr;
-    int numWords;
+    TCL_HASH_TYPE numWords;
 
     if (iPtr == NULL || iPtr->execEnvPtr == NULL) {
-	return (void *) ckrealloc((char *) ptr, numBytes);
+	return ckrealloc((char *)ptr, numBytes);
     }
 
     eePtr = iPtr->execEnvPtr;
@@ -1493,7 +1493,7 @@ CompileExprObj(
 	 * TIP #280: No invoker (yet) - Expression compilation.
 	 */
 
-	int length;
+	Tcl_Size length;
 	const char *string = TclGetStringFromObj(objPtr, &length);
 
 	TclInitCompileEnv(interp, &compEnv, string, length, NULL, 0);
@@ -1945,7 +1945,7 @@ TclNRExecuteByteCode(
 {
     Interp *iPtr = (Interp *) interp;
     TEBCdata *TD;
-    int size = sizeof(TEBCdata) - 1
+    TCL_HASH_TYPE size = sizeof(TEBCdata) - 1
 	    + (codePtr->maxStackDepth + codePtr->maxExceptDepth)
 		* sizeof(void *);
     TCL_HASH_TYPE numWords = (size + sizeof(Tcl_Obj *) - 1) / sizeof(Tcl_Obj *);
@@ -2105,7 +2105,7 @@ TEBCresume(
 
     Tcl_Obj *objPtr, *valuePtr, *value2Ptr, *part1Ptr, *part2Ptr, *tmpPtr;
     Tcl_Obj **objv = NULL;
-    int length, objc = 0;
+    Tcl_Size length, objc = 0;
     int opnd, pcAdjustment;
     Var *varPtr, *arrayPtr;
 #ifdef TCL_COMPILE_DEBUG
@@ -2181,7 +2181,7 @@ TEBCresume(
 	 * instruction.
 	 */
 
-	TRACE_WITH_OBJ(("%u => ... after \"%.20s\": TCL_OK, result=",
+	TRACE_WITH_OBJ(("%" TCL_SIZE_MODIFIER "d => ... after \"%.20s\": TCL_OK, result=",
 		objc, cmdNameBuf), Tcl_GetObjResult(interp));
 
 	/*
@@ -2326,7 +2326,7 @@ TEBCresume(
 
     CHECK_STACK();
     if (traceInstructions) {
-	fprintf(stdout, "%2d: %2" TCL_T_MODIFIER "d ", iPtr->numLevels, CURR_DEPTH);
+	fprintf(stdout, "%2" TCL_SIZE_MODIFIER "d: %2" TCL_T_MODIFIER "d ", iPtr->numLevels, CURR_DEPTH);
 	TclPrintInstruction(codePtr, pc);
 	fflush(stdout);
     }
@@ -2446,8 +2446,8 @@ TEBCresume(
 	    if (traceInstructions) {
 		TRACE_APPEND(("YIELD...\n"));
 	    } else {
-		fprintf(stdout, "%d: (%" TCL_Z_MODIFIER "u) yielding value \"%.30s\"\n",
-			iPtr->numLevels, (size_t)(pc - codePtr->codeStart),
+		fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) yielding value \"%.30s\"\n",
+			iPtr->numLevels, (pc - codePtr->codeStart),
 			Tcl_GetString(OBJ_AT_TOS));
 	    }
 	    fflush(stdout);
@@ -2489,8 +2489,8 @@ TEBCresume(
 		TRACE(("[%.30s] => YIELD...\n", O2S(valuePtr)));
 	    } else {
 		/* FIXME: What is the right thing to trace? */
-		fprintf(stdout, "%d: (%" TCL_Z_MODIFIER "u) yielding to [%.30s]\n",
-			iPtr->numLevels, (size_t)(pc - codePtr->codeStart),
+		fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) yielding to [%.30s]\n",
+			iPtr->numLevels, (pc - codePtr->codeStart),
 			TclGetString(valuePtr));
 	    }
 	    fflush(stdout);
@@ -2714,11 +2714,11 @@ TEBCresume(
 	/* Ugly abuse! */
 	starting = 1;
 #endif
-	TRACE(("=> drop %d items\n", objc));
+	TRACE(("=> drop %" TCL_SIZE_MODIFIER "d items\n", objc));
 	NEXT_INST_V(1, objc, 0);
 
     case INST_EXPAND_STKTOP: {
-	int i;
+	Tcl_Size i;
 	TEBCdata *newTD;
 	ptrdiff_t oldCatchTopOff, oldTosPtrOff;
 
@@ -2845,14 +2845,14 @@ TEBCresume(
 
 #ifdef TCL_COMPILE_DEBUG
 	if (tclTraceExec >= 2) {
-	    int i;
+	    Tcl_Size i;
 
 	    if (traceInstructions) {
 		strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
-		TRACE(("%u => call ", objc));
+		TRACE(("%" TCL_SIZE_MODIFIER "d => call ", objc));
 	    } else {
-		fprintf(stdout, "%d: (%" TCL_Z_MODIFIER "u) invoking ", iPtr->numLevels,
-			(size_t)(pc - codePtr->codeStart));
+		fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) invoking ", iPtr->numLevels,
+			(pc - codePtr->codeStart));
 	    }
 	    for (i = 0;  i < objc;  i++) {
 		TclPrintObject(stdout, objv[i], 15);
@@ -2977,15 +2977,15 @@ TEBCresume(
 	cleanup = objc;
 #ifdef TCL_COMPILE_DEBUG
 	if (tclTraceExec >= 2) {
-	    int i;
+	    Tcl_Size i;
 
 	    if (traceInstructions) {
 		strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
-		TRACE(("%u => call (implementation %s) ", objc, O2S(objPtr)));
+		TRACE(("%" TCL_SIZE_MODIFIER "d => call (implementation %s) ", objc, O2S(objPtr)));
 	    } else {
 		fprintf(stdout,
-			"%d: (%" TCL_Z_MODIFIER "u) invoking (using implementation %s) ",
-			iPtr->numLevels, (size_t)(pc - codePtr->codeStart),
+			"%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) invoking (using implementation %s) ",
+			iPtr->numLevels, (pc - codePtr->codeStart),
 			O2S(objPtr));
 	    }
 	    for (i = 0;  i < objc;  i++) {
@@ -3188,7 +3188,7 @@ TEBCresume(
 
     {
 	int storeFlags;
-	int len;
+	Tcl_Size len;
 
     case INST_STORE_ARRAY4:
 	opnd = TclGetUInt4AtPtr(pc+1);
@@ -4481,7 +4481,7 @@ TEBCresume(
 	NEXT_INST_F(1, 0, 1);
     break;
     case INST_INFO_LEVEL_ARGS: {
-	int level;
+	Tcl_Size level;
 	CallFrame *framePtr = iPtr->varFramePtr;
 	CallFrame *rootFramePtr = iPtr->rootFramePtr;
 
@@ -4561,7 +4561,7 @@ TEBCresume(
 	Object *oPtr;
 	CallFrame *framePtr;
 	CallContext *contextPtr;
-	int skip, newDepth;
+	Tcl_Size skip, newDepth;
 
     case INST_TCLOO_SELF:
 	framePtr = iPtr->varFramePtr;
@@ -4613,7 +4613,7 @@ TEBCresume(
 	} else {
 	    Class *classPtr = oPtr->classPtr;
 	    struct MInvoke *miPtr;
-	    int i;
+	    Tcl_Size i;
 	    const char *methodType;
 
 	    if (classPtr == NULL) {
@@ -4636,7 +4636,7 @@ TEBCresume(
 			if (traceInstructions) {
 			    strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
 			} else {
-			    fprintf(stdout, "%d: (%" TCL_Z_MODIFIER "u) invoking ",
+			    fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_T_MODIFIER "d) invoking ",
 				    iPtr->numLevels,
 				    (size_t)(pc - codePtr->codeStart));
 			}
@@ -4738,7 +4738,7 @@ TEBCresume(
 	    if (traceInstructions) {
 		strncpy(cmdNameBuf, TclGetString(objv[0]), 20);
 	    } else {
-		fprintf(stdout, "%d: (%" TCL_Z_MODIFIER "u) invoking ",
+		fprintf(stdout, "%" TCL_SIZE_MODIFIER "d: (%" TCL_Z_MODIFIER "u) invoking ",
 			iPtr->numLevels, (size_t)(pc - codePtr->codeStart));
 	    }
 	    for (i = 0;  i < opnd;  i++) {
@@ -4836,7 +4836,7 @@ TEBCresume(
 
     {
 	int numIndices, nocase, match, cflags;
-	int length2, fromIdx, toIdx, index, s1len, s2len;
+	Tcl_Size length2, fromIdx, toIdx, index, s1len, s2len;
 	const char *s1, *s2;
 
     case INST_LIST:
@@ -4857,7 +4857,7 @@ TEBCresume(
 	    goto gotError;
 	}
 	TclNewIntObj(objResultPtr, length);
-	TRACE_APPEND(("%d\n", length));
+	TRACE_APPEND(("%" TCL_SIZE_MODIFIER "d\n", length));
 	NEXT_INST_F(1, 1, 1);
 
     case INST_LIST_INDEX:	/* lindex with objc == 3 */
@@ -4904,7 +4904,9 @@ TEBCresume(
 	    Tcl_ResetResult(interp);
 	}
 
+	DECACHE_STACK_INFO();
 	objResultPtr = TclLindexList(interp, valuePtr, value2Ptr);
+	CACHE_STACK_INFO();
 
     lindexDone:
 	if (!objResultPtr) {
@@ -5140,7 +5142,7 @@ TEBCresume(
 	    toIdx = objc - 1;
 	}
 
-	assert ( toIdx >= 0 && toIdx < objc);
+	assert (toIdx >= 0 && toIdx < objc);
 	/*
 	assert ( fromIdx != TCL_INDEX_NONE );
 	 *
@@ -5178,7 +5180,7 @@ TEBCresume(
 	}
 	match = 0;
 	if (length > 0) {
-	    int i = 0;
+	    Tcl_Size i = 0;
 	    Tcl_Obj *o;
 	    int isArithSeries = TclHasInternalRep(value2Ptr,&tclArithSeriesType);
 	    /*
@@ -5246,7 +5248,8 @@ TEBCresume(
 
     case INST_LREPLACE4:
 	{
-	int numToDelete, numNewElems, end_indicator;
+	TCL_HASH_TYPE numToDelete, numNewElems;
+	int end_indicator;
 	int haveSecondIndex, flags;
 	Tcl_Obj *fromIdxObj, *toIdxObj;
 	opnd = TclGetInt4AtPtr(pc + 1);
@@ -5401,7 +5404,7 @@ TEBCresume(
 	valuePtr = OBJ_AT_TOS;
 	length = TclGetCharLength(valuePtr);
 	TclNewIntObj(objResultPtr, length);
-	TRACE(("\"%.20s\" => %d\n", O2S(valuePtr), length));
+	TRACE(("\"%.20s\" => %" TCL_SIZE_MODIFIER "d\n", O2S(valuePtr), length));
 	NEXT_INST_F(1, 1, 1);
 
     case INST_STR_UPPER:
@@ -5478,7 +5481,7 @@ TEBCresume(
 	    TclNewObj(objResultPtr);
 	} else if (TclIsPureByteArray(valuePtr)) {
 	    objResultPtr = Tcl_NewByteArrayObj(
-		    TclGetByteArrayFromObj(valuePtr, NULL)+index, 1);
+		    TclGetByteArrayFromObj(valuePtr, (Tcl_Size *)NULL)+index, 1);
 	} else if (valuePtr->bytes && length == valuePtr->length) {
 	    objResultPtr = Tcl_NewStringObj((const char *)
 		    valuePtr->bytes+index, 1);
@@ -5618,7 +5621,7 @@ TEBCresume(
 	    toIdx = endIdx;
 	}
 
-	if (fromIdx == 0 && toIdx == endIdx) {
+	if ((fromIdx == 0) && (toIdx == endIdx)) {
 	    TclDecrRefCount(OBJ_AT_TOS);
 	    OBJ_AT_TOS = value3Ptr;
 	    TRACE_APPEND(("\"%.30s\"\n", O2S(value3Ptr)));
@@ -5781,7 +5784,7 @@ TEBCresume(
 
     {
 	const char *string1, *string2;
-	int trim1, trim2;
+	Tcl_Size trim1, trim2;
 
     case INST_STR_TRIM_LEFT:
 	valuePtr = OBJ_UNDER_TOS;	/* String */
@@ -6755,8 +6758,7 @@ TEBCresume(
 	ForeachInfo *infoPtr;
 	Tcl_Obj *listPtr, **elements;
 	ForeachVarList *varListPtr;
-	int numLists, listLen, numVars;
-	int listTmpDepth;
+	Tcl_Size numLists, listLen, numVars, listTmpDepth;
 	size_t iterNum, iterMax, iterTmp;
 	int varIndex, valIndex, j;
 	long i;
@@ -6892,7 +6894,7 @@ TEBCresume(
 			if (TclPtrSetVarIdx(interp, varPtr, NULL, NULL, NULL,
 				valuePtr, TCL_LEAVE_ERR_MSG, varIndex)==NULL){
 			    CACHE_STACK_INFO();
-			    TRACE_APPEND(("ERROR init. index temp %d: %.30s",
+			    TRACE_APPEND(("ERROR init. index temp %" TCL_SIZE_MODIFIER "d: %.30s",
 				    varIndex, O2S(Tcl_GetObjResult(interp))));
 			    goto gotError;
 			}
@@ -6939,7 +6941,7 @@ TEBCresume(
 	tmpPtr = OBJ_AT_DEPTH(1);
 	infoPtr = (ForeachInfo *)tmpPtr->internalRep.twoPtrValue.ptr1;
 	numLists = infoPtr->numLists;
-	TRACE_APPEND(("=> appending to list at depth %d\n", 3 + numLists));
+	TRACE_APPEND(("=> appending to list at depth %" TCL_SIZE_MODIFIER "d\n", 3 + numLists));
 
 	objPtr = OBJ_AT_DEPTH(3 + numLists);
 	Tcl_ListObjAppendElement(NULL, objPtr, OBJ_AT_TOS);
@@ -7022,7 +7024,7 @@ TEBCresume(
 
     {
 	int opnd2, allocateDict, done, allocdict;
-	int i;
+	Tcl_Size i;
 	Tcl_Obj *dictPtr, *statePtr, *keyPtr, *listPtr, *varNamePtr, *keysPtr;
 	Tcl_Obj *emptyPtr, **keyPtrPtr;
 	Tcl_DictSearch *searchPtr;
@@ -7765,7 +7767,7 @@ TEBCresume(
 	    if (result == TCL_BREAK) {
 		result = TCL_OK;
 		pc = (codePtr->codeStart + rangePtr->breakOffset);
-		TRACE_APPEND(("%s, range at %d, new pc %d\n",
+		TRACE_APPEND(("%s, range at %" TCL_SIZE_MODIFIER "d, new pc %" TCL_SIZE_MODIFIER "d\n",
 			StringForResultCode(result),
 			rangePtr->codeOffset, rangePtr->breakOffset));
 		NEXT_INST_F(0, 0, 0);
@@ -7777,7 +7779,7 @@ TEBCresume(
 	    }
 	    result = TCL_OK;
 	    pc = (codePtr->codeStart + rangePtr->continueOffset);
-	    TRACE_APPEND(("%s, range at %d, new pc %d\n",
+	    TRACE_APPEND(("%s, range at %" TCL_SIZE_MODIFIER "d, new pc %" TCL_SIZE_MODIFIER "d\n",
 		    StringForResultCode(result),
 		    rangePtr->codeOffset, rangePtr->continueOffset));
 	    NEXT_INST_F(0, 0, 0);
@@ -7948,8 +7950,8 @@ TEBCresume(
 	}
 #ifdef TCL_COMPILE_DEBUG
 	if (traceInstructions) {
-	    fprintf(stdout, "  ... found catch at %d, catchTop=%" TCL_T_MODIFIER "d, "
-		    "unwound to %" TCL_T_MODIFIER "d, new pc %" TCL_T_MODIFIER "d\n",
+	    fprintf(stdout, "  ... found catch at %" TCL_SIZE_MODIFIER "d, catchTop=%" TCL_T_MODIFIER "d, "
+		    "unwound to %" TCL_T_MODIFIER "d, new pc %" TCL_SIZE_MODIFIER "d\n",
 		    rangePtr->codeOffset, (catchTop - initCatchTop - 1),
 		    PTR2INT(*catchTop), rangePtr->catchOffset);
 	}
@@ -9454,7 +9456,7 @@ TclGetSrcInfoForPc(
 
 	ExtCmdLoc *eclPtr;
 	ECL *locPtr = NULL;
-	int srcOffset;
+	Tcl_Size srcOffset;
 	int i;
 	Interp *iPtr = (Interp *) *codePtr->interpHandle;
 	Tcl_HashEntry *hePtr =
@@ -9501,7 +9503,7 @@ GetSrcInfoForPc(
 				 * in codePtr's code. */
     ByteCode *codePtr,		/* The bytecode sequence in which to look up
 				 * the command source for the pc. */
-    int *lengthPtr,		/* If non-NULL, the location where the length
+    Tcl_Size *lengthPtr,	/* If non-NULL, the location where the length
 				 * of the command's source should be stored.
 				 * If NULL, no length is stored. */
     const unsigned char **pcBeg,/* If non-NULL, the bytecode location
@@ -9511,11 +9513,11 @@ GetSrcInfoForPc(
 				 * of the command containing the pc should
 				 * be stored. */
 {
-    int pcOffset = (pc - codePtr->codeStart);
-    int numCmds = codePtr->numCommands;
+    Tcl_Size pcOffset = pc - codePtr->codeStart;
+    Tcl_Size numCmds = codePtr->numCommands;
     unsigned char *codeDeltaNext, *codeLengthNext;
     unsigned char *srcDeltaNext, *srcLengthNext;
-    int codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i;
+    Tcl_Size codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i;
     int bestDist = INT_MAX;	/* Distance of pc to best cmd's start pc. */
     int bestSrcOffset = -1;	/* Initialized to avoid compiler warning. */
     int bestSrcLength = -1;	/* Initialized to avoid compiler warning. */
@@ -10011,7 +10013,7 @@ EvalStatsCmd(
     Tcl_AppendPrintfToObj(objPtr, "Total literal objects\t\t%" TCL_Z_MODIFIER "u\n",
 	    statsPtr->numLiteralsCreated);
 
-    Tcl_AppendPrintfToObj(objPtr, "\nCurrent literal objects\t\t%d (%0.1f%% of current objects)\n",
+    Tcl_AppendPrintfToObj(objPtr, "\nCurrent literal objects\t\t%" TCL_SIZE_MODIFIER "d (%0.1f%% of current objects)\n",
 	    globalTablePtr->numEntries,
 	    Percent(globalTablePtr->numEntries, tclObjsAlloced-tclObjsFreed));
     Tcl_AppendPrintfToObj(objPtr, "  ByteCode literals\t\t%" TCL_Z_MODIFIER "u (%0.1f%% of current literals)\n",
@@ -10103,7 +10105,7 @@ EvalStatsCmd(
     for (i = 0;  i <= maxSizeDecade;  i++) {
 	decadeHigh = (1 << (i+1)) - 1;
 	sum += statsPtr->literalCount[i];
-	Tcl_AppendPrintfToObj(objPtr, "\t%10d\t\t%8.0f%%\n",
+	Tcl_AppendPrintfToObj(objPtr, "\t%10" TCL_SIZE_MODIFIER "d\t\t%8.0f%%\n",
 		decadeHigh, Percent(sum, statsPtr->numLiteralsCreated));
     }
 
@@ -10135,7 +10137,7 @@ EvalStatsCmd(
     for (i = minSizeDecade;  i <= maxSizeDecade;  i++) {
 	decadeHigh = (1 << (i+1)) - 1;
 	sum += statsPtr->srcCount[i];
-	Tcl_AppendPrintfToObj(objPtr, "\t%10d\t\t%8.0f%%\n",
+	Tcl_AppendPrintfToObj(objPtr, "\t%10" TCL_SIZE_MODIFIER "d\t\t%8.0f%%\n",
 		decadeHigh, Percent(sum, statsPtr->numCompilations));
     }
 
@@ -10158,7 +10160,7 @@ EvalStatsCmd(
     for (i = minSizeDecade;  i <= maxSizeDecade;  i++) {
 	decadeHigh = (1 << (i+1)) - 1;
 	sum += statsPtr->byteCodeCount[i];
-	Tcl_AppendPrintfToObj(objPtr, "\t%10d\t\t%8.0f%%\n",
+	Tcl_AppendPrintfToObj(objPtr, "\t%10" TCL_SIZE_MODIFIER "d\t\t%8.0f%%\n",
 		decadeHigh, Percent(sum, statsPtr->numCompilations));
     }
 
-- 
cgit v0.12


From f3f254e8bab8854467fda3c5a2c48a640fb7687c Mon Sep 17 00:00:00 2001
From: dkf <donal.k.fellows@manchester.ac.uk>
Date: Mon, 22 May 2023 07:48:43 +0000
Subject: Small documentation corrections

---
 doc/chan.n         |  19 ++++++++--
 doc/close.n        |  21 +++++++----
 doc/configurable.n |   2 +-
 doc/link.n         |  14 ++++----
 doc/lremove.n      |   2 +-
 doc/lseq.n         | 103 ++++++++++++++++++++++++++++-------------------------
 6 files changed, 95 insertions(+), 66 deletions(-)

diff --git a/doc/chan.n b/doc/chan.n
index 1ecef4c..70f451d 100644
--- a/doc/chan.n
+++ b/doc/chan.n
@@ -55,7 +55,9 @@ channel is flushed in the background before finally being closed.
 .PP
 \fBchan close\fR may return an error if an error occurs while flushing
 output.  If a process in a command pipeline created by \fBopen\fR returns an
-error, \fBchan close\fR generates an error in the same manner as \fBexec\fR.
+error (either by returning a non-zero exit code or writing to its standard
+error file descriptor), \fBchan close\fR generates an error in the same
+manner as \fBexec\fR.
 .PP
 Closing one side of a socket or command pipeline may lead to the shutdown() or
 close() of the underlying system resource, leading to a reaction from whatever
@@ -70,6 +72,17 @@ description of channel sharing.
 .PP
 When the last interpreter sharing a channel is destroyed, the channel is
 switched to blocking mode and fully flushed and then closed.
+.PP
+Channels are automatically closed when an interpreter is destroyed and
+when the process exits.
+From 8.6 on (TIP#398), nonblocking channels are no longer switched to
+blocking mode when exiting; this guarantees a timely exit even when the
+peer or a communication channel is stalled. To ensure proper flushing of
+stalled nonblocking channels on exit, one must now either (a) actively
+switch them back to blocking or (b) use the environment variable
+\fBTCL_FLUSH_NONBLOCKING_ON_EXIT\fR, which when set and not equal to
+.QW \fB0\fR
+restores the previous behavior.
 .RE
 .TP
 \fBchan configure \fIchannelName\fR ?\fIoptionName\fR? ?\fIvalue\fR? ?\fIoptionName value\fR?...
@@ -288,8 +301,8 @@ first words of a command that provides the interface for a \fBrefchan\fR.
 \fBImode\fR is a list of one or more of the strings
 .QW \fBread\fR
 or
-.QW \fBwrite\fR
-, indicating whether the channel is a read channel, a write channel, or both.
+.QW \fBwrite\fR ,
+indicating whether the channel is a read channel, a write channel, or both.
 It is an error if the handler does not support the chosen mode.
 .PP
 The handler is called as needed from the global namespace at the top level, and
diff --git a/doc/close.n b/doc/close.n
index 3d18aea..2066583 100644
--- a/doc/close.n
+++ b/doc/close.n
@@ -12,11 +12,12 @@
 .SH NAME
 close \- Close an open channel
 .SH SYNOPSIS
-\fBclose \fIchannelId\fR ?r(ead)|w(rite)?
+\fBclose \fIchannelId\fR ?\fBr\fR(\fBead\fR)|\fBw\fR(\fBrite\fR)?
 .BE
 .SH DESCRIPTION
 .PP
-Closes or half-closes the channel given by \fIchannelId\fR.
+Closes or half-closes the channel given by \fIchannelId\fR. \fBchan close\fR
+is another name for this command.
 .PP
 \fIChannelId\fR must be an identifier for an open channel such as a
 Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR),
@@ -49,12 +50,20 @@ When the last interpreter in which the channel is registered invokes
 .PP
 Channels are automatically closed when an interpreter is destroyed and
 when the process exits.
-From 8.6 on (TIP#398), nonblocking channels are no longer switched to blocking mode when exiting; this guarantees a timely exit even when the peer or a communication channel is stalled. To ensure proper flushing of stalled nonblocking channels on exit, one must now either (a) actively switch them back to blocking or (b) use the environment variable TCL_FLUSH_NONBLOCKING_ON_EXIT,  which when set and not equal to "0" restores the previous behavior.
+From 8.6 on (TIP#398), nonblocking channels are no longer switched to
+blocking mode when exiting; this guarantees a timely exit even when the
+peer or a communication channel is stalled. To ensure proper flushing of
+stalled nonblocking channels on exit, one must now either (a) actively
+switch them back to blocking or (b) use the environment variable
+\fBTCL_FLUSH_NONBLOCKING_ON_EXIT\fR, which when set and not equal to
+.QW \fB0\fR
+restores the previous behavior.
 .PP
 The command returns an empty string, and may generate an error if
 an error occurs while flushing output.  If a command in a command
-pipeline created with \fBopen\fR returns an error, \fBclose\fR
-generates an error (similar to the \fBexec\fR command.)
+pipeline created with \fBopen\fR returns an error (either by returning a
+non-zero exit code or writing to its standard error file descriptor),
+\fBclose\fR generates an error (similar to the \fBexec\fR command.)
 .PP
 The two-argument form is a
 .QW "half-close" :
@@ -95,7 +104,7 @@ proc withOpenFile {filename channelVar script} {
 }
 .CE
 .SH "SEE ALSO"
-file(n), open(n), socket(n), eof(n), Tcl_StandardChannels(3)
+chan(n), file(n), open(n), socket(n), eof(n), Tcl_StandardChannels(3)
 .SH KEYWORDS
 blocking, channel, close, nonblocking, half-close
 '\" Local Variables:
diff --git a/doc/configurable.n b/doc/configurable.n
index 6477894..a138c33 100644
--- a/doc/configurable.n
+++ b/doc/configurable.n
@@ -4,7 +4,7 @@
 '\" See the file "license.terms" for information on usage and redistribution
 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 '\"
-.TH configurable n 0.1 TclOO "TclOO Commands"
+.TH configurable n 0.4 TclOO "TclOO Commands"
 .so man.macros
 .BS
 '\" Note:  do not modify the .SH NAME line immediately below!
diff --git a/doc/link.n b/doc/link.n
index e06be33..a11c261 100644
--- a/doc/link.n
+++ b/doc/link.n
@@ -52,11 +52,11 @@ oo::class create ABC {
 
     constructor {} {
         \fBlink\fR Foo
-        # The method foo is now directly accessible as foo here
+        # The method Foo is now directly accessible as Foo here
         \fBlink\fR {bar Foo}
-        # The method foo is now directly accessible as bar
+        # The method Foo is now directly accessible as bar
         \fBlink\fR {::ExternalCall Foo}
-        # The method foo is now directly accessible in the global
+        # The method Foo is now directly accessible in the global
         # namespace as ExternalCall
     }
 
@@ -71,13 +71,13 @@ oo::class create ABC {
 ABC create abc
 abc grill
         \fI\(-> Step 1:\fR
-        \fI\(-> This is foo in ::abc\fR
+        \fI\(-> This is Foo in ::abc\fR
         \fI\(-> Step 2:\fR
-        \fI\(-> This is foo in ::abc\fR
+        \fI\(-> This is Foo in ::abc\fR
 # Direct access via the linked command
 puts "Step 3:"; ExternalCall
         \fI\(-> Step 3:\fR
-        \fI\(-> This is foo in ::abc\fR
+        \fI\(-> This is Foo in ::abc\fR
 .CE
 .PP
 This example shows that multiple linked commands can be made in a call to
@@ -88,7 +88,7 @@ oo::class create Ex {
     constructor {} {
         \fBlink\fR a b c
         # The methods a, b, and c (defined below) are all now
-        # directly acessible within methods under their own names.
+        # directly accessible within methods under their own names.
     }
 
     method a {} {
diff --git a/doc/lremove.n b/doc/lremove.n
index 8763ea6..bd4a5eb 100644
--- a/doc/lremove.n
+++ b/doc/lremove.n
@@ -16,7 +16,7 @@ lremove \- Remove elements from a list by index
 .SH DESCRIPTION
 .PP
 \fBlremove\fR returns a new list formed by simultaneously removing zero or
-more elements of \fIlist\fR at each of the indices given by an arbirary number
+more elements of \fIlist\fR at each of the indices given by an arbitrary number
 of \fIindex\fR arguments. The indices may be in any order and may be repeated;
 the element at index will only be removed once.  The index values are
 interpreted the same as index values for the command \fBstring index\fR,
diff --git a/doc/lseq.n b/doc/lseq.n
index df8a8bc..08be86f 100644
--- a/doc/lseq.n
+++ b/doc/lseq.n
@@ -11,73 +11,80 @@
 .SH NAME
 lseq \- Build a numeric sequence returned as a list
 .SH SYNOPSIS
-\fBlseq \fIStart \fR?(\fB..\fR|\fBto\fR)? \fIEnd\fR ??\fBby\fR? \fIStep\fR?
+\fBlseq \fIstart \fR?(\fB..\fR|\fBto\fR)? \fIend\fR ??\fBby\fR? \fIstep\fR?
 
-\fBlseq \fIStart \fBcount\fR \fICount\fR ??\fBby\fR? \fIStep\fR?
+\fBlseq \fIstart \fBcount\fR \fIcount\fR ??\fBby\fR? \fIstep\fR?
 
-\fBlseq \fICount\fR ?\fBby \fIStep\fR?
+\fBlseq \fIcount\fR ?\fBby \fIstep\fR?
 .BE
 .SH DESCRIPTION
 .PP
 The \fBlseq\fR command creates a sequence of numeric values using the given
-parameters \fIStart\fR, \fIEnd\fR, and \fIStep\fR. The \fIoperation\fR
-argument ".." or "to" defines an inclusive range. The "count" option is used
-to define a count of the number of elements in the list. The short form with a
-single count value will create a range from 0 to count-1.
-
-The numeric arguments, \fIStart\fR, \fIEnd\fR, \fIStep\fR, and \fICount\fR,
-can also be a valid expression. the lseq command will evaluate the expression
+parameters \fIstart\fR, \fIend\fR, and \fIstep\fR.
+The \fIoperation\fR argument
+.QW \fB..\fR
+or
+.QW \fBto\fR
+defines an inclusive range; if it is omitted, the range is exclusive.
+The \fBcount\fR option is used to define a count of the number of elements in
+the list.
+The \fIstep\fR (which may be preceded by \fBby\fR) is 1 if not provided.
+The short form with a
+single \fIcount\fR value will create a range from 0 to \fIcount\fR-1 (i.e.,
+\fIcount\fR values).
+.PP
+The numeric arguments, \fIstart\fR, \fIend\fR, \fIstep\fR, and \fIcount\fR,
+can also be a valid expression. the \fBlseq\fR command will evaluate the
+expression (as if with \fBexpr\fR)
 and use the numeric result, or return an error as with any invalid argument
-value. A valid expression is a valid [expr] expression, however, the result
-must be numeric; a non-numeric string will result in an error.
+value; a non-numeric expression result will result in an error.
 
 .SH EXAMPLES
 .CS
 .\"
+\fBlseq\fR 3
+         \fI\(-> 0 1 2\fR
 
- lseq 3
- \(-> 0 1 2
+\fBlseq\fR 3 0
+         \fI\(-> 3 2 1 0\fR
 
- lseq 3 0
- \(-> 3 2 1 0
+\fBlseq\fR 10 .. 1 by -2
+         \fI\(-> 10 8 6 4 2\fR
 
- lseq 10 .. 1 by -2
- \(-> 10 8 6 4 2
+set l [\fBlseq\fR 0 -5]
+         \fI\(-> 0 -1 -2 -3 -4 -5\fR
 
- set l [lseq 0 -5]
- \(-> 0 -1 -2 -3 -4 -5
-
- foreach i [lseq [llength $l]] {
-   puts l($i)=[lindex $l $i]
- }
- \(-> l(0)=0
-    l(1)=-1
-    l(2)=-2
-    l(3)=-3
-    l(4)=-4
-    l(5)=-5
+foreach i [\fBlseq\fR [llength $l]] {
+    puts l($i)=[lindex $l $i]
+}
+        \fI\(-> l(0)=0\fR
+        \fI\(-> l(1)=-1\fR
+        \fI\(-> l(2)=-2\fR
+        \fI\(-> l(3)=-3\fR
+        \fI\(-> l(4)=-4\fR
+        \fI\(-> l(5)=-5\fR
 
- foreach i [lseq [llength $l]-1 0] {
+foreach i [\fBlseq\fR {[llength $l]-1} 0] {
     puts l($i)=[lindex $l $i]
- }
- \(-> l(5)=-5
-    l(4)=-4
-    l(3)=-3
-    l(2)=-2
-    l(1)=-1
-    l(0)=0
+}
+        \fI\(-> l(5)=-5\fR
+        \fI\(-> l(4)=-4\fR
+        \fI\(-> l(3)=-3\fR
+        \fI\(-> l(2)=-2\fR
+        \fI\(-> l(1)=-1\fR
+        \fI\(-> l(0)=0\fR
 
- set i 17
- \(-> 17
- if {$i in [lseq 0 50]} { # equivalent to: (0 <= $i && $i < 50)
-     puts "Ok"
- } else {
-     puts "outside :("
- }
- \(-> Ok
+set i 17
+         \fI\(-> 17\fR
+if {$i in [\fBlseq\fR 0 50]} { # equivalent to: (0 <= $i && $i < 50)
+    puts "Ok"
+} else {
+    puts "outside :("
+}
+        \fI\(-> Ok\fR
 
- set sqrs [lmap i [lseq 1 10] {expr $i*$i}]
- \(-> 1 4 9 16 25 36 49 64 81 100
+set sqrs [lmap i [\fBlseq\fR 1 10] { expr {$i*$i} }]
+        \fI\(-> 1 4 9 16 25 36 49 64 81 100\fR
 .\"
 .CE
 .SH "SEE ALSO"
-- 
cgit v0.12


From 2acd355f8dc8e75b3a63b7b1dc079ebccb3a2701 Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Tue, 23 May 2023 16:03:29 +0000
Subject: Give Tcl_CreateThread a TCL_HASH_TYPE (unsigned) stackSize parameter

---
 doc/Thread.3       | 2 +-
 generic/tcl.decls  | 2 +-
 generic/tclDecls.h | 4 ++--
 generic/tclEvent.c | 2 +-
 generic/tclInt.h   | 2 +-
 unix/tclUnixThrd.c | 6 +++---
 win/tclWinThrd.c   | 8 ++++----
 7 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/doc/Thread.3 b/doc/Thread.3
index 2005c93..ac60230 100644
--- a/doc/Thread.3
+++ b/doc/Thread.3
@@ -69,7 +69,7 @@ This procedure will act as the \fBmain()\fR of the newly created
 thread. The specified \fIclientData\fR will be its sole argument.
 .AP ClientData clientData in
 Arbitrary information. Passed as sole argument to the \fIproc\fR.
-.AP int stackSize in
+.AP unsigned stackSize in
 The size of the stack given to the new thread.
 .AP int flags in
 Bitmask containing flags allowing the caller to modify behavior of
diff --git a/generic/tcl.decls b/generic/tcl.decls
index 2e5d7b4..77aeb84 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -1391,7 +1391,7 @@ declare 392 {
 }
 declare 393 {
     int Tcl_CreateThread(Tcl_ThreadId *idPtr, Tcl_ThreadCreateProc *proc,
-	    void *clientData, Tcl_Size stackSize, int flags)
+	    void *clientData, TCL_HASH_TYPE stackSize, int flags)
 }
 
 # Introduced in 8.3.2
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index f9b36ba..c19b2c0 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -1198,7 +1198,7 @@ EXTERN void		Tcl_MutexFinalize(Tcl_Mutex *mutex);
 /* 393 */
 EXTERN int		Tcl_CreateThread(Tcl_ThreadId *idPtr,
 				Tcl_ThreadCreateProc *proc, void *clientData,
-				Tcl_Size stackSize, int flags);
+				TCL_HASH_TYPE stackSize, int flags);
 /* 394 */
 EXTERN Tcl_Size		Tcl_ReadRaw(Tcl_Channel chan, char *dst,
 				Tcl_Size bytesToRead);
@@ -2479,7 +2479,7 @@ typedef struct TclStubs {
     int (*tcl_ProcObjCmd) (void *clientData, Tcl_Interp *interp, Tcl_Size objc, Tcl_Obj *const objv[]); /* 390 */
     void (*tcl_ConditionFinalize) (Tcl_Condition *condPtr); /* 391 */
     void (*tcl_MutexFinalize) (Tcl_Mutex *mutex); /* 392 */
-    int (*tcl_CreateThread) (Tcl_ThreadId *idPtr, Tcl_ThreadCreateProc *proc, void *clientData, Tcl_Size stackSize, int flags); /* 393 */
+    int (*tcl_CreateThread) (Tcl_ThreadId *idPtr, Tcl_ThreadCreateProc *proc, void *clientData, TCL_HASH_TYPE stackSize, int flags); /* 393 */
     Tcl_Size (*tcl_ReadRaw) (Tcl_Channel chan, char *dst, Tcl_Size bytesToRead); /* 394 */
     Tcl_Size (*tcl_WriteRaw) (Tcl_Channel chan, const char *src, Tcl_Size srcLen); /* 395 */
     Tcl_Channel (*tcl_GetTopChannel) (Tcl_Channel chan); /* 396 */
diff --git a/generic/tclEvent.c b/generic/tclEvent.c
index 41c8700..5501721 100644
--- a/generic/tclEvent.c
+++ b/generic/tclEvent.c
@@ -2060,7 +2060,7 @@ Tcl_CreateThread(
     Tcl_ThreadId *idPtr,	/* Return, the ID of the thread */
     Tcl_ThreadCreateProc *proc,	/* Main() function of the thread */
     void *clientData,		/* The one argument to Main() */
-    Tcl_Size stackSize,		/* Size of stack for the new thread */
+    TCL_HASH_TYPE stackSize,	/* Size of stack for the new thread */
     int flags)			/* Flags controlling behaviour of the new
 				 * thread. */
 {
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 87b16a8..e40c5bc 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3329,7 +3329,7 @@ MODULE_SCOPE int	TclCreateSocketAddress(Tcl_Interp *interp,
 			    const char **errorMsgPtr);
 MODULE_SCOPE int	TclpThreadCreate(Tcl_ThreadId *idPtr,
 			    Tcl_ThreadCreateProc *proc, void *clientData,
-			    int stackSize, int flags);
+			    TCL_HASH_TYPE stackSize, int flags);
 MODULE_SCOPE Tcl_Size	TclpFindVariable(const char *name, Tcl_Size *lengthPtr);
 MODULE_SCOPE void	TclpInitLibraryPath(char **valuePtr,
 			    TCL_HASH_TYPE *lengthPtr, Tcl_Encoding *encodingPtr);
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c
index 0c32b0d..c67495e 100644
--- a/unix/tclUnixThrd.c
+++ b/unix/tclUnixThrd.c
@@ -222,7 +222,7 @@ TclpThreadCreate(
     Tcl_ThreadId *idPtr,	/* Return, the ID of the thread */
     Tcl_ThreadCreateProc *proc,	/* Main() function of the thread */
     ClientData clientData,	/* The one argument to Main() */
-    int stackSize,		/* Size of stack for the new thread */
+    TCL_HASH_TYPE stackSize,	/* Size of stack for the new thread */
     int flags)			/* Flags controlling behaviour of the new
 				 * thread. */
 {
@@ -236,7 +236,7 @@ TclpThreadCreate(
 
 #ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
     if (stackSize != TCL_THREAD_STACK_DEFAULT) {
-	pthread_attr_setstacksize(&attr, stackSize);
+	pthread_attr_setstacksize(&attr, (size_t)stackSize);
 #ifdef TCL_THREAD_STACK_MIN
     } else {
 	/*
@@ -255,7 +255,7 @@ TclpThreadCreate(
 
 	result = pthread_attr_getstacksize(&attr, &size);
 	if (!result && (size < TCL_THREAD_STACK_MIN)) {
-	    pthread_attr_setstacksize(&attr, (size_t) TCL_THREAD_STACK_MIN);
+	    pthread_attr_setstacksize(&attr, (size_t)TCL_THREAD_STACK_MIN);
 	}
 #endif /* TCL_THREAD_STACK_MIN */
     }
diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index e9d4e08..da9133f 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -204,7 +204,7 @@ TclpThreadCreate(
     Tcl_ThreadId *idPtr,	/* Return, the ID of the thread. */
     Tcl_ThreadCreateProc *proc,	/* Main() function of the thread. */
     ClientData clientData,	/* The one argument to Main(). */
-    int stackSize,		/* Size of stack for the new thread. */
+	TCL_HASH_TYPE stackSize,	/* Size of stack for the new thread. */
     int flags)			/* Flags controlling behaviour of the new
 				 * thread. */
 {
@@ -223,11 +223,11 @@ TclpThreadCreate(
 		 */
 
 #if defined(_MSC_VER) || defined(__MSVCRT__)
-    tHandle = (HANDLE) _beginthreadex(NULL, (unsigned) stackSize,
+    tHandle = (HANDLE) _beginthreadex(NULL, (unsigned)stackSize,
 	    (Tcl_ThreadCreateProc*) TclWinThreadStart, winThreadPtr,
 	    0, (unsigned *)idPtr);
 #else
-    tHandle = CreateThread(NULL, (DWORD) stackSize,
+    tHandle = CreateThread(NULL, (DWORD)stackSize,
 	    TclWinThreadStart, winThreadPtr, 0, (LPDWORD)idPtr);
 #endif
 
@@ -725,7 +725,7 @@ Tcl_ConditionWait(
     if (timePtr == NULL) {
 	wtime = INFINITE;
     } else {
-	wtime = timePtr->sec * 1000 + timePtr->usec / 1000;
+	wtime = (DWORD)timePtr->sec * 1000 + (DWORD)timePtr->usec / 1000;
     }
 
     /*
-- 
cgit v0.12


From 9a6a7030e80397a55a4ee8d090ec9f85b585f13d Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Wed, 24 May 2023 10:31:56 +0000
Subject: Remove TCL_SIZE_SMAX, not used anywhere. Some more variable which
 should have been Tcl_Size

---
 generic/tclInt.h  | 6 ------
 generic/tclUtil.c | 4 ++--
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/generic/tclInt.h b/generic/tclInt.h
index a7d0395..497c3a5 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -105,12 +105,6 @@
 #endif
 
 /*
- * Maximum *signed* value that can be stored in a Tcl_Size type. This is
- * primarily used for checking overflows in dynamically allocating memory.
- */
-#define TCL_SIZE_SMAX ((((Tcl_Size) 1) << ((8*(Tcl_Size)sizeof(Tcl_Size)) - 1)) - 1)
-
-/*
  * Macros used to cast between pointers and integers (e.g. when storing an int
  * in ClientData), on 64-bit architectures they avoid gcc warning about "cast
  * to/from pointer from/to integer of different size".
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 67c7bc1..cf6dc75 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -1035,10 +1035,10 @@ TclScanElement(
 				 * needs protection or escape. */
     int requireEscape = 0;	/* Force use of CONVERT_ESCAPE mode.  For some
 				 * reason bare or brace-quoted form fails. */
-    int extra = 0;		/* Count of number of extra bytes needed for
+    Tcl_Size extra = 0;		/* Count of number of extra bytes needed for
 				 * formatted element, assuming we use escape
 				 * sequences in formatting. */
-    TCL_HASH_TYPE bytesNeeded;		/* Buffer length computed to complete the
+    Tcl_Size bytesNeeded;		/* Buffer length computed to complete the
 				 * element formatting in the selected mode. */
 #if COMPAT
     int preferEscape = 0;	/* Use preferences to track whether to use */
-- 
cgit v0.12


From 6c1bdd15d6fabcc595c0fefdb9994800f21cf07d Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Wed, 24 May 2023 15:16:14 +0000
Subject: More size protection for winDde

---
 win/tclWinDde.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/win/tclWinDde.c b/win/tclWinDde.c
index 697aae6..3377bfa 100644
--- a/win/tclWinDde.c
+++ b/win/tclWinDde.c
@@ -313,12 +313,12 @@ DdeSetServerName(
     Tcl_Obj *handlerPtr)	/* Name of the optional proc/command to handle
 				 * incoming Dde eval's */
 {
-    int suffix, offset;
+    int suffix;
     RegisteredInterp *riPtr, *prevPtr;
     Tcl_DString dString;
     const WCHAR *actualName;
     Tcl_Obj *srvListPtr = NULL, **srvPtrPtr = NULL;
-    Tcl_Size n, srvCount = 0;
+    Tcl_Size n, srvCount = 0, offset;
     int lastSuffix, r = TCL_OK;
     ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
 
@@ -942,8 +942,8 @@ DdeServerProc(
 	 */
 
 	HSZPAIR *returnPtr;
-	int i;
-	int numItems;
+	Tcl_Size i;
+	DWORD numItems;
 
 	for (i = 0, riPtr = tsdPtr->interpListPtr; riPtr != NULL;
 		i++, riPtr = riPtr->nextPtr) {
@@ -952,12 +952,15 @@ DdeServerProc(
 	     */
 	}
 
-	numItems = i;
+	if ((size_t)i >= UINT_MAX/sizeof(HSZPAIR)) {
+	    return NULL;
+	}
+	numItems = (DWORD)i;
 	ddeReturn = DdeCreateDataHandle(ddeInstance, NULL,
-		(numItems + 1) * sizeof(HSZPAIR), 0, 0, 0, 0);
+		(numItems + 1) * (DWORD)sizeof(HSZPAIR), 0, 0, 0, 0);
 	returnPtr = (HSZPAIR *) DdeAccessData(ddeReturn, &dlen);
 	len = dlen;
-	for (i = 0, riPtr = tsdPtr->interpListPtr; i < numItems;
+	for (i = 0, riPtr = tsdPtr->interpListPtr; i < (Tcl_Size)numItems;
 		i++, riPtr = riPtr->nextPtr) {
 	    returnPtr[i].hszSvc = DdeCreateStringHandleW(ddeInstance,
 		    TCL_DDE_SERVICE_NAME, CP_WINUNICODE);
@@ -1645,7 +1648,7 @@ DdeObjCmd(
 
 			if ((tmp >= sizeof(WCHAR))
 				&& !dataString[tmp / sizeof(WCHAR) - 1]) {
-			    tmp -= sizeof(WCHAR);
+			    tmp -= (DWORD)sizeof(WCHAR);
 			}
 			Tcl_DStringInit(&dsBuf);
 			Tcl_WCharToUtfDString(dataString, tmp>>1, &dsBuf);
-- 
cgit v0.12


From c7771a763e2451560f1667170fba99a679e1e9eb Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Wed, 24 May 2023 15:18:05 +0000
Subject: =?UTF-8?q?Enhance=20html=20generation,=20so=20it=20can=20handle?=
 =?UTF-8?q?=20the=20"=C2=A9"=20copy-sign=20as=20well?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 tools/tcltk-man2html-utils.tcl | 2 +-
 tools/tcltk-man2html.tcl       | 2 +-
 unix/Makefile.in               | 2 +-
 win/Makefile.in                | 2 +-
 win/makefile.vc                | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/tools/tcltk-man2html-utils.tcl b/tools/tcltk-man2html-utils.tcl
index 78aa8ec..63e1fb9 100644
--- a/tools/tcltk-man2html-utils.tcl
+++ b/tools/tcltk-man2html-utils.tcl
@@ -1271,7 +1271,7 @@ proc output-directive {line} {
 ##
 proc merge-copyrights {l1 l2} {
     set merge {}
-    set re1 {^Copyright +(?:\(c\)|\\\(co|&copy;) +(\w.*?)(?:all rights reserved)?(?:\. )*$}
+    set re1 {^Copyright +(?:\(c\)|\\\(©|co|&copy;) +(\w.*?)(?:all rights reserved)?(?:\. )*$}
     set re2 {^(\d+) +(?:by +)?(\w.*)$}         ;# date who
     set re3 {^(\d+)-(\d+) +(?:by +)?(\w.*)$}   ;# from to who
     set re4 {^(\d+), *(\d+) +(?:by +)?(\w.*)$} ;# date1 date2 who
diff --git a/tools/tcltk-man2html.tcl b/tools/tcltk-man2html.tcl
index 5f211f3..2b35bd8 100755
--- a/tools/tcltk-man2html.tcl
+++ b/tools/tcltk-man2html.tcl
@@ -29,7 +29,7 @@ set ::CSSFILE "docs.css"
 ## Source the utility functions that provide most of the
 ## implementation of the transformation from nroff to html.
 ##
-source [file join [file dirname [info script]] tcltk-man2html-utils.tcl]
+source -encoding utf-8 [file join [file dirname [info script]] tcltk-man2html-utils.tcl]
 
 proc getversion {tclh {name {}}} {
     if {[file exists $tclh]} {
diff --git a/unix/Makefile.in b/unix/Makefile.in
index 802472b..996cd30 100644
--- a/unix/Makefile.in
+++ b/unix/Makefile.in
@@ -2424,7 +2424,7 @@ html-tk: ${NATIVE_TCLSH}
 	@EXTRA_BUILD_HTML@
 
 BUILD_HTML = \
-	@${NATIVE_TCLSH} $(TOOL_DIR)/tcltk-man2html.tcl \
+	@${NATIVE_TCLSH} -encoding utf-8 $(TOOL_DIR)/tcltk-man2html.tcl \
 		--useversion=$(MAJOR_VERSION).$(MINOR_VERSION) \
 		--htmldir="$(HTML_INSTALL_DIR)" \
 		--srcdir=$(TOP_DIR) $(BUILD_HTML_FLAGS)
diff --git a/win/Makefile.in b/win/Makefile.in
index 6c92749..b282452 100644
--- a/win/Makefile.in
+++ b/win/Makefile.in
@@ -974,7 +974,7 @@ runtest: tcltest
 # `make shell SCRIPT=foo.tcl`
 shell: binaries
 	@TCL_LIBRARY="$(LIBRARY_DIR)"; export TCL_LIBRARY; \
-	$(WINE) ./$(TCLSH) $(SCRIPT)
+	$(WINE) ./$(TCLSH) -encoding utf-8 $(SCRIPT)
 
 # This target can be used to run tclsh inside either gdb or insight
 gdb: binaries
diff --git a/win/makefile.vc b/win/makefile.vc
index d1f4ef3..b1a8b6a 100644
--- a/win/makefile.vc
+++ b/win/makefile.vc
@@ -676,7 +676,7 @@ CHMFILE=$(HTMLDIR)\$(HTMLBASE).chm
 htmlhelp: chmsetup $(CHMFILE)
 
 $(CHMFILE): $(DOCDIR)\*
-	@$(TCLSH) $(TOOLSDIR)\tcltk-man2html.tcl "--htmldir=$(HTMLDIR)"
+	@$(TCLSH) -encoding utf-8 $(TOOLSDIR)\tcltk-man2html.tcl "--htmldir=$(HTMLDIR)"
 	@echo Compiling HTML help project
 	-"$(HHC)" <<$(HHPFILE) >NUL
 [OPTIONS]
-- 
cgit v0.12


From 70a3d08fc4eb639c20c5613ea5952a0dfdd5e935 Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Wed, 24 May 2023 15:22:00 +0000
Subject: Fix regular expression in previous commit

---
 tools/tcltk-man2html-utils.tcl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/tcltk-man2html-utils.tcl b/tools/tcltk-man2html-utils.tcl
index 63e1fb9..c658d71 100644
--- a/tools/tcltk-man2html-utils.tcl
+++ b/tools/tcltk-man2html-utils.tcl
@@ -1271,7 +1271,7 @@ proc output-directive {line} {
 ##
 proc merge-copyrights {l1 l2} {
     set merge {}
-    set re1 {^Copyright +(?:\(c\)|\\\(©|co|&copy;) +(\w.*?)(?:all rights reserved)?(?:\. )*$}
+    set re1 {^Copyright +(?:\(c\)|\\\(co|©|&copy;) +(\w.*?)(?:all rights reserved)?(?:\. )*$}
     set re2 {^(\d+) +(?:by +)?(\w.*)$}         ;# date who
     set re3 {^(\d+)-(\d+) +(?:by +)?(\w.*)$}   ;# from to who
     set re4 {^(\d+), *(\d+) +(?:by +)?(\w.*)$} ;# date1 date2 who
-- 
cgit v0.12