]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Define ULong_to_Ptr / Ptr_to_ULong to help clean up 64/32 bit issues.
authorJulian Seward <jseward@acm.org>
Mon, 7 Feb 2005 00:00:50 +0000 (00:00 +0000)
committerJulian Seward <jseward@acm.org>
Mon, 7 Feb 2005 00:00:50 +0000 (00:00 +0000)
git-svn-id: svn://svn.valgrind.org/vex/trunk@853

VEX/priv/main/vex_main.c
VEX/pub/libvex_basictypes.h

index 36d93a6933f08da8a51cf091db826a61a7158657..78b4fd109097cefbb35a1bff890a7d7bf33a4073 100644 (file)
@@ -150,6 +150,9 @@ void LibVEX_Init (
    vassert(sizeof(void*) == sizeof(int*));
    vassert(sizeof(void*) == sizeof(HWord));
 
+   vassert(VEX_HOST_WORDSIZE == sizeof(void*));
+   vassert(VEX_HOST_WORDSIZE == sizeof(HWord));
+
    /* Really start up .. */
    vex_debuglevel         = debuglevel;
    vex_valgrind_support   = valgrind_support;
index 858c0c3199c8385b318d8e455a64692617e84311..54587399d002f8f724b9fc67a7cdfa9d4a96ab5c 100644 (file)
@@ -94,8 +94,48 @@ typedef  unsigned long HWord;
 #define offsetof(type,memb) ((Int)&((type*)0)->memb)
 
 
-#endif /* ndef __LIBVEX_BASICTYPES_H */
+/* We need to know the host word size in order to write Ptr_to_ULong
+   and ULong_to_Ptr in a way that doesn't cause compilers to complain.
+   These functions allow us to case pointers to and from 64-bit
+   integers without complaints from compilers, regardless of the host
+   word size. */
+
+#undef VEX_HOST_WORDSIZE
+
+#if defined(__amd64__)
+#   define VEX_HOST_WORDSIZE 8
+#elif defined(__i386__)
+#   define VEX_HOST_WORDSIZE 4
+#elif defined (__powerpc__)
+    /* need to distinguish ppc32 from ppc64 */
+#   define VEX_HOST_WORDSIZE 4
+#else
+#   error "Vex: Fatal: Can't establish the host architecture"
+#endif
+
+
+#if VEX_HOST_WORDSIZE == 8
+   static inline ULong Ptr_to_ULong ( void* p ) {
+      return (ULong)p;
+   }
+   static inline void* ULong_to_Ptr ( ULong n ) {
+      return (void*)n;
+   }
+#elif VEX_HOST_WORDSIZE == 4
+   static inline ULong Ptr_to_ULong ( void* p ) {
+      UInt w = (UInt)p;
+      return (ULong)w;
+   }
+   static inline void* ULong_to_Ptr ( ULong n ) {
+      UInt w = (UInt)n;
+      return (void*)w;
+   }
+#else
+#   error "Vex: Fatal: Can't define  Ptr_to_ULong / ULong_to_Ptr"
+#endif
+
 
+#endif /* ndef __LIBVEX_BASICTYPES_H */
 
 /*---------------------------------------------------------------*/
 /*---                                     libvex_basictypes.h ---*/