Skip to content

Commit e01ade3

Browse files
committed
rgbmatrix: Don't inline the allocator functions
1 parent 2f120c7 commit e01ade3

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

shared-module/rgbmatrix/RGBMatrix.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void common_hal_rgbmatrix_rgbmatrix_reconstruct(rgbmatrix_rgbmatrix_obj_t* self,
8484
_PM_FREE(self->core.screenData);
8585

8686
self->framebuffer = NULL;
87-
self->bufinfo.buf = _PM_allocator_impl(self->bufsize);
87+
self->bufinfo.buf = common_hal_rgbmatrix_allocator_impl(self->bufsize);
8888
self->bufinfo.len = self->bufsize;
8989
self->bufinfo.typecode = 'H' | MP_OBJ_ARRAY_TYPECODE_FLAG_RW;
9090
}
@@ -211,3 +211,20 @@ int common_hal_rgbmatrix_rgbmatrix_get_height(rgbmatrix_rgbmatrix_obj_t* self) {
211211
int computed_height = (self->rgb_count / 3) << (self->addr_count);
212212
return computed_height;
213213
}
214+
215+
void *common_hal_rgbmatrix_allocator_impl(size_t sz) {
216+
if (gc_alloc_possible()) {
217+
return m_malloc_maybe(sz + sizeof(void*), true);
218+
} else {
219+
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
220+
return allocation ? allocation->ptr : NULL;
221+
}
222+
}
223+
224+
void common_hal_rgbmatrix_free_impl(void *ptr_in) {
225+
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
226+
227+
if (allocation) {
228+
free_memory(allocation);
229+
}
230+
}

shared-module/rgbmatrix/allocator.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,11 @@
1-
#ifndef MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
2-
#define MICROPY_INCLUDED_SHARED_MODULE_RGBMATRIX_ALLOCATOR_H
1+
#pragma once
32

43
#include <stdbool.h>
54
#include "py/gc.h"
65
#include "py/misc.h"
76
#include "supervisor/memory.h"
87

9-
#define _PM_ALLOCATOR _PM_allocator_impl
10-
#define _PM_FREE(x) (_PM_free_impl((x)), (x)=NULL, (void)0)
11-
12-
static inline void *_PM_allocator_impl(size_t sz) {
13-
if (gc_alloc_possible()) {
14-
return m_malloc_maybe(sz + sizeof(void*), true);
15-
} else {
16-
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
17-
return allocation ? allocation->ptr : NULL;
18-
}
19-
}
20-
21-
static inline void _PM_free_impl(void *ptr_in) {
22-
supervisor_allocation *allocation = allocation_from_ptr(ptr_in);
23-
24-
if (allocation) {
25-
free_memory(allocation);
26-
}
27-
}
28-
29-
#endif
8+
#define _PM_ALLOCATOR common_hal_rgbmatrix_allocator_impl
9+
#define _PM_FREE(x) (common_hal_rgbmatrix_free_impl((x)), (x)=NULL, (void)0)
10+
extern void *common_hal_rgbmatrix_allocator_impl(size_t sz);
11+
extern void common_hal_rgbmatrix_free_impl(void *);

0 commit comments

Comments
 (0)