Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code style fixes for nanoframework/nf-interpreter PR#2634 #2638

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions targets/ChibiOS/_common/platform_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include <ch.h>
#include <chmemheaps.h> // Required for platform_realloc heap_header
#include <string.h> // Required for platform_realloc memcpy
//#include <nanoHAL_v2.h> // Not required as we are fully using the platform specific implementation.
#include <string.h> // Required for platform_realloc memcpy
// #include <nanoHAL_v2.h> // Not required as we are fully using the platform specific implementation.

void *platform_malloc(size_t size)
{
Expand All @@ -15,19 +15,21 @@ void *platform_malloc(size_t size)

void platform_free(void *ptr)
{
if (ptr) {
if (ptr)
{
chHeapFree(ptr);
}
}

void *platform_realloc(void *ptr, size_t size) //ptr is the memory address
void *platform_realloc(void *ptr, size_t size) // ptr is the memory address
{
union heap_header *hp;
uint32_t prev_size, new_size;

void *new_ptr;

if(ptr == NULL) {
if (ptr == NULL)
{
return chHeapAlloc(NULL, size);
}

Expand All @@ -36,19 +38,23 @@ void *platform_realloc(void *ptr, size_t size) //ptr is the memory address
prev_size = hp->used.size; /* size is always multiple of 8 */

/* check new size memory alignment */
if(size % 8 == 0) {
if (size % 8 == 0)
{
new_size = size;
}
else {
new_size = ((int) (size / 8)) * 8 + 8;
else
{
new_size = ((int)(size / 8)) * 8 + 8;
}

if(prev_size >= new_size) {
if (prev_size >= new_size)
{
return ptr;
}

ptr = chHeapAlloc(NULL, size);
if(new_ptr == NULL) {
if (new_ptr == NULL)
{
return NULL;
}

Expand Down