aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xquartz/xpr/x-hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/xquartz/xpr/x-hash.h')
-rw-r--r--xorg-server/hw/xquartz/xpr/x-hash.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/xorg-server/hw/xquartz/xpr/x-hash.h b/xorg-server/hw/xquartz/xpr/x-hash.h
index 3456dbedf..78bc7b317 100644
--- a/xorg-server/hw/xquartz/xpr/x-hash.h
+++ b/xorg-server/hw/xquartz/xpr/x-hash.h
@@ -30,6 +30,9 @@
#ifndef X_HASH_H
#define X_HASH_H 1
+#include <stdlib.h>
+#include <assert.h>
+
typedef struct x_hash_table_struct x_hash_table;
typedef int (x_compare_fun) (const void *a, const void *b);
@@ -57,4 +60,32 @@ X_EXTERN void X_PFX (hash_table_foreach) (x_hash_table *h,
x_hash_foreach_fun *fun,
void *data);
+/* Conversion between unsigned int (e.g. xp_resource_id) and void pointer */
+
+/* Forward declarations */
+static __inline__ void *
+X_PFX (cvt_uint_to_vptr) (unsigned int val) __attribute__((always_inline));
+static __inline__ unsigned int
+X_PFX (cvt_vptr_to_uint) (void * val) __attribute__((always_inline));
+
+/* Implementations */
+static __inline__ void *
+X_PFX (cvt_uint_to_vptr) (unsigned int val)
+{
+ return (void*)((size_t)(val));
+}
+
+static __inline__ unsigned int
+X_PFX (cvt_vptr_to_uint) (void * val)
+{
+ size_t sv = (size_t)val;
+ unsigned int uv = (unsigned int)sv;
+
+ /* If this assert fails, chances are val actually is a pointer,
+ or there's been memory corruption */
+ assert(sv == uv);
+
+ return uv;
+}
+
#endif /* X_HASH_H */