Skip to content

Commit d53d1df

Browse files
author
Arto Kinnunen
committed
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
1 parent 661681f commit d53d1df

File tree

6 files changed

+51
-32
lines changed

6 files changed

+51
-32
lines changed

mbed-client-libservice/ns_list.h

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ typedef struct ns_list {
9696
* always assign returned entry pointers to a properly typed pointer variable.
9797
* This assignment will be then type-checked where the compiler supports it, and
9898
* will dereference correctly on compilers that don't support this extension.
99+
*
100+
* If you need to support C++03 compilers that cannot return properly-typed
101+
* pointers, such as IAR 7, you need to use NS_LIST_TYPECOERCE to force the type.
99102
* ~~~
100103
* NS_LIST_HEAD(example_entry_t, link) my_list;
101104
*
@@ -199,6 +202,27 @@ union \
199202
#define NS_LIST_TYPECAST_(list, val) (0 ? (list)->type : (val))
200203
#endif
201204

205+
/** \brief Macro to force correct type if necessary.
206+
*
207+
* In C, doesn't matter if NS_LIST_TYPECAST_ works or not, as it's legal
208+
* to assign void * to a pointer. In C++, we can't do that, so need
209+
* a back-up plan for C++03. This forces the type, so breaks type-safety -
210+
* only activate when needed, meaning we still get typechecks on other
211+
* toolchains.
212+
*
213+
* If a straight assignment of a ns_list function to a pointer fails
214+
* on a C++03 compiler, use the following construct. This will not be
215+
* required with C++11 compilers.
216+
* ~~~
217+
* type *elem = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list));
218+
* ~~~
219+
*/
220+
#if defined(NS_LIST_PTR_TYPE_) || !defined(__cplusplus)
221+
#define NS_LIST_TYPECOERCE(type, val) (val)
222+
#else
223+
#define NS_LIST_TYPECOERCE(type, val) (type) (val)
224+
#endif
225+
202226
/** \brief Internal macro to check types of input entry pointer. */
203227
#define NS_LIST_TYPECHECK_(list, entry) \
204228
(NS_PTR_MATCH_((list)->type, (entry), "incorrect entry type for list"), (entry))
@@ -480,7 +504,8 @@ typedef struct ns_list_link {
480504
* \param list `(const list_t *)` Pointer to list - evaluated multiple times.
481505
*/
482506
#define ns_list_foreach(type, e, list) \
483-
for (type *e = ns_list_get_first(list); e; e = ns_list_get_next(list, e))
507+
for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list)); \
508+
e; e = NS_LIST_TYPECOERCE(type *, ns_list_get_next(list, e)))
484509

485510
/** \brief Iterate forwards over a list, where user may delete.
486511
*
@@ -500,25 +525,26 @@ typedef struct ns_list_link {
500525
* \param list `(list_t *)` Pointer to list - evaluated multiple times.
501526
*/
502527
#define ns_list_foreach_safe(type, e, list) \
503-
for (type *e = ns_list_get_first(list), *_next##e; \
504-
e && (_next##e = ns_list_get_next(list, e), true); e = _next##e)
528+
for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_first(list)), *_next##e; \
529+
e && (_next##e = NS_LIST_TYPECOERCE(type *, ns_list_get_next(list, e)), true); e = _next##e)
505530

506531
/** \brief Iterate backwards over a list.
507532
*
508533
* As ns_list_foreach(), but going backwards - see its documentation.
509534
* Iterating forwards is *slightly* more efficient.
510535
*/
511536
#define ns_list_foreach_reverse(type, e, list) \
512-
for (type *e = ns_list_get_last(list); e; e = ns_list_get_previous(list, e))
537+
for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_last(list)); \
538+
e; e = NS_LIST_TYPECOERCE(type *, ns_list_get_previous(list, e)))
513539

514540
/** \brief Iterate backwards over a list, where user may delete.
515541
*
516542
* As ns_list_foreach_safe(), but going backwards - see its documentation.
517543
* Iterating forwards is *slightly* more efficient.
518544
*/
519545
#define ns_list_foreach_reverse_safe(type, e, list) \
520-
for (type *e = ns_list_get_last(list), *_next##e; \
521-
e && (_next##e = ns_list_get_previous(list, e), true); e = _next##e)
546+
for (type *e = NS_LIST_TYPECOERCE(type *, ns_list_get_last(list)), *_next##e; \
547+
e && (_next##e = NS_LIST_TYPECOERCE(type *, ns_list_get_previous(list, e)), true); e = _next##e)
522548

523549
/** \hideinitializer \brief Count entries on a list
524550
*

mbed-client-libservice/ns_types.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ typedef int_fast32_t int_fast24_t;
121121
#define alignas(n) __align(n)
122122
#define __alignas_is_defined 1
123123
#elif (defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L) || (defined __cplusplus && __cplusplus >= 201103L)
124-
#include <stdalign.h>
124+
# if defined __ARMCC_VERSION && __ARMCC_VERSION < 6120000
125+
/* Workaround for Arm Compiler versions prior to 6.12 */
126+
# if !defined __cplusplus
127+
# define alignas _Alignas
128+
# endif
129+
# define __alignas_is_defined 1
130+
# else
131+
# include <stdalign.h>
132+
# endif
125133
#elif defined __GNUC__
126134
#define alignas(n) __attribute__((__aligned__(n)))
127135
#define __alignas_is_defined 1

mbed_lib.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "nanostack-libservice"
3+
}

module.json

Lines changed: 0 additions & 18 deletions
This file was deleted.

source/libBits/common_functions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool bitsequal(const uint8_t *a, const uint8_t *b, uint_fast8_t bits)
3535
uint_fast8_t bytes = bits / 8;
3636
bits %= 8;
3737

38-
if (memcmp(a, b, bytes)) {
38+
if (bytes && memcmp(a, b, bytes)) {
3939
return false;
4040
}
4141

test/libService/unittest/stubs/mbed_trace_stub.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#include <stdarg.h>
1919
#include <stdlib.h>
2020

21-
#ifndef YOTTA_CFG_MBED_TRACE
22-
#define YOTTA_CFG_MBED_TRACE 1
23-
#define YOTTA_CFG_MBED_TRACE_FEA_IPV6 1
21+
#ifndef MBED_CONF_MBED_TRACE_ENABLE
22+
#define MBED_CONF_MBED_TRACE_ENABLE 1
23+
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
2424
#endif
2525

2626
#include "mbed-trace/mbed_trace.h"
27-
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
27+
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
2828
#include "mbed-client-libservice/ip6string.h"
2929
#include "mbed-client-libservice/common_functions.h"
3030
#endif
@@ -101,7 +101,7 @@ const char *mbed_trace_last(void)
101101
}
102102

103103
/* Helping functions */
104-
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
104+
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
105105
char *mbed_trace_ipv6(const void *addr_ptr)
106106
{
107107
return NULL;
@@ -111,7 +111,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
111111
{
112112
return NULL;
113113
}
114-
#endif //YOTTA_CFG_MBED_TRACE_FEA_IPV6
114+
#endif //MBED_CONF_MBED_TRACE_FEA_IPV6
115115

116116
char *mbed_trace_array(const uint8_t *buf, uint16_t len)
117117
{

0 commit comments

Comments
 (0)