Skip to content

Commit 7ac2000

Browse files
authored
Merge pull request #3799 from dhalbert/wifi-radio-gc-collect
Include wifi.radio singleton in gc
2 parents a7ec4a0 + 169b487 commit 7ac2000

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
#include "common-hal/canio/CAN.h"
9696
#endif
9797

98+
#if CIRCUITPY_WIFI
99+
#include "shared-bindings/wifi/__init__.h"
100+
#endif
101+
98102
#if MICROPY_ENABLE_PYSTACK
99103
static size_t PLACE_IN_DTCM_BSS(_pystack[CIRCUITPY_PYSTACK_SIZE / sizeof(size_t)]);
100104
#endif
@@ -560,6 +564,10 @@ void gc_collect(void) {
560564
common_hal_bleio_gc_collect();
561565
#endif
562566

567+
#if CIRCUITPY_WIFI
568+
common_hal_wifi_gc_collect();
569+
#endif
570+
563571
// This naively collects all object references from an approximate stack
564572
// range.
565573
gc_collect_root((void**)sp, ((uint32_t)port_stack_get_top() - sp) / sizeof(uint32_t));

ports/esp32s2/common-hal/wifi/Radio.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "common-hal/wifi/__init__.h"
3333
#include "lib/utils/interrupt_char.h"
34+
#include "py/gc.h"
3435
#include "py/runtime.h"
3536
#include "shared-bindings/ipaddress/IPv4Address.h"
3637
#include "shared-bindings/wifi/ScannedNetworks.h"
@@ -262,3 +263,8 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address,
262263

263264
return elapsed_time;
264265
}
266+
267+
void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self) {
268+
// Only bother to scan the actual object references.
269+
gc_collect_ptr(self->current_scan);
270+
}

ports/esp32s2/common-hal/wifi/Radio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ typedef struct {
5959
uint8_t last_disconnect_reason;
6060
} wifi_radio_obj_t;
6161

62+
extern void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self);
63+
6264
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_WIFI_RADIO_H

ports/esp32s2/common-hal/wifi/__init__.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,7 @@ void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t* esp_ip_addre
160160

161161
IP_ADDR4(esp_ip_address, bytes[0], bytes[1], bytes[2], bytes[3]);
162162
}
163+
164+
void common_hal_wifi_gc_collect(void) {
165+
common_hal_wifi_radio_gc_collect(&common_hal_wifi_radio_obj);
166+
}

shared-bindings/wifi/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
extern wifi_radio_obj_t common_hal_wifi_radio_obj;
3535

3636
void common_hal_wifi_init(void);
37+
void common_hal_wifi_gc_collect(void);
3738

3839
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI___INIT___H

0 commit comments

Comments
 (0)