Module: xenomai-forge
Branch: next
Commit: 28221054cfb21b0c1a988b0fa972432ab85d848d
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=28221054cfb21b0c1a988b0fa972432ab85d848d
Author: Philippe Gerum
Date: Mon May 5 09:28:54 2014 +0200
copperplate/heapobj: check sanity of ref-types at build time (C only)
---
include/copperplate/heapobj.h | 21 +++--
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/include/copperplate/heapobj.h b/include/copperplate/heapobj.h
index 38deb89..6b5617c 100644
--- a/include/copperplate/heapobj.h
+++ b/include/copperplate/heapobj.h
@@ -324,21 +324,30 @@ static inline int pshared_check(void *heap, void *addr)
return 0;
}
+#ifdef __cplusplus
+#define __check_ref_width(__dst, __src)\
+ ({ \
+ assert(sizeof(__dst) >= sizeof(__src)); \
+ (typeof(__dst))__src; \
+ })
+#else
+#define __check_ref_width(__dst, __src)
\
+ __builtin_choose_expr( \
+ sizeof(__dst) >= sizeof(__src), (typeof(__dst))__src, \
+ ((void)0))
+#endif
+
#define mainheap_ref(ptr, type)
\
({ \
type handle;\
- assert(__builtin_types_compatible_p(typeof(type), unsigned
long) || \
- __builtin_types_compatible_p(typeof(type), uintptr_t)); \
+ handle = __check_ref_width(handle, ptr);\
assert(ptr == NULL || __memchk(__main_heap, ptr)); \
- handle = (type)ptr; \
handle; \
})
#define mainheap_deref(handle, type) \
({ \
type *ptr; \
- assert(__builtin_types_compatible_p(typeof(handle), unsigned
long) || \
- __builtin_types_compatible_p(typeof(handle),
uintptr_t)); \
- ptr = (type *)handle; \
+ ptr = __check_ref_width(ptr, handle); \
ptr;\
})
___
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git