[PATCH 2/2] Make U64_TO_POINTER and POINTER_TO_U64 endianness neutral.



This allows exchanging sysprof trace files between architectures of different
endianness.

Signed-off-by: Michel Dänzer <michel daenzer net>
---
 stackstash.h |   25 +++++++++++++++++++++++--
 1 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/stackstash.h b/stackstash.h
index 4fad001..2a40d55 100644
--- a/stackstash.h
+++ b/stackstash.h
@@ -27,8 +27,29 @@ typedef struct StackStash StackStash;
 typedef struct StackNode StackNode;
 typedef struct StackLink StackLink;
 
-#define U64_TO_POINTER(u)	((void *)(intptr_t)u)
-#define POINTER_TO_U64(p)	((uint64_t)(intptr_t)p)
+static inline void*
+U64_TO_POINTER(uint64_t u)
+{
+    intptr_t ip = u >> 32;
+
+    if (sizeof ip > 4)
+	ip |= u << 32;
+
+    return (void*)ip;
+}
+
+static inline uint64_t
+POINTER_TO_U64(const void *p)
+{
+    uintptr_t uip = (uintptr_t)p;
+    uint64_t u = (uint64_t)uip << 32;
+
+    if (sizeof uip > 4)
+	u |= (uint64_t)uip >> 32;
+
+    return u;
+}
+
 
 struct StackNode
 {
-- 
1.7.5.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]