Index: generic/tclCompExpr.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclCompExpr.c,v
retrieving revision 1.35
diff -u -p -r1.35 tclCompExpr.c
--- generic/tclCompExpr.c	9 Nov 2006 16:52:30 -0000	1.35
+++ generic/tclCompExpr.c	10 Nov 2006 04:23:05 -0000
@@ -1246,7 +1246,7 @@ TclCompileExpr(
 		Tcl_HashEntry *hPtr = Tcl_CreateHashEntry(&opHashTable,
 			operatorTable[i].name, &new);
 		if (new) {
-		    Tcl_SetHashValue(hPtr, (ClientData) i);
+		    Tcl_SetHashValue(hPtr, (ClientData) INT2PTR(i));
 		}
 	    }
 	    opTableInitialized = 1;
@@ -1387,7 +1387,7 @@ CompileSubExpr(
 	    break;
 	}
 	Tcl_DStringFree(&opBuf);
-	opIndex = (int) Tcl_GetHashValue(hPtr);
+	opIndex = PTR2INT(Tcl_GetHashValue(hPtr));
 	opDescPtr = &(operatorTable[opIndex]);
 
 	/*
Index: generic/tclEncoding.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclEncoding.c,v
retrieving revision 1.50
diff -u -p -r1.50 tclEncoding.c
--- generic/tclEncoding.c	2 Nov 2006 16:14:20 -0000	1.50
+++ generic/tclEncoding.c	10 Nov 2006 04:23:06 -0000
@@ -2760,7 +2760,7 @@ EscapeToUtfProc(
     dstStart = dst;
     dstEnd = dst + dstLen - TCL_UTF_MAX;
 
-    state = (int) *statePtr;
+    state = PTR2INT(*statePtr);
     if (flags & TCL_ENCODING_START) {
 	state = 0;
     }
@@ -2899,7 +2899,7 @@ EscapeToUtfProc(
 	numChars++;
     }
 
-    *statePtr = (Tcl_EncodingState) state;
+    *statePtr = (Tcl_EncodingState) INT2PTR(state);
     *srcReadPtr = src - srcStart;
     *dstWrotePtr = dst - dstStart;
     *dstCharsPtr = numChars;
@@ -2989,7 +2989,7 @@ EscapeFromUtfProc(
 	memcpy((VOID *)dst, (VOID *)dataPtr->init, (size_t)dataPtr->initLen);
 	dst += dataPtr->initLen;
     } else {
-	state = (int) *statePtr;
+	state = PTR2INT(*statePtr);
     }
 
     encodingPtr = GetTableEncoding(dataPtr, state);
@@ -3103,7 +3103,7 @@ EscapeFromUtfProc(
 	}
     }
 
-    *statePtr = (Tcl_EncodingState) state;
+    *statePtr = (Tcl_EncodingState) INT2PTR(state);
     *srcReadPtr = src - srcStart;
     *dstWrotePtr = dst - dstStart;
     *dstCharsPtr = numChars;
Index: generic/tclEvent.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclEvent.c,v
retrieving revision 1.68
diff -u -p -r1.68 tclEvent.c
--- generic/tclEvent.c	19 Sep 2006 22:07:34 -0000	1.68
+++ generic/tclEvent.c	10 Nov 2006 04:23:06 -0000
@@ -721,7 +721,7 @@ Tcl_Exit(
 	 * returns, so critical is this dependcy.
 	 */
 
-	currentAppExitPtr((ClientData) status);
+	currentAppExitPtr((ClientData) INT2PTR(status));
 	Tcl_Panic("AppExitProc returned unexpectedly");
     } else {
 	/*
Index: generic/tclExecute.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
retrieving revision 1.249
diff -u -p -r1.249 tclExecute.c
--- generic/tclExecute.c	2 Nov 2006 15:58:08 -0000	1.249
+++ generic/tclExecute.c	10 Nov 2006 04:23:06 -0000
@@ -659,7 +659,7 @@ TclStackAlloc(
 
     eePtr->tosPtr += numWords;
     *(eePtr->tosPtr-1) = (Tcl_Obj *) stackRefCountPtr;
-    *(eePtr->tosPtr)   = (Tcl_Obj *) numWords;
+    *(eePtr->tosPtr)   = (Tcl_Obj *) INT2PTR(numWords);
 
     return (char *) (tosPtr+1);
 }
@@ -673,7 +673,7 @@ TclStackFree(
     char **stackRefCountPtr;
 
     stackRefCountPtr = (char **) *(eePtr->tosPtr-1);
-    eePtr->tosPtr -= (int) *(eePtr->tosPtr);
+    eePtr->tosPtr -= PTR2INT(*(eePtr->tosPtr));
 
     --*stackRefCountPtr;
     if (*stackRefCountPtr == (char *) 0) {
@@ -2645,7 +2645,7 @@ TclExecuteByteCode(
 	TRACE(("%d => %.20s ", opnd, O2S(*tosPtr)));
 	hPtr = Tcl_FindHashEntry(&jtPtr->hashTable, Tcl_GetString(*tosPtr));
 	if (hPtr != NULL) {
-	    int jumpOffset = (int) Tcl_GetHashValue(hPtr);
+	    int jumpOffset = PTR2INT(Tcl_GetHashValue(hPtr));
 
 	    TRACE_APPEND(("found in table, new pc %u\n",
 		    (unsigned int)(pc - codePtr->codeStart + jumpOffset)));
Index: generic/tclHash.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclHash.c,v
retrieving revision 1.26
diff -u -p -r1.26 tclHash.c
--- generic/tclHash.c	22 Oct 2006 00:13:29 -0000	1.26
+++ generic/tclHash.c	10 Nov 2006 04:23:06 -0000
@@ -329,7 +329,7 @@ Tcl_CreateHashEntry(
 	    index = hash & tablePtr->mask;
 	}
     } else {
-	hash = (unsigned int) key;
+	hash = PTR2UINT(key);
 	index = RANDOM_INDEX (tablePtr, hash);
     }
 
@@ -342,7 +342,7 @@ Tcl_CreateHashEntry(
 	for (hPtr = tablePtr->buckets[index]; hPtr != NULL;
 		hPtr = hPtr->nextPtr) {
 #if TCL_HASH_KEY_STORE_HASH
-	    if (hash != (unsigned int) hPtr->hash) {
+	    if (hash != PTR2UINT(hPtr->hash)) {
 		continue;
 	    }
 #endif
@@ -356,7 +356,7 @@ Tcl_CreateHashEntry(
 	for (hPtr = tablePtr->buckets[index]; hPtr != NULL;
 		hPtr = hPtr->nextPtr) {
 #if TCL_HASH_KEY_STORE_HASH
-	    if (hash != (unsigned int) hPtr->hash) {
+	    if (hash != PTR2UINT(hPtr->hash)) {
 		continue;
 	    }
 #endif
@@ -387,7 +387,7 @@ Tcl_CreateHashEntry(
     hPtr->tablePtr = tablePtr;
 #if TCL_HASH_KEY_STORE_HASH
 #   if TCL_PRESERVE_BINARY_COMPATABILITY
-    hPtr->hash = (VOID *) hash;
+    hPtr->hash = UINT2PTR(hash);
 #   else
     hPtr->hash = hash;
 #   endif
@@ -464,7 +464,7 @@ Tcl_DeleteHashEntry(
 	    || typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
 	index = RANDOM_INDEX (tablePtr, entryPtr->hash);
     } else {
-	index = ((unsigned int) entryPtr->hash) & tablePtr->mask;
+	index = PTR2UINT(entryPtr->hash) & tablePtr->mask;
     }
 
     bucketPtr = &(tablePtr->buckets[index]);
@@ -1127,7 +1127,7 @@ RebuildTable(
 		    || typePtr->flags & TCL_HASH_KEY_RANDOMIZE_HASH) {
 		index = RANDOM_INDEX (tablePtr, hPtr->hash);
 	    } else {
-		index = ((unsigned int) hPtr->hash) & tablePtr->mask;
+		index = PTR2UINT(hPtr->hash) & tablePtr->mask;
 	    }
 	    hPtr->nextPtr = tablePtr->buckets[index];
 	    tablePtr->buckets[index] = hPtr;
Index: generic/tclIO.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclIO.c,v
retrieving revision 1.110
diff -u -p -r1.110 tclIO.c
--- generic/tclIO.c	8 Nov 2006 11:41:44 -0000	1.110
+++ generic/tclIO.c	10 Nov 2006 04:23:07 -0000
@@ -9414,7 +9414,7 @@ HaveVersion(
 {
     Tcl_ChannelTypeVersion actualVersion = Tcl_ChannelVersion(chanTypePtr);
 
-    return ((int)actualVersion) >= ((int)minimumVersion);
+    return (PTR2INT(actualVersion)) >= (PTR2INT(minimumVersion));
 }
 
 /*
Index: generic/tclInt.h
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclInt.h,v
retrieving revision 1.293
diff -u -p -r1.293 tclInt.h
--- generic/tclInt.h	9 Nov 2006 15:19:03 -0000	1.293
+++ generic/tclInt.h	10 Nov 2006 04:23:08 -0000
@@ -113,6 +113,31 @@ typedef int ptrdiff_t;
 #endif
 
 /*
+ * 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".
+ */
+
+#if !defined(INT2PTR) && !defined(PTR2INT)
+#   if defined(HAVE_INTPTR_T) || defined(intptr_t)	
+#       define INT2PTR(p) ((void*)(intptr_t)(p))
+#       define PTR2INT(p) ((int)(intptr_t)(p))
+#   else
+#       define INT2PTR(p) ((void*)(p))
+#       define PTR2INT(p) ((int)(p))
+#   endif
+#endif
+#if !defined(UINT2PTR) && !defined(PTR2UINT)
+#   if defined(HAVE_UINTPTR_T) || defined(uintptr_t)
+#       define UINT2PTR(p) ((void*)(uintptr_t)(p))
+#       define PTR2UINT(p) ((unsigned int)(uintptr_t)(p))
+#   else
+#       define UINT2PTR(p) ((void*)(p))
+#       define PTR2UINT(p) ((unsigned int)(p))
+#   endif
+#endif
+
+/*
  * The following procedures allow namespaces to be customized to support
  * special name resolution rules for commands/variables.
  */
Index: generic/tclProc.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclProc.c,v
retrieving revision 1.105
diff -u -p -r1.105 tclProc.c
--- generic/tclProc.c	2 Nov 2006 16:39:07 -0000	1.105
+++ generic/tclProc.c	10 Nov 2006 04:23:08 -0000
@@ -682,10 +682,10 @@ TclObjGetFrame(
     result = 1;
     curLevel = iPtr->varFramePtr->level;
     if (objPtr->typePtr == &levelReferenceType) {
-	if ((int) objPtr->internalRep.twoPtrValue.ptr1) {
-	    level = curLevel - (int) objPtr->internalRep.twoPtrValue.ptr2;
+	if (PTR2INT(objPtr->internalRep.twoPtrValue.ptr1)) {
+	    level = curLevel - PTR2INT(objPtr->internalRep.twoPtrValue.ptr2);
 	} else {
-	    level = (int) objPtr->internalRep.twoPtrValue.ptr2;
+	    level = PTR2INT(objPtr->internalRep.twoPtrValue.ptr2);
 	}
 	if (level < 0) {
 	    goto levelError;
@@ -715,7 +715,7 @@ TclObjGetFrame(
 	    TclFreeIntRep(objPtr);
 	    objPtr->typePtr = &levelReferenceType;
 	    objPtr->internalRep.twoPtrValue.ptr1 = (void *) 0;
-	    objPtr->internalRep.twoPtrValue.ptr2 = (void *) level;
+	    objPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(level);
 	} else if (isdigit(UCHAR(*name))) { /* INTL: digit */
 	    if (Tcl_GetInt(interp, name, &level) != TCL_OK) {
 		return -1;
@@ -730,7 +730,7 @@ TclObjGetFrame(
 	    TclFreeIntRep(objPtr);
 	    objPtr->typePtr = &levelReferenceType;
 	    objPtr->internalRep.twoPtrValue.ptr1 = (void *) 1;
-	    objPtr->internalRep.twoPtrValue.ptr2 = (void *) level;
+	    objPtr->internalRep.twoPtrValue.ptr2 = INT2PTR(level);
 	    level = curLevel - level;
 	} else {
 	    /*
Index: generic/tclTest.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclTest.c,v
retrieving revision 1.105
diff -u -p -r1.105 tclTest.c
--- generic/tclTest.c	22 Sep 2006 18:13:29 -0000	1.105
+++ generic/tclTest.c	10 Nov 2006 04:23:08 -0000
@@ -1440,10 +1440,10 @@ TestdcallCmd(dummy, interp, argc, argv)
 	}
 	if (id < 0) {
 	    Tcl_DontCallWhenDeleted(delInterp, DelCallbackProc,
-		    (ClientData) (-id));
+		    (ClientData) INT2PTR(-id));
 	} else {
 	    Tcl_CallWhenDeleted(delInterp, DelCallbackProc,
-		    (ClientData) id);
+		    (ClientData) INT2PTR(id));
 	}
     }
     Tcl_DeleteInterp(delInterp);
@@ -1461,7 +1461,7 @@ DelCallbackProc(clientData, interp)
 					 * delString. */
     Tcl_Interp *interp;			/* Interpreter being deleted. */
 {
-    int id = (int) clientData;
+    int id = PTR2INT(clientData);
     char buffer[TCL_INTEGER_SPACE];
 
     TclFormatInt(buffer, id);
@@ -2181,10 +2181,10 @@ TestexithandlerCmd(clientData, interp, a
     }
     if (strcmp(argv[1], "create") == 0) {
 	Tcl_CreateExitHandler((value & 1) ? ExitProcOdd : ExitProcEven,
-		(ClientData) value);
+		(ClientData) INT2PTR(value));
     } else if (strcmp(argv[1], "delete") == 0) {
 	Tcl_DeleteExitHandler((value & 1) ? ExitProcOdd : ExitProcEven,
-		(ClientData) value);
+		(ClientData) INT2PTR(value));
     } else {
 	Tcl_AppendResult(interp, "bad option \"", argv[1],
 		"\": must be create or delete", NULL);
@@ -2199,7 +2199,7 @@ ExitProcOdd(clientData)
 {
     char buf[16 + TCL_INTEGER_SPACE];
 
-    sprintf(buf, "odd %d\n", (int) clientData);
+    sprintf(buf, "odd %d\n", PTR2INT(clientData));
     write(1, buf, strlen(buf));
 }
 
@@ -2209,7 +2209,7 @@ ExitProcEven(clientData)
 {
     char buf[16 + TCL_INTEGER_SPACE];
 
-    sprintf(buf, "even %d\n", (int) clientData);
+    sprintf(buf, "even %d\n", PTR2INT(clientData));
     write(1, buf, strlen(buf));
 }
 
@@ -3159,7 +3159,7 @@ TestMathFunc(clientData, interp, args, r
     Tcl_Value *resultPtr;		/* Where to store result. */
 {
     resultPtr->type = TCL_INT;
-    resultPtr->intValue = (int) clientData;
+    resultPtr->intValue = PTR2INT(clientData);
     return TCL_OK;
 }
 
@@ -4813,7 +4813,7 @@ TestsetCmd(data, interp, argc, argv)
     int argc;				/* Number of arguments. */
     CONST char **argv;			/* Argument strings. */
 {
-    int flags = (int) data;
+    int flags = PTR2INT(data);
     CONST char *value;
 
     if (argc == 2) {
@@ -6953,14 +6953,14 @@ TestHashSystemHashCmd(clientData, interp
     }
 
     for (i=0 ; i<limit ; i++) {
-	hPtr = Tcl_CreateHashEntry(&hash, (char *)i, &isNew);
+	hPtr = Tcl_CreateHashEntry(&hash, (char*) INT2PTR(i), &isNew);
 	if (!isNew) {
 	    Tcl_SetObjResult(interp, Tcl_NewIntObj(i));
 	    Tcl_AppendToObj(Tcl_GetObjResult(interp)," creation problem",-1);
 	    Tcl_DeleteHashTable(&hash);
 	    return TCL_ERROR;
 	}
-	Tcl_SetHashValue(hPtr, (ClientData) (i+42));
+	Tcl_SetHashValue(hPtr, (ClientData) INT2PTR(i+42));
     }
 
     if (hash.numEntries != limit) {
@@ -6970,14 +6970,14 @@ TestHashSystemHashCmd(clientData, interp
     }
 
     for (i=0 ; i<limit ; i++) {
-	hPtr = Tcl_FindHashEntry(&hash, (char *)i);
+	hPtr = Tcl_FindHashEntry(&hash, (char*) INT2PTR(i));
 	if (hPtr == NULL) {
 	    Tcl_SetObjResult(interp, Tcl_NewIntObj(i));
 	    Tcl_AppendToObj(Tcl_GetObjResult(interp)," lookup problem",-1);
 	    Tcl_DeleteHashTable(&hash);
 	    return TCL_ERROR;
 	}
-	if ((int)(Tcl_GetHashValue(hPtr)) != i+42) {
+	if (PTR2INT(Tcl_GetHashValue(hPtr)) != i+42) {
 	    Tcl_SetObjResult(interp, Tcl_NewIntObj(i));
 	    Tcl_AppendToObj(Tcl_GetObjResult(interp)," value problem",-1);
 	    Tcl_DeleteHashTable(&hash);
Index: generic/tclThreadStorage.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclThreadStorage.c,v
retrieving revision 1.10
diff -u -p -r1.10 tclThreadStorage.c
--- generic/tclThreadStorage.c	7 Nov 2006 14:26:26 -0000	1.10
+++ generic/tclThreadStorage.c	10 Nov 2006 04:23:08 -0000
@@ -189,7 +189,7 @@ static Tcl_HashTable *
 ThreadStorageGetHashTable(
     Tcl_ThreadId id)		/* Id of thread to get hash table for */
 {
-    int index = (unsigned) id % STORAGE_CACHE_SLOTS;
+    int index = PTR2UINT(id) % STORAGE_CACHE_SLOTS;
     Tcl_HashEntry *hPtr;
     int new;
 
@@ -397,7 +397,7 @@ TclpFinalizeThreadDataThread(void)
 {
     Tcl_ThreadId id = Tcl_GetCurrentThread();
 				/* Id of the thread to finalize. */
-    int index = (unsigned int)id % STORAGE_CACHE_SLOTS;
+    int index = PTR2UINT(id) % STORAGE_CACHE_SLOTS;
     Tcl_HashEntry *hPtr;	/* Hash entry for current thread in master
 				 * table. */
     Tcl_HashTable* hashTablePtr;/* Pointer to the hash table holding TSD
Index: generic/tclTimer.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclTimer.c,v
retrieving revision 1.26
diff -u -p -r1.26 tclTimer.c
--- generic/tclTimer.c	2 Nov 2006 15:58:09 -0000	1.26
+++ generic/tclTimer.c	10 Nov 2006 04:23:08 -0000
@@ -293,7 +293,7 @@ TclCreateAbsoluteTimerHandler(
     timerHandlerPtr->proc = proc;
     timerHandlerPtr->clientData = clientData;
     tsdPtr->lastTimerId++;
-    timerHandlerPtr->token = (Tcl_TimerToken) tsdPtr->lastTimerId;
+    timerHandlerPtr->token = (Tcl_TimerToken) INT2PTR(tsdPtr->lastTimerId);
 
     /*
      * Add the event to the queue in the correct position
@@ -567,7 +567,7 @@ TimerHandlerEventProc(
 	 * Bail out if the next timer is of a newer generation.
 	 */
 
-	if ((currentTimerId - (int)timerHandlerPtr->token) < 0) {
+	if ((currentTimerId - PTR2INT(timerHandlerPtr->token)) < 0) {
 	    break;
 	}
 
Index: generic/tclUtil.c
===================================================================
RCS file: /cvsroot/tcl/tcl/generic/tclUtil.c,v
retrieving revision 1.74
diff -u -p -r1.74 tclUtil.c
--- generic/tclUtil.c	2 Nov 2006 15:58:09 -0000	1.74
+++ generic/tclUtil.c	10 Nov 2006 04:23:09 -0000
@@ -2635,7 +2635,7 @@ TclSetProcessGlobalValue(
     Tcl_IncrRefCount(newValue);
     cacheMap = GetThreadHash(&pgvPtr->key);
     ClearHash(cacheMap);
-    hPtr = Tcl_CreateHashEntry(cacheMap, (char *)pgvPtr->epoch, &dummy);
+    hPtr = Tcl_CreateHashEntry(cacheMap, (char *) INT2PTR(pgvPtr->epoch), &dummy);
     Tcl_SetHashValue(hPtr, (ClientData) newValue);
     Tcl_MutexUnlock(&pgvPtr->mutex);
 }
@@ -2697,7 +2697,7 @@ TclGetProcessGlobalValue(
 	}
     }
     cacheMap = GetThreadHash(&pgvPtr->key);
-    hPtr = Tcl_FindHashEntry(cacheMap, (char *)epoch);
+    hPtr = Tcl_FindHashEntry(cacheMap, (char *) INT2PTR(epoch));
     if (NULL == hPtr) {
 	int dummy;
 
@@ -2730,7 +2730,7 @@ TclGetProcessGlobalValue(
 	 */
 
 	value = Tcl_NewStringObj(pgvPtr->value, pgvPtr->numBytes);
-	hPtr = Tcl_CreateHashEntry(cacheMap, (char *)pgvPtr->epoch, &dummy);
+	hPtr = Tcl_CreateHashEntry(cacheMap, (char *) INT2PTR(pgvPtr->epoch), &dummy);
 	Tcl_MutexUnlock(&pgvPtr->mutex);
 	Tcl_SetHashValue(hPtr, (ClientData) value);
 	Tcl_IncrRefCount(value);
Index: unix/configure.in
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/configure.in,v
retrieving revision 1.151
diff -u -p -r1.151 configure.in
--- unix/configure.in	10 Nov 2006 01:55:58 -0000	1.151
+++ unix/configure.in	10 Nov 2006 04:23:09 -0000
@@ -315,7 +315,7 @@ AC_TYPE_PID_T
 AC_TYPE_SIZE_T
 AC_TYPE_UID_T
 
-AC_CACHE_CHECK([for socklen_t], ac_cv_type_socklen_t, [
+AC_CACHE_CHECK([for socklen_t], tcl_cv_type_socklen_t, [
     AC_EGREP_CPP(changequote(<<,>>)dnl
 <<(^|[^a-zA-Z_0-9])socklen_t[^a-zA-Z_0-9]>>dnl
 changequote([,]),[
@@ -325,11 +325,43 @@ changequote([,]),[
     #include <stdlib.h>
     #include <stddef.h>
     #endif
-    ], ac_cv_type_socklen_t=yes, ac_cv_type_socklen_t=no)])
-if test $ac_cv_type_socklen_t = no; then
+    ], tcl_cv_type_socklen_t=yes, tcl_cv_type_socklen_t=no)])
+if test $tcl_cv_type_socklen_t = no; then
     AC_DEFINE(socklen_t, unsigned, [What is the type of socklen_t?])
 fi
 
+AC_CHECK_TYPE([intptr_t], [
+    AC_DEFINE([HAVE_INTPTR_T], 1, [Do we have the intptr_t type?])], [
+    AC_CACHE_CHECK([for pointer-size signed integer type], tcl_cv_intptr_t, [
+    for tcl_cv_intptr_t in "int" "long" "long long" none; do
+	if test "$tcl_cv_intptr_t" != none; then
+	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
+		    [[sizeof (void *) <= sizeof ($tcl_cv_intptr_t)]])], 
+		[tcl_ok=yes], [tcl_ok=no])
+	    test "$tcl_ok" = yes && break; fi
+    done])
+    if test "$tcl_cv_intptr_t" != none; then
+	AC_DEFINE_UNQUOTED([intptr_t], [$tcl_cv_intptr_t], [Signed integer
+	   type wide enough to hold a pointer.])
+    fi
+])
+AC_CHECK_TYPE([uintptr_t], [
+    AC_DEFINE([HAVE_UINTPTR_T], 1, [Do we have the uintptr_t type?])], [
+    AC_CACHE_CHECK([for pointer-size unsigned integer type], tcl_cv_uintptr_t, [
+    for tcl_cv_uintptr_t in "unsigned int" "unsigned long" "unsigned long long" \
+	    none; do
+	if test "$tcl_cv_uintptr_t" != none; then
+	    AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([AC_INCLUDES_DEFAULT],
+		    [[sizeof (void *) <= sizeof ($tcl_cv_uintptr_t)]])], 
+		[tcl_ok=yes], [tcl_ok=no])
+	    test "$tcl_ok" = yes && break; fi
+    done])
+    if test "$tcl_cv_uintptr_t" != none; then
+	AC_DEFINE_UNQUOTED([uintptr_t], [$tcl_cv_uintptr_t], [Unsigned integer
+	   type wide enough to hold a pointer.])
+    fi
+])
+
 #--------------------------------------------------------------------
 #	If a system doesn't have an opendir function (man, that's old!)
 #	then we have to supply a different version of dirent.h which
Index: unix/tclUnixChan.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixChan.c,v
retrieving revision 1.72
diff -u -p -r1.72 tclUnixChan.c
--- unix/tclUnixChan.c	7 Sep 2006 09:17:33 -0000	1.72
+++ unix/tclUnixChan.c	10 Nov 2006 04:23:10 -0000
@@ -729,7 +729,7 @@ FileGetHandleProc(
     FileState *fsPtr = (FileState *) instanceData;
 
     if (direction & fsPtr->validMask) {
-	*handlePtr = (ClientData) fsPtr->fd;
+	*handlePtr = (ClientData) INT2PTR(fsPtr->fd);
 	return TCL_OK;
     } else {
 	return TCL_ERROR;
@@ -1900,7 +1900,7 @@ Tcl_MakeFileChannel(
 {
     FileState *fsPtr;
     char channelName[16 + TCL_INTEGER_SPACE];
-    int fd = (int) handle;
+    int fd = PTR2INT(handle);
     Tcl_ChannelType *channelTypePtr;
     struct sockaddr sockaddr;
     socklen_t sockaddrLen = sizeof(sockaddr);
@@ -1921,7 +1921,7 @@ Tcl_MakeFileChannel(
     if (getsockname(fd, (struct sockaddr *)&sockaddr, &sockaddrLen) == 0
 	    && sockaddrLen > 0
 	    && sockaddr.sa_family == AF_INET) {
-	return MakeTcpClientChannelMode((ClientData) fd, mode);
+	return MakeTcpClientChannelMode((ClientData) INT2PTR(fd), mode);
     } else {
 	channelTypePtr = &fileChannelType;
 	fsPtr = (FileState *) ckalloc((unsigned) sizeof(FileState));
@@ -2423,7 +2423,7 @@ TcpGetHandleProc(
 {
     TcpState *statePtr = (TcpState *) instanceData;
 
-    *handlePtr = (ClientData)statePtr->fd;
+    *handlePtr = (ClientData) INT2PTR(statePtr->fd);
     return TCL_OK;
 }
 
@@ -2792,7 +2792,7 @@ MakeTcpClientChannelMode(
     char channelName[16 + TCL_INTEGER_SPACE];
 
     statePtr = (TcpState *) ckalloc((unsigned) sizeof(TcpState));
-    statePtr->fd = (int) sock;
+    statePtr->fd = PTR2INT(sock);
     statePtr->flags = 0;
     statePtr->acceptProc = NULL;
     statePtr->acceptProcData = NULL;
@@ -2998,7 +2998,7 @@ TclpGetDefaultStdChannel(
 #undef ZERO_OFFSET
 #undef ERROR_OFFSET
 
-    channel = Tcl_MakeFileChannel((ClientData) fd, mode);
+    channel = Tcl_MakeFileChannel((ClientData) INT2PTR(fd), mode);
     if (channel == NULL) {
 	return NULL;
     }
@@ -3088,7 +3088,7 @@ Tcl_GetOpenFile(
 	if (Tcl_GetChannelHandle(chan,
 		(forWriting ? TCL_WRITABLE : TCL_READABLE),
 		(ClientData*) &data) == TCL_OK) {
-	    fd = (int) data;
+	    fd = PTR2INT(data);
 
 	    /*
 	     * The call to fdopen below is probably dangerous, since it will
Index: unix/tclUnixPipe.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixPipe.c,v
retrieving revision 1.35
diff -u -p -r1.35 tclUnixPipe.c
--- unix/tclUnixPipe.c	2 Aug 2006 20:04:11 -0000	1.35
+++ unix/tclUnixPipe.c	10 Nov 2006 04:23:10 -0000
@@ -25,8 +25,8 @@
  * the same as NULL.
  */
 
-#define MakeFile(fd)	((TclFile)(((int)fd)+1))
-#define GetFd(file)	(((int)file)-1)
+#define MakeFile(fd)	((TclFile)INT2PTR(((int)(fd))+1))
+#define GetFd(file)	(PTR2INT(file)-1)
 
 /*
  * This structure describes per-instance state of a pipe based channel.
@@ -113,7 +113,7 @@ TclpMakeFile(
 
     if (Tcl_GetChannelHandle(channel, direction,
 	    (ClientData *) &data) == TCL_OK) {
-	return MakeFile((int) data);
+	return MakeFile(PTR2INT(data));
     } else {
 	return (TclFile) NULL;
     }
@@ -513,7 +513,7 @@ TclpCreateProcess(
     }
 
     TclpCloseFile(errPipeIn);
-    *pidPtr = (Tcl_Pid) pid;
+    *pidPtr = (Tcl_Pid) INT2PTR(pid);
     return TCL_OK;
 
   error:
@@ -525,7 +525,7 @@ TclpCreateProcess(
 	 * here, since this is the error case. [Bug: 6148]
 	 */
 
-	Tcl_WaitPid((Tcl_Pid) pid, &status, 0);
+	Tcl_WaitPid((Tcl_Pid) INT2PTR(pid), &status, 0);
     }
 
     if (errPipeIn) {
@@ -964,7 +964,7 @@ PipeCloseProc(
 
 	if (pipePtr->errorFile) {
 	    errChan = Tcl_MakeFileChannel(
-		(ClientData) GetFd(pipePtr->errorFile), TCL_READABLE);
+		(ClientData) INT2PTR(GetFd(pipePtr->errorFile)), TCL_READABLE);
 	} else {
 	    errChan = NULL;
 	}
@@ -1157,11 +1157,11 @@ PipeGetHandleProc(
     PipeState *psPtr = (PipeState *) instanceData;
 
     if (direction == TCL_READABLE && psPtr->inFile) {
-	*handlePtr = (ClientData) GetFd(psPtr->inFile);
+	*handlePtr = (ClientData) INT2PTR(GetFd(psPtr->inFile));
 	return TCL_OK;
     }
     if (direction == TCL_WRITABLE && psPtr->outFile) {
-	*handlePtr = (ClientData) GetFd(psPtr->outFile);
+	*handlePtr = (ClientData) INT2PTR(GetFd(psPtr->outFile));
 	return TCL_OK;
     }
     return TCL_ERROR;
@@ -1192,11 +1192,11 @@ Tcl_WaitPid(
     int result;
     pid_t real_pid;
 
-    real_pid = (pid_t) pid;
+    real_pid = (pid_t) PTR2INT(pid);
     while (1) {
 	result = (int) waitpid(real_pid, statPtr, options);
 	if ((result != -1) || (errno != EINTR)) {
-	    return (Tcl_Pid) result;
+	    return (Tcl_Pid) INT2PTR(result);
 	}
     }
 }
Index: unix/tclUnixPort.h
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixPort.h,v
retrieving revision 1.55
diff -u -p -r1.55 tclUnixPort.h
--- unix/tclUnixPort.h	31 Oct 2006 22:24:39 -0000	1.55
+++ unix/tclUnixPort.h	10 Nov 2006 04:23:10 -0000
@@ -104,6 +104,12 @@ EXTERN Tcl_WideUInt	strtoull _ANSI_ARGS_
 #ifndef NO_SYS_WAIT_H
 #   include <sys/wait.h>
 #endif
+#if HAVE_INTTYPES_H
+#   include <inttypes.h>
+#endif
+#if HAVE_STDINT_H
+#   include <stdint.h>
+#endif
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #else
Index: unix/tclUnixTest.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixTest.c,v
retrieving revision 1.22
diff -u -p -r1.22 tclUnixTest.c
--- unix/tclUnixTest.c	14 Mar 2006 19:34:30 -0000	1.22
+++ unix/tclUnixTest.c	10 Nov 2006 04:23:10 -0000
@@ -28,8 +28,8 @@
  * the same as NULL. Note that this code is duplicated from tclUnixPipe.c
  */
 
-#define MakeFile(fd) ((TclFile)((fd)+1))
-#define GetFd(file) (((int)file)-1)
+#define MakeFile(fd)	((TclFile)INT2PTR(((int)(fd))+1))
+#define GetFd(file)	(PTR2INT(file)-1)
 
 /*
  * The stuff below is used to keep track of file handlers created and
@@ -402,7 +402,7 @@ TestfilewaitCmd(
 	Tcl_SetResult(interp, "couldn't get channel file", TCL_STATIC);
 	return TCL_ERROR;
     }
-    fd = (int) data;
+    fd = PTR2INT(data);
     if (Tcl_GetInt(interp, argv[3], &timeout) != TCL_OK) {
 	return TCL_ERROR;
     }
Index: unix/tclUnixThrd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixThrd.c,v
retrieving revision 1.45
diff -u -p -r1.45 tclUnixThrd.c
--- unix/tclUnixThrd.c	16 Oct 2006 18:41:25 -0000	1.45
+++ unix/tclUnixThrd.c	10 Nov 2006 04:23:10 -0000
@@ -191,7 +191,7 @@ void
 TclpThreadExit(
     int status)
 {
-    pthread_exit((VOID *)status);
+    pthread_exit(INT2PTR(status));
 }
 #endif /* TCL_THREADS */
 
