Skip to content

Commit 62de250

Browse files
committed
Include display objects in gc.
1 parent c90ce2b commit 62de250

File tree

9 files changed

+36
-8
lines changed

9 files changed

+36
-8
lines changed

main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ void gc_collect(void) {
455455
// This collects root pointers from the VFS mount table. Some of them may
456456
// have lost their references in the VM even though they are mounted.
457457
gc_collect_root((void**)&MP_STATE_VM(vfs_mount_table), sizeof(mp_vfs_mount_t) / sizeof(mp_uint_t));
458+
459+
#if CIRCUITPY_DISPLAYIO
460+
displayio_gc_collect();
461+
#endif
462+
458463
// This naively collects all object references from an approximate stack
459464
// range.
460465
gc_collect_root((void**)sp, ((uint32_t)&_estack - sp) / sizeof(uint32_t));

ports/nrf/background.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "supervisor/usb.h"
3030
#include "supervisor/shared/stack.h"
3131

32-
#ifdef CIRCUITPY_DISPLAYIO
32+
#if CIRCUITPY_DISPLAYIO
3333
#include "shared-module/displayio/__init__.h"
3434
#endif
3535

@@ -48,7 +48,7 @@ void run_background_tasks(void) {
4848
filesystem_background();
4949
usb_background();
5050

51-
#ifdef CIRCUITPY_DISPLAYIO
51+
#if CIRCUITPY_DISPLAYIO
5252
displayio_refresh_displays();
5353
#endif
5454
running_background_tasks = false;

ports/nrf/supervisor/port.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,22 @@ void reset_port(void) {
9393
i2c_reset();
9494
spi_reset();
9595
uart_reset();
96+
97+
#if CIRCUITPY_PULSEIO
9698
pwmout_reset();
9799
pulseout_reset();
98100
pulsein_reset();
101+
#endif
102+
99103
timers_reset();
100104

101-
#if CIRCUITPY_RTC
105+
#if CIRCUITPY_RTC
102106
rtc_reset();
103-
#endif
107+
#endif
104108

109+
#if CIRCUITPY_BLEIO
105110
bleio_reset();
111+
#endif
106112

107113
reset_all_pins();
108114
}

py/gc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ void gc_collect_start(void) {
383383
#endif
384384
}
385385

386+
void gc_collect_ptr(void *ptr) {
387+
gc_mark(ptr);
388+
}
389+
386390
void gc_collect_root(void **ptrs, size_t len) {
387391
for (size_t i = 0; i < len; i++) {
388392
void *ptr = ptrs[i];

py/gc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ bool gc_is_locked(void);
4343
// A given port must implement gc_collect by using the other collect functions.
4444
void gc_collect(void);
4545
void gc_collect_start(void);
46+
void gc_collect_ptr(void *ptr);
4647
void gc_collect_root(void **ptrs, size_t len);
4748
void gc_collect_end(void);
4849

shared-bindings/board/__init__.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
//|
3535
//| .. module:: board
3636
//| :synopsis: Board specific pin names
37-
//| :platform: SAMD21
3837
//|
3938
//| Common container for board base pin names. These will vary from board to
4039
//| board so don't expect portability when using this module.

shared-module/board/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void reset_board_busses(void) {
103103
#endif
104104
#if BOARD_SPI
105105
bool display_using_spi = false;
106-
#ifdef CIRCUITPY_DISPLAYIO
106+
#if CIRCUITPY_DISPLAYIO
107107
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
108108
if (displays[i].fourwire_bus.bus == spi_singleton) {
109109
display_using_spi = true;

shared-module/displayio/__init__.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "shared-module/displayio/__init__.h"
44

55
#include "lib/utils/interrupt_char.h"
6+
#include "py/gc.h"
67
#include "py/reload.h"
78
#include "py/runtime.h"
89
#include "shared-bindings/board/__init__.h"
@@ -181,7 +182,6 @@ void common_hal_displayio_release_displays(void) {
181182
}
182183

183184
void reset_displays(void) {
184-
#if CIRCUITPY_DISPLAYIO
185185
// The SPI buses used by FourWires may be allocated on the heap so we need to move them inline.
186186
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
187187
if (displays[i].fourwire_bus.base.type != &displayio_fourwire_type) {
@@ -218,5 +218,17 @@ void reset_displays(void) {
218218
display->auto_brightness = true;
219219
common_hal_displayio_display_show(display, &circuitpython_splash);
220220
}
221-
#endif
221+
}
222+
223+
void displayio_gc_collect(void) {
224+
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
225+
if (displays[i].display.base.type == NULL) {
226+
continue;
227+
}
228+
229+
// Alternatively, we could use gc_collect_root over the whole object,
230+
// but this is more precise, and is the only field that needs marking.
231+
gc_collect_ptr(displays[i].display.current_group);
232+
233+
}
222234
}

shared-module/displayio/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ extern displayio_group_t circuitpython_splash;
4646

4747
void displayio_refresh_displays(void);
4848
void reset_displays(void);
49+
void displayio_gc_collect(void);
4950

5051
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H

0 commit comments

Comments
 (0)