| 1 |
The compiler error is:
|
| 2 |
/usr/include/bluetooth/bluetooth.h::131:9: error: invalid conversion from 'void*' to 'bt_get_le64(void*)::<anonymous struct>*'
|
| 3 |
...
|
| 4 |
|
| 5 |
The reason is that C++, in contrast to C, does not allow conversion of
|
| 6 |
void * to anything, and this code gets compiled as C++ when the app is
|
| 7 |
written in C++. The macro with the assignment itself is older, but only
|
| 8 |
recent Bluez starts to use it in inline functions, thus triggering the
|
| 9 |
problem.
|
| 10 |
|
| 11 |
This patch keeps the "struct __attribute__((packed))" magic and merely
|
| 12 |
changes the typecast so that it works in C and C++. Like the existing
|
| 13 |
macro this patch relies on support for typeof.
|
| 14 |
|
| 15 |
The new variant of the code is in an ifdef and only used for C++
|
| 16 |
to avoid unexpected regressions in C applications.
|
| 17 |
|
| 18 |
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
|
| 19 |
---
|
| 20 |
lib/bluetooth.h | 30 ++++++++++++++++++++++++++++++
|
| 21 |
1 files changed, 30 insertions(+), 0 deletions(-)
|
| 22 |
|
| 23 |
Index: bluez-4.98/lib/bluetooth.h
|
| 24 |
===================================================================
|
| 25 |
--- bluez-4.98.orig/lib/bluetooth.h 2012-02-05 13:20:23.753659182 +0100
|
| 26 |
+++ bluez-4.98/lib/bluetooth.h 2012-02-05 13:26:33.905473976 +0100
|
| 27 |
@@ -109,6 +109,12 @@
|
| 28 |
#endif
|
| 29 |
|
| 30 |
/* Bluetooth unaligned access */
|
| 31 |
+#ifndef __cplusplus
|
| 32 |
+/*
|
| 33 |
+ * traditional code, doesn't work in C++ because
|
| 34 |
+ * of the void * to struct pointer assignment
|
| 35 |
+ */
|
| 36 |
+
|
| 37 |
#define bt_get_unaligned(ptr) \
|
| 38 |
({ \
|
| 39 |
struct __attribute__((packed)) { \
|
| 40 |
@@ -125,6 +131,31 @@
|
| 41 |
__p->__v = (val); \
|
| 42 |
} while(0)
|
| 43 |
|
| 44 |
+#else /* __cplusplus */
|
| 45 |
+
|
| 46 |
+/*
|
| 47 |
+ * modified code with typeof typecast, for C++;
|
| 48 |
+ * the traditional code continues to be used for
|
| 49 |
+ * C to avoid unexpected regressions with this
|
| 50 |
+ * code here (it should work in C and C++, though)
|
| 51 |
+ */
|
| 52 |
+#define bt_get_unaligned(ptr) \
|
| 53 |
+({ \
|
| 54 |
+ struct __attribute__((packed)) { \
|
| 55 |
+ typeof(*(ptr)) __v; \
|
| 56 |
+ } *__p = (typeof(__p)) (ptr); \
|
| 57 |
+ __p->__v; \
|
| 58 |
+})
|
| 59 |
+
|
| 60 |
+#define bt_put_unaligned(val, ptr) \
|
| 61 |
+do { \
|
| 62 |
+ struct __attribute__((packed)) { \
|
| 63 |
+ typeof(*(ptr)) __v; \
|
| 64 |
+ } *__p = (typeof(__p)) (ptr); \
|
| 65 |
+ __p->__v = (val); \
|
| 66 |
+} while(0)
|
| 67 |
+#endif /* __cplusplus */
|
| 68 |
+
|
| 69 |
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
| 70 |
static inline uint64_t bt_get_le64(void *ptr)
|
| 71 |
{ |