--- include/ptlib/unix/ptlib/contain.h.orig	2009-08-29 14:52:29.000000000 +0400
+++ include/ptlib/unix/ptlib/contain.h	2009-08-29 14:52:33.000000000 +0400
@@ -81,9 +81,11 @@
 #ifdef P_64BIT
 typedef long          INT;
 typedef unsigned long UINT;
+#define _hptr(x)        (PINDEX)(unsigned long)(x)
 #else
 typedef int           INT;
 typedef unsigned int  UINT;
+#define _hptr(x)        (unsigned)(x)
 #endif
 
 // Create "Windows" style definitions.
--- src/ptlib/unix/tlib.cxx.orig	2009-08-29 15:51:42.000000000 +0400
+++ src/ptlib/unix/tlib.cxx	2009-08-29 15:51:45.000000000 +0400
@@ -400,7 +400,7 @@
 {
   if (PProcessInstance != NULL) {
     PWaitAndSignal m(PProcessInstance->activeThreadMutex);
-    PThread & thread = PProcessInstance->activeThreads[(uintptr_t)id];
+    PThread & thread = PProcessInstance->activeThreads[_hptr(id)];
     return thread.GetThreadName();
   }
   return psprintf("%08x", id);
--- src/ptlib/unix/tlibthrd.cxx.orig	2009-08-29 14:54:22.000000000 +0400
+++ src/ptlib/unix/tlibthrd.cxx	2009-08-29 15:41:14.000000000 +0400
@@ -250,7 +250,7 @@
 {
   PWaitAndSignal m(activeThreadMutex);
 
-  if (!activeThreads.Contains((unsigned)id)) 
+  if (!activeThreads.Contains(_hptr(id))) 
     return PFalse;
 
   return pthread_kill(id, sig) == 0;
@@ -259,8 +259,8 @@
 void PProcess::PXSetThread(pthread_t id, PThread * thread)
 {
   activeThreadMutex.Wait();
-  PThread * currentThread = activeThreads.GetAt((PINDEX)id);
-  activeThreads.SetAt((PINDEX)id, thread);
+  PThread * currentThread = activeThreads.GetAt(_hptr(id));
+  activeThreads.SetAt(_hptr(id), thread);
   activeThreadMutex.Signal();
 
   if (currentThread != NULL) 
@@ -393,7 +393,7 @@
     if (id != 0) {
       process.activeThreadMutex.Wait();
       pthread_detach(id);
-      process.activeThreads.SetAt((unsigned)id, NULL);
+      process.activeThreads.SetAt(_hptr(id), NULL);
       process.activeThreadMutex.Signal();
     }
 
--- src/ptlib/common/osutils.cxx.orig	2009-08-29 15:55:29.000000000 +0400
+++ src/ptlib/common/osutils.cxx	2009-08-29 15:55:32.000000000 +0400
@@ -2208,21 +2208,21 @@
 PReadWriteMutex::Nest * PReadWriteMutex::GetNest() const
 {
   PWaitAndSignal mutex(nestingMutex);
-  return nestedThreads.GetAt(POrdinalKey((INT)PThread::GetCurrentThreadId()));
+  return nestedThreads.GetAt(POrdinalKey(_hptr(PThread::GetCurrentThreadId())));
 }
 
 
 void PReadWriteMutex::EndNest()
 {
   nestingMutex.Wait();
-  nestedThreads.RemoveAt(POrdinalKey((INT)PThread::GetCurrentThreadId()));
+  nestedThreads.RemoveAt(POrdinalKey(_hptr(PThread::GetCurrentThreadId())));
   nestingMutex.Signal();
 }
 
 
 PReadWriteMutex::Nest & PReadWriteMutex::StartNest()
 {
-  POrdinalKey threadId = (INT)PThread::GetCurrentThreadId();
+  POrdinalKey threadId = _hptr(PThread::GetCurrentThreadId());
 
   nestingMutex.Wait();
 
