rgbmatrix: Don't inline the allocator functions

This commit is contained in:
Jeff Epler 2020-08-28 11:24:59 -05:00
parent 2f120c70ee
commit e01ade3848
2 changed files with 23 additions and 24 deletions

View File

@ -84,7 +84,7 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
_PM_FREE(self->core.screenData);
self->framebuffer = NULL;
self->bufinfo.buf = _PM_allocator_impl(self->bufsize);
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
self->bufinfo.len = self->bufsize;
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
}
@ -211,3 +211,20 @@ int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
int computed_height = (self->rgb_count / 3) << (self->addr_count);
return computed_height;
}
void *common_hal_rgbmatrix_allocator_impl(size_t sz) {
if (gc_alloc_possible()) {
return m_malloc_maybe(sz + sizeof(void*), true);
} else {
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
return allocation ? allocation->ptr : NULL;
}
}
void common_hal_rgbmatrix_free_impl(void *ptr_in) {
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
if (allocation) {
free_memory(allocation);
}
}

View File

@ -1,29 +1,11 @@
#ifndef MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
#define MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
#pragma once
#include <stdbool.h>
#include "py/gc.h"
#include "py/misc.h"
#include "supervisor/memory.h"
#define _PM_ALLOCATOR _PM_allocator_impl
#define _PM_FREE(x) (_PM_free_impl((x)), (x)=NULL, (void)0)
static inline void *_PM_allocator_impl(size_t sz) {
if (gc_alloc_possible()) {
return m_malloc_maybe(sz + sizeof(void*), true);
} else {
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
return allocation ? allocation->ptr : NULL;
}
}
static inline void _PM_free_impl(void *ptr_in) {
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
if (allocation) {
free_memory(allocation);
}
}
#endif
#define _PM_ALLOCATOR common_hal_rgbmatrix_allocator_impl
#define _PM_FREE(x) (common_hal_rgbmatrix_free_impl((x)), (x)=NULL, (void)0)
extern void *common_hal_rgbmatrix_allocator_impl(size_t sz);
extern void common_hal_rgbmatrix_free_impl(void *);