diff --git a/libraries/AP_HAL_ChibiOS/Util.cpp b/libraries/AP_HAL_ChibiOS/Util.cpp index 705c89225684b..aeec5aed47017 100644 --- a/libraries/AP_HAL_ChibiOS/Util.cpp +++ b/libraries/AP_HAL_ChibiOS/Util.cpp @@ -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) { @@ -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); } diff --git a/libraries/AP_HAL_ChibiOS/Util.h b/libraries/AP_HAL_ChibiOS/Util.h index d2480b9065fff..9fae8f94903d2 100644 --- a/libraries/AP_HAL_ChibiOS/Util.h +++ b/libraries/AP_HAL_ChibiOS/Util.h @@ -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