Skip to content

Commit

Permalink
Merge commit '661681f65c3fb61aec2e4605bef0fc075cc8cb0d' into mbedos511
Browse files Browse the repository at this point in the history
* commit '661681f65c3fb61aec2e4605bef0fc075cc8cb0d':
  Squashed 'features/frameworks/nanostack-libservice/' changes from bb56e37..1d4c358
  • Loading branch information
Arto Kinnunen committed Nov 10, 2018
2 parents e1ef0e4 + 661681f commit 923ce13
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ extern "C" {
typedef struct ns_list {
void *first_entry; ///< Pointer to first entry, or NULL if list is empty
void **last_nextptr; ///< Pointer to last entry's `next` pointer, or
///< to head's `first_entry` pointer if list is empty
///< to head's `first_entry` pointer if list is empty
} ns_list_t;

/** \brief Declare a list head type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,17 @@ typedef int_fast32_t int_fast24_t;
# define NS_STATIC_ASSERT(test, str) _Static_assert(test, str);
# elif defined __GNUC__ && NS_GCC_VERSION >= 40600 && !defined __CC_ARM
# ifdef _Static_assert
/*
* Some versions of glibc cdefs.h (which comes in via <stdint.h> above)
* attempt to define their own _Static_assert (if GCC < 4.6 or
* __STRICT_ANSI__) using an extern declaration, which doesn't work in a
* struct/union.
*
* For GCC >= 4.6 and __STRICT_ANSI__, we can do better - just use
* the built-in _Static_assert with __extension__. We have to do this, as
* ns_list.h needs to use it in a union. No way to get at it though, without
* overriding their define.
*/
/*
* Some versions of glibc cdefs.h (which comes in via <stdint.h> above)
* attempt to define their own _Static_assert (if GCC < 4.6 or
* __STRICT_ANSI__) using an extern declaration, which doesn't work in a
* struct/union.
*
* For GCC >= 4.6 and __STRICT_ANSI__, we can do better - just use
* the built-in _Static_assert with __extension__. We have to do this, as
* ns_list.h needs to use it in a union. No way to get at it though, without
* overriding their define.
*/
# undef _Static_assert
# define _Static_assert(x, y) __extension__ _Static_assert(x, y)
# endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ uint_fast8_t ip4tos(const void *ip4addr, char *p)
//Append a dot if this is not the last digit
if (component < 3) {
p[outputPos++] = '.';
}
}
}

// Return length of generated string, excluding the terminating null character
Expand All @@ -59,7 +59,7 @@ static void ipv4_itoa(char *string, uint8_t byte)
do {
*string++ = '0' + byte % 10;
byte /= 10;
} while(byte);
} while (byte);

//We put the final \0, then go back one step on the last digit for the swap
*string-- = '\0';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ bool stoip6(const char *ip6addr, size_t len, void *dest)
coloncolon = field_no;
q++;
len -= 2;
}
else {
} else {
len -= 1;
}
}
Expand Down Expand Up @@ -150,11 +149,13 @@ int stoip6_prefix(const char *ip6addr, void *dest, int_fast16_t *prefix_len_out)
static bool is_hex(char c)
{
// 'A' (0x41) and 'a' (0x61) are mapped in the ASCII table in such a way that masking the 0x20 bit turn 'a' in 'A'
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F')
if ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F') {
return true;
}

if (c >= '0' && c <= '9')
if (c >= '0' && c <= '9') {
return true;
}

