8000 sharpdisplay: Re-use supervisor allocations if possible · adafruit/circuitpython@b520498 · GitHub
[go: up one dir, main page]

Skip to content

Commit b520498

Browse files
committed
sharpdisplay: Re-use supervisor allocations if possible
This is enabled by #3482 I was unable to determine why previously I had added sizeof(void*) to the GC heap allocation, so I removed that code as a mistake.
1 parent 50e9008 commit b520498

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

shared-module/sharpdisplay/SharpMemoryFramebuffer.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,22 @@
3434
#include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h"
3535

3636
#include "supervisor/memory.h"
37+
#include "supervisor/shared/safe_mode.h"
3738

3839
#define SHARPMEM_BIT_WRITECMD_LSB (0x80)
3940
#define SHARPMEM_BIT_VCOM_LSB (0x40)
4041

41-
static inline void *hybrid_alloc(size_t sz) {
42-
if (gc_alloc_possible()) {
43-
return m_malloc(sz + sizeof(void*), true);
44-
} else {
45-
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
46-
if (!allocation) {
47-
return NULL;
48-
}
42+
static void *hybrid_alloc(size_t sz) {
43+
supervisor_allocation *allocation = allocate_memory(align32_size(sz), false);
44+
if (allocation) {
4945
memset(allocation->ptr, 0, sz);
5046
return allocation->ptr;
5147
}
48+
if (gc_alloc_possible()) {
49+
return m_malloc(sz, true);
50+
}
51+
reset_into_safe_mode(MEM_MANAGE);
52+
return NULL; // unreached
5253
}
5354

5455
static inline void hybrid_free(void *ptr_in) {
@@ -155,7 +156,8 @@ void common_hal_sharpdisplay_framebuffer_construct(sharpdisplay_framebuffer_obj_
155156

156157
int row_stride = common_hal_sharpdisplay_framebuffer_get_row_stride(self);
157158
self->bufinfo.len = row_stride * height + 2;
158-
self->bufinfo.buf = gc_alloc(self->bufinfo.len, false, true);
159+
// re-use a supervisor allocation if possible
160+
self->bufinfo.buf = hybrid_alloc(self->bufinfo.len);
159161

160162
uint8_t *data = self->bufinfo.buf;
161163
*data++ = SHARPMEM_BIT_WRITECMD_LSB;

0 commit comments

Comments
0 (0)
0