Skip to content

Commit

Permalink
Squashed 'features/frameworks/nanostack-libservice/' changes from 1d4…
Browse files Browse the repository at this point in the history
…c358..dd98c37

dd98c37 Merge pull request ARMmbed#85 from ARMmbed/sync_with_MbedOS
8418f4c (via Mbed OS) Add missing mbed_lib.json for frameworks and nanostack
eb0692e Merge pull request ARMmbed#84 from ARMmbed/nslist_iar7
7ce58bf Support C++03 compilers that cannot return properly-typed pointers.
2775dce Merge pull request ARMmbed#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 (ARMmbed#79)

git-subtree-dir: features/frameworks/nanostack-libservice
git-subtree-split: dd98c37c363acd0b6547ca59adc735ee52b2a7b1
  • Loading branch information
Arto Kinnunen committed Feb 25, 2019
1 parent 661681f commit d53d1df
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 32 deletions.
38 changes: 32 additions & 6 deletions mbed-client-libservice/ns_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
*
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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.
*
Expand All @@ -500,25 +525,26 @@ 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.
*
* As ns_list_foreach(), but going backwards - see its documentation.
* 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.
*
* As ns_list_foreach_safe(), but going backwards - see its documentation.
* 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
*
Expand Down
10 changes: 9 additions & 1 deletion mbed-client-libservice/ns_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdalign.h>
# 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>
# endif
#elif defined __GNUC__
#define alignas(n) __attribute__((__aligned__(n)))
#define __alignas_is_defined 1
Expand Down
3 changes: 3 additions & 0 deletions mbed_lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "nanostack-libservice"
}
18 changes: 0 additions & 18 deletions module.json

This file was deleted.

2 changes: 1 addition & 1 deletion source/libBits/common_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 6 additions & 6 deletions test/libService/unittest/stubs/mbed_trace_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#include <stdarg.h>
#include <stdlib.h>

#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
Expand Down Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down

0 comments on commit d53d1df

Please sign in to comment.