Squashed 'features/frameworks/nanostack-libservice/' changes from 1d4c358..dd98c37

dd98c37 Merge pull request #85 from ARMmbed/sync_with_MbedOS
8418f4c (via Mbed OS) Add missing mbed_lib.json for frameworks and nanostack
eb0692e Merge pull request #84 from ARMmbed/nslist_iar7
7ce58bf Support C++03 compilers that cannot return properly-typed pointers.
2775dce Merge pull request #83 from ARMmbed/IOTTHD-3187
fef3c6d Remove references to yotta
a953636 Avoid memcmp(x, NULL, 0)
1de4b47 (split) Fix C++11 build with Arm Compiler 6 (#79)

git-subtree-dir: features/frameworks/nanostack-libservice
git-subtree-split: dd98c37c363acd0b6547ca59adc735ee52b2a7b1
pull/9838/head
Arto Kinnunen 2019-02-25 12:57:27 +02:00
parent 661681f65c
commit d53d1dffb7
6 changed files with 51 additions and 32 deletions

View File

@ -96,6 +96,9 @@ typedef struct ns_list {
* always assign returned entry pointers to a properly typed pointer variable. * always assign returned entry pointers to a properly typed pointer variable.
* This assignment will be then type-checked where the compiler supports it, and * This assignment will be then type-checked where the compiler supports it, and
* will dereference correctly on compilers that don't support this extension. * 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; * NS_LIST_HEAD(example_entry_t, link) my_list;
* *
@ -199,6 +202,27 @@ union \
#define NS_LIST_TYPECAST_(list, val) (0 ? (list)->type : (val)) #define NS_LIST_TYPECAST_(list, val) (0 ? (list)->type : (val))
#endif #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. */ /** \brief Internal macro to check types of input entry pointer. */
#define NS_LIST_TYPECHECK_(list, entry) \ #define NS_LIST_TYPECHECK_(list, entry) \
(NS_PTR_MATCH_((list)->type, (entry), "incorrect entry type for 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. * \param list `(const list_t *)` Pointer to list - evaluated multiple times.
*/ */
#define ns_list_foreach(type, e, list) \ #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. /** \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. * \param list `(list_t *)` Pointer to list - evaluated multiple times.
*/ */
#define ns_list_foreach_safe(type, e, list) \ #define ns_list_foreach_safe(type, e, list) \
for (type *e = ns_list_get_first(list), *_next##e; \ for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list)), *_next##e; \
e && (_next##e = ns_list_get_next(list, e), true); e = _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. /** \brief Iterate backwards over a list.
* *
@ -509,7 +534,8 @@ typedef struct ns_list_link {
* Iterating forwards is *slightly* more efficient. * Iterating forwards is *slightly* more efficient.
*/ */
#define ns_list_foreach_reverse(type, e, list) \ #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. /** \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. * Iterating forwards is *slightly* more efficient.
*/ */
#define ns_list_foreach_reverse_safe(type, e, list) \ #define ns_list_foreach_reverse_safe(type, e, list) \
for (type *e = ns_list_get_last(list), *_next##e; \ for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_last(list)), *_next##e; \
e && (_next##e = ns_list_get_previous(list, e), true); e = _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 /** \hideinitializer \brief Count entries on a list
* *

View File

@ -121,7 +121,15 @@ typedef int_fast32_t int_fast24_t;
#define alignas(n) __align(n) #define alignas(n) __align(n)
#define __alignas_is_defined 1 #define __alignas_is_defined 1
#elif (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L) #elif (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L)
# 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 <stdalign.h> # include <stdalign.h>
# endif
#elif defined __GNUC__ #elif defined __GNUC__
#define alignas(n) __attribute__((__aligned__(n))) #define alignas(n) __attribute__((__aligned__(n)))
#define __alignas_is_defined 1 #define __alignas_is_defined 1

3
mbed_lib.json Normal file
View File

@ -0,0 +1,3 @@
{
"name": "nanostack-libservice"
}

View File

@ -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 <seppo.takalo@arm.com>",
"homepage": "https://github.com/ARMmbed/mbed-client-libservice",
"license": "Apache-2.0",
"extraIncludes": [
"mbed-client-libservice"
],
"dependencies": {
"mbed-trace": "ARMmbed/mbed-trace"
},
"targetDependencies": {}
}

View File

@ -35,7 +35,7 @@ bool bitsequal(const uint8_t *a, const uint8_t *b, uint_fast8_t bits)
uint_fast8_t bytes = bits / 8; uint_fast8_t bytes = bits / 8;
bits %= 8; bits %= 8;
if (memcmp(a, b, bytes)) { if (bytes && memcmp(a, b, bytes)) {
return false; return false;
} }

View File

@ -18,13 +18,13 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#ifndef YOTTA_CFG_MBED_TRACE #ifndef MBED_CONF_MBED_TRACE_ENABLE
#define YOTTA_CFG_MBED_TRACE 1 #define MBED_CONF_MBED_TRACE_ENABLE 1
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1 #define MBED_CONF_MBED_TRACE_FEA_IPV6 1
#endif #endif
#include "mbed-trace/mbed_trace.h" #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/ip6string.h"
#include "mbed-client-libservice/common_functions.h" #include "mbed-client-libservice/common_functions.h"
#endif #endif
@ -101,7 +101,7 @@ const char *mbed_trace_last(void)
} }
/* Helping functions */ /* 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) char *mbed_trace_ipv6(const void *addr_ptr)
{ {
return NULL; return NULL;
@ -111,7 +111,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
{ {
return NULL; 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) char *mbed_trace_array(const uint8_t *buf, uint16_t len)
{ {