return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const mem_stat_t *ns_dyn_mem_get_mem_stat(void)


ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
void (*passed_fptr)(heap_fail_t),
mem_stat_t *info_ptr)
void (*passed_fptr)(heap_fail_t),
mem_stat_t *info_ptr)
{
#ifndef STANDARD_MALLOC
ns_mem_book_t *book;
Expand All @@ -108,7 +108,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
h_size -= (sizeof(ns_mem_word_size_t) - temp_int);
}
book = heap;
book->heap_main = (ns_mem_word_size_t *)&(book[1]); // SET Heap Pointer
book->heap_main = (ns_mem_word_size_t *) & (book[1]); // SET Heap Pointer
book->heap_size = h_size - sizeof(ns_mem_book_t); //Set Heap Size
temp_int = (book->heap_size / sizeof(ns_mem_word_size_t));
temp_int -= 2;
Expand All @@ -127,7 +127,7 @@ ns_mem_book_t *ns_mem_init(void *heap, ns_mem_heap_size_t h_size,
memset(book->mem_stat_info_ptr, 0, sizeof(mem_stat_t));
book->mem_stat_info_ptr->heap_sector_size = book->heap_size;
}
book->temporary_alloc_heap_limit = book->heap_size/100 * (100-TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
book->temporary_alloc_heap_limit = book->heap_size / 100 * (100 - TEMPORARY_ALLOC_FREE_HEAP_THRESHOLD);
#endif
//There really is no support to standard malloc in this library anymore
book->heap_failure_callback = passed_fptr;
Expand All @@ -154,12 +154,12 @@ int ns_mem_set_temporary_alloc_free_heap_threshold(ns_mem_book_t *book, uint8_t
return -1;
}

if (free_heap_amount && free_heap_amount < book->heap_size/2) {
if (free_heap_amount && free_heap_amount < book->heap_size / 2) {
heap_limit = book->heap_size - free_heap_amount;
}

if (!free_heap_amount && free_heap_percentage && free_heap_percentage < 50) {
heap_limit = book->heap_size/100 * (100 - free_heap_percentage);
heap_limit = book->heap_size / 100 * (100 - free_heap_percentage);
}

if (free_heap_amount == 0 && free_heap_percentage == 0) {
Expand Down Expand Up @@ -215,7 +215,7 @@ static ns_mem_word_size_t convert_allocation_size(ns_mem_book_t *book, ns_mem_bl
heap_failure(book, NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED);
} else if (requested_bytes < 1) {
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t)) ) {
} else if (requested_bytes > (book->heap_size - 2 * sizeof(ns_mem_word_size_t))) {
heap_failure(book, NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID);
}
return (requested_bytes + sizeof(ns_mem_word_size_t) - 1) / sizeof(ns_mem_word_size_t);
Expand Down Expand Up @@ -266,10 +266,10 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_

// ns_list_foreach, either forwards or backwards, result to ptr
for (hole_t *cur_hole = direction > 0 ? ns_list_get_first(&book->holes_list)
: ns_list_get_last(&book->holes_list);
cur_hole;
cur_hole = direction > 0 ? ns_list_get_next(&book->holes_list, cur_hole)
: ns_list_get_previous(&book->holes_list, cur_hole)
: ns_list_get_last(&book->holes_list);
cur_hole;
cur_hole = direction > 0 ? ns_list_get_next(&book->holes_list, cur_hole)
: ns_list_get_previous(&book->holes_list, cur_hole)
) {
ns_mem_word_size_t *p = block_start_from_hole(cur_hole);
if (ns_mem_block_validate(p) != 0 || *p >= 0) {
Expand All @@ -295,7 +295,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
ns_mem_word_size_t hole_size = block_data_size - data_size - 2;
ns_mem_word_size_t *hole_ptr;
//There is enough room for a new hole so create it first
if ( direction > 0 ) {
if (direction > 0) {
hole_ptr = block_ptr + 1 + data_size + 1;
// Hole will be left at end of area.
// Would like to just replace this block_ptr with new descriptor, but
Expand Down Expand Up @@ -324,7 +324,7 @@ static void *ns_mem_internal_alloc(ns_mem_book_t *book, const ns_mem_block_size_
block_ptr[0] = data_size;
block_ptr[1 + data_size] = data_size;

done:
done:
if (book->mem_stat_info_ptr) {
if (block_ptr) {
//Update Allocate OK
Expand Down Expand Up @@ -433,7 +433,7 @@ static void ns_mem_free_and_merge_with_adjacent_blocks(ns_mem_book_t *book, ns_m
} else {
// Didn't find adjacent descriptors, but may still
// be merging with small blocks without descriptors.
if ( merged_data_size >= HOLE_T_SIZE ) {
if (merged_data_size >= HOLE_T_SIZE) {
// Locate hole position in list, if we don't already know
// from merging with the block above.
if (!existing_end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static NS_LIST_DEFINE(ns_nvm_request_list, ns_nvm_request_t, link);
*/
void ns_nvm_callback_func(platform_nvm_status status, void *args)
{
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t*)args;
ns_nvm_request_t *ns_nvm_request_ptr = (ns_nvm_request_t *)args;
int client_retval = NS_NVM_OK;

if (status == PLATFORM_NVM_ERROR) {
Expand All @@ -69,7 +69,7 @@ void ns_nvm_callback_func(platform_nvm_status status, void *args)
client_retval = NS_NVM_DATA_NOT_FOUND;
}

switch(ns_nvm_request_ptr->operation) {
switch (ns_nvm_request_ptr->operation) {
case NS_NVM_INIT:
ns_nvm_operation_continue(ns_nvm_request_ptr->original_request, true);
ns_dyn_mem_free(ns_nvm_request_ptr);
Expand Down Expand Up @@ -185,7 +185,7 @@ static int ns_nvm_operation_continue(ns_nvm_request_t *request, bool free_reques
platform_nvm_status ret = PLATFORM_NVM_OK;

ns_nvm_operation_in_progress = true;
switch(request->operation) {
switch (request->operation) {
case NS_NVM_KEY_WRITE:
request->operation = NS_NVM_KEY_CREATE;
ret = platform_nvm_key_create(ns_nvm_callback_func, request->client_key_name, *request->buffer_len, 0, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ TEST(ip6tos, ip6_prefix_tos_func)
/***********************************************************/
/* Second test group for the old tests that were once lost */

const char string_addr[][40] =
{
const char string_addr[][40] = {
"2001:db8::1:0:0:1", // 1
"2001:db8:aaaa:bbbb:cccc:dddd:eeee:1", // 2
"2001:db8::1", // 3
Expand All @@ -81,34 +80,31 @@ const char string_addr[][40] =
};


const uint8_t hex_addr[][16] =
{
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 },
const uint8_t hex_addr[][16] = {
{ 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
{ 0x20, 0x01, 0xd, 0xb8, 0xaa, 0xaa, 0xbb, 0xbb, 0xcc, 0xcc, 0xdd, 0xdd, 0xee, 0xee, 0x00, 0x01 },
{ 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,0,0,0,0,0,0,1 },
{ 0x20, 0x01, 0xd,0xb8, 0,0,0,0,0,0,0,0, 0,2,0,1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{
i++;
}
};
Expand Down
Loading

0 comments on commit 923ce13

Please sign in to comment.