diff --git a/mbed-client-libservice/ns_list.h b/mbed-client-libservice/ns_list.h index 090cecefa5..0030d56dea 100644 --- a/mbed-client-libservice/ns_list.h +++ b/mbed-client-libservice/ns_list.h @@ -96,6 +96,9 @@ typedef struct ns_list { * always assign returned entry pointers to a properly typed pointer variable. * This assignment will be then type-checked where the compiler supports it, and * will dereference correctly on compilers that don't support this extension. + * + * If you need to support C++03 compilers that cannot return properly-typed + * pointers, such as IAR 7, you need to use NS_LIST_TYPECOERCE to force the type. * ~~~ * NS_LIST_HEAD(example_entry_t, link) my_list; * @@ -199,6 +202,27 @@ union \ #define NS_LIST_TYPECAST_(list, val) (0 ? (list)->type : (val)) #endif +/** \brief Macro to force correct type if necessary. + * + * In C, doesn't matter if NS_LIST_TYPECAST_ works or not, as it's legal + * to assign void * to a pointer. In C++, we can't do that, so need + * a back-up plan for C++03. This forces the type, so breaks type-safety - + * only activate when needed, meaning we still get typechecks on other + * toolchains. + * + * If a straight assignment of a ns_list function to a pointer fails + * on a C++03 compiler, use the following construct. This will not be + * required with C++11 compilers. + * ~~~ + * type *elem = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list)); + * ~~~ + */ +#if defined(NS_LIST_PTR_TYPE_) || !defined(__cplusplus) +#define NS_LIST_TYPECOERCE(type, val) (val) +#else +#define NS_LIST_TYPECOERCE(type, val) (type) (val) +#endif + /** \brief Internal macro to check types of input entry pointer. */ #define NS_LIST_TYPECHECK_(list, entry) \ (NS_PTR_MATCH_((list)->type, (entry), "incorrect entry type for list"), (entry)) @@ -480,7 +504,8 @@ typedef struct ns_list_link { * \param list `(const list_t *)` Pointer to list - evaluated multiple times. */ #define ns_list_foreach(type, e, list) \ - for (type *e = ns_list_get_first(list); e; e = ns_list_get_next(list, e)) + for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list)); \ + e; e = NS_LIST_TYPECOERCE(type *, ns_list_get_next(list, e))) /** \brief Iterate forwards over a list, where user may delete. * @@ -500,8 +525,8 @@ typedef struct ns_list_link { * \param list `(list_t *)` Pointer to list - evaluated multiple times. */ #define ns_list_foreach_safe(type, e, list) \ - for (type *e = ns_list_get_first(list), *_next##e; \ - e && (_next##e = ns_list_get_next(list, e), true); e = _next##e) + for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list)), *_next##e; \ + e && (_next##e = NS_LIST_TYPECOERCE(type *, ns_list_get_next(list, e)), true); e = _next##e) /** \brief Iterate backwards over a list. * @@ -509,7 +534,8 @@ typedef struct ns_list_link { * Iterating forwards is *slightly* more efficient. */ #define ns_list_foreach_reverse(type, e, list) \ - for (type *e = ns_list_get_last(list); e; e = ns_list_get_previous(list, e)) + for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_last(list)); \ + e; e = NS_LIST_TYPECOERCE(type *, ns_list_get_previous(list, e))) /** \brief Iterate backwards over a list, where user may delete. * @@ -517,8 +543,8 @@ typedef struct ns_list_link { * Iterating forwards is *slightly* more efficient. */ #define ns_list_foreach_reverse_safe(type, e, list) \ - for (type *e = ns_list_get_last(list), *_next##e; \ - e && (_next##e = ns_list_get_previous(list, e), true); e = _next##e) + for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_last(list)), *_next##e; \ + e && (_next##e = NS_LIST_TYPECOERCE(type *, ns_list_get_previous(list, e)), true); e = _next##e) /** \hideinitializer \brief Count entries on a list * diff --git a/mbed-client-libservice/ns_types.h b/mbed-client-libservice/ns_types.h index f9b7815b26..bbb28dd369 100644 --- a/mbed-client-libservice/ns_types.h +++ b/mbed-client-libservice/ns_types.h @@ -121,7 +121,15 @@ typedef int_fast32_t int_fast24_t; #define alignas(n) __align(n) #define __alignas_is_defined 1 #elif (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L) -#include +# if defined __ARMCC_VERSION && __ARMCC_VERSION < 6120000 +/* Workaround for Arm Compiler versions prior to 6.12 */ +# if !defined __cplusplus +# define alignas _Alignas +# endif +# define __alignas_is_defined 1 +# else +# include +# endif #elif defined __GNUC__ #define alignas(n) __attribute__((__aligned__(n))) #define __alignas_is_defined 1 diff --git a/mbed_lib.json b/mbed_lib.json new file mode 100644 index 0000000000..75957496a9 --- /dev/null +++ b/mbed_lib.json @@ -0,0 +1,3 @@ +{ + "name": "nanostack-libservice" +} diff --git a/module.json b/module.json deleted file mode 100644 index a7233e766f..0000000000 --- a/module.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "nanostack-libservice", - "version": "3.6.0", - "description": "Helper libraries for mbed-client and 6LoWPAN stack.", - "keywords": [ - "libservice" - ], - "author": "Seppo Takalo ", - "homepage": "https://github.com/ARMmbed/mbed-client-libservice", - "license": "Apache-2.0", - "extraIncludes": [ - "mbed-client-libservice" - ], - "dependencies": { - "mbed-trace": "ARMmbed/mbed-trace" - }, - "targetDependencies": {} -} diff --git a/source/libBits/common_functions.c b/source/libBits/common_functions.c index 67fe86ead8..2c4b8f3f94 100644 --- a/source/libBits/common_functions.c +++ b/source/libBits/common_functions.c @@ -35,7 +35,7 @@ bool bitsequal(const uint8_t *a, const uint8_t *b, uint_fast8_t bits) uint_fast8_t bytes = bits / 8; bits %= 8; - if (memcmp(a, b, bytes)) { + if (bytes && memcmp(a, b, bytes)) { return false; } diff --git a/test/libService/unittest/stubs/mbed_trace_stub.c b/test/libService/unittest/stubs/mbed_trace_stub.c index d3458b2223..e762aee785 100644 --- a/test/libService/unittest/stubs/mbed_trace_stub.c +++ b/test/libService/unittest/stubs/mbed_trace_stub.c @@ -18,13 +18,13 @@ #include #include -#ifndef YOTTA_CFG_MBED_TRACE -#define YOTTA_CFG_MBED_TRACE 1 -#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1 +#ifndef MBED_CONF_MBED_TRACE_ENABLE +#define MBED_CONF_MBED_TRACE_ENABLE 1 +#define MBED_CONF_MBED_TRACE_FEA_IPV6 1 #endif #include "mbed-trace/mbed_trace.h" -#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1 +#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1 #include "mbed-client-libservice/ip6string.h" #include "mbed-client-libservice/common_functions.h" #endif @@ -101,7 +101,7 @@ const char *mbed_trace_last(void) } /* Helping functions */ -#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1 +#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1 char *mbed_trace_ipv6(const void *addr_ptr) { return NULL; @@ -111,7 +111,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len) { return NULL; } -#endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6 +#endif //MBED_CONF_MBED_TRACE_FEA_IPV6 char *mbed_trace_array(const uint8_t *buf, uint16_t len) {