AP_HAL_ChibiOS: implement standard realloc method
This commit is contained in:
parent
792fe2697a
commit
a9ea7ca3dc
@ -86,6 +86,26 @@ void *Util::allocate_heap_memory(size_t size)
|
|||||||
return heap;
|
return heap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
realloc implementation thanks to wolfssl, used by AP_Scripting
|
||||||
|
*/
|
||||||
|
void *Util::std_realloc(void *addr, size_t size)
|
||||||
|
{
|
||||||
|
if (size == 0) {
|
||||||
|
free(addr);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
if (addr == nullptr) {
|
||||||
|
return malloc(size);
|
||||||
|
}
|
||||||
|
void *new_mem = malloc(size);
|
||||||
|
if (new_mem != nullptr) {
|
||||||
|
memcpy(new_mem, addr, chHeapGetSize(addr) > size ? size : chHeapGetSize(addr));
|
||||||
|
free(addr);
|
||||||
|
}
|
||||||
|
return new_mem;
|
||||||
|
}
|
||||||
|
|
||||||
void *Util::heap_realloc(void *heap, void *ptr, size_t new_size)
|
void *Util::heap_realloc(void *heap, void *ptr, size_t new_size)
|
||||||
{
|
{
|
||||||
if (heap == nullptr) {
|
if (heap == nullptr) {
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
// heap functions, note that a heap once alloc'd cannot be dealloc'd
|
// heap functions, note that a heap once alloc'd cannot be dealloc'd
|
||||||
virtual void *allocate_heap_memory(size_t size) override;
|
virtual void *allocate_heap_memory(size_t size) override;
|
||||||
virtual void *heap_realloc(void *heap, void *ptr, size_t new_size) override;
|
virtual void *heap_realloc(void *heap, void *ptr, size_t new_size) override;
|
||||||
|
virtual void *std_realloc(void *ptr, size_t new_size) override;
|
||||||
#endif // ENABLE_HEAP
|
#endif // ENABLE_HEAP
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user