Skip to content

Commit

Permalink
halc: fup
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Nov 17, 2024
1 parent bfc2a3f commit 020e939
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
19 changes: 10 additions & 9 deletions libraries/AP_HAL_ChibiOS/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void Util::free_type(void *ptr, size_t size, AP_HAL::Util::Memory_Type mem_type)
/*
heap functions used by lua scripting
*/
void *Util::allocate_heap_memory(uint32_t size)
void *Util::heap_create(uint32_t size)
{
memory_heap_t *heap = (memory_heap_t *)malloc(size + sizeof(memory_heap_t));
if (heap == nullptr) {
Expand All @@ -110,24 +110,25 @@ void *Util::allocate_heap_memory(uint32_t size)
return heap;
}

void Util::free_heap_memory(void *ptr)
void Util::heap_destroy(void *ptr)
{
memory_heap_t *heap = (memory_heap_t *)ptr;
free(ptr);
}

void *Util::heap_allocfree(void *heap, void *ptr, uint32_t new_size)
void *Util::heap_allocate(void *heap, uint32_t size)
{
if (heap == nullptr) {
return nullptr;
}
if (new_size == 0) {
if (ptr != nullptr) {
chHeapFree(ptr);
}
if (size == 0) {
return nullptr;
}
return chHeapAlloc((memory_heap_t *)heap, new_size);
return chHeapAlloc((memory_heap_t *)heap, size);
}

void Util::heap_free(void *ptr)
{
return chHeapFree(ptr);
}


Expand Down
7 changes: 4 additions & 3 deletions libraries/AP_HAL_ChibiOS/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ class ChibiOS::Util : public AP_HAL::Util {

#if ENABLE_HEAP
// heap functions for scripting support
void *allocate_heap_memory(uint32_t size) override;
void free_heap_memory(void *p) override;
void *heap_allocfree(void *heap, void *ptr, uint32_t new_size) override;
void *heap_create(uint32_t size) override;
void heap_destroy(void *p) override;
void *heap_allocate(void *heap, uint32_t size) override;
void heap_free(void *ptr) override;
void *std_realloc(void *ptr, uint32_t new_size) override;
#endif // ENABLE_HEAP

Expand Down

0 comments on commit 020e939

Please sign in to comment.