Skip to content

Commit 3472567

Browse files
committed
use gc_ptr_on_heap() instead of checking if gc_bytes is zero
1 parent ffc42b9 commit 3472567

File tree

10 files changed

+18
-10
lines changed

10 files changed

+18
-10
lines changed

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static void stop_mp(void) {
214214
mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table);
215215

216216
// Unmount all heap allocated vfs mounts.
217-
while (gc_nbytes(vfs) > 0) {
217+
while (gc_ptr_on_heap(vfs)) {
218218
vfs = vfs->next;
219219
}
220220
MP_STATE_VM(vfs_mount_table) = vfs;

ports/espressif/common-hal/_bleio/Characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void common_hal_bleio_characteristic_deinit(bleio_characteristic_obj_t *self) {
120120
return;
121121
}
122122
if (self->current_value != NULL) {
123-
if (gc_nbytes(self->current_value) > 0) {
123+
if (gc_ptr_on_heap(self->current_value)) {
124124
m_free(self->current_value);
125125
} else {
126126
port_free(self->current_value);

ports/nordic/common-hal/_bleio/Characteristic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
8080
// to allocate.
8181
self->initial_value_len = initial_value_bufinfo->len;
8282
if (gc_alloc_possible()) {
83-
if (gc_nbytes(initial_value_bufinfo->buf) > 0) {
83+
if (gc_ptr_on_heap(initial_value_bufinfo->buf)) {
8484
uint8_t *initial_value = m_malloc_without_collect(self->initial_value_len);
8585
memcpy(initial_value, initial_value_bufinfo->buf, self->initial_value_len);
8686
self->initial_value = initial_value;

ports/nordic/common-hal/_bleio/Service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
131131
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&user_desc_md.read_perm);
132132
// If the description is on the Python heap, then have the SD copy it. If not, assume it's
133133
// static and will live for longer than the SD.
134-
user_desc_md.vloc = gc_nbytes(user_description) > 0 ? BLE_GATTS_VLOC_STACK : BLE_GATTS_VLOC_USER;
134+
user_desc_md.vloc = gc_ptr_on_heap(user_description) ? BLE_GATTS_VLOC_STACK : BLE_GATTS_VLOC_USER;
135135
char_md.p_user_desc_md = &user_desc_md;
136136
char_md.p_char_user_desc = (const uint8_t *)user_description;
137137
char_md.char_user_desc_max_size = strlen(user_description);

ports/nordic/common-hal/busio/UART.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void uart_reset(void) {
122122

123123
void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) {
124124
// Don't never reset objects on the heap.
125-
if (gc_alloc_possible() && gc_nbytes(self) > 0) {
125+
if (gc_alloc_possible() && gc_ptr_on_heap(self)) {
126126
return;
127127
}
128128
for (size_t i = 0; i < MP_ARRAY_SIZE(nrfx_uartes); i++) {
@@ -346,7 +346,7 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
346346
RUN_BACKGROUND_TASKS;
347347
}
348348

349-
if (!nrfx_is_in_ram(data) && gc_alloc_possible() && gc_nbytes(tx_buf) > 0) {
349+
if (!nrfx_is_in_ram(data) && gc_alloc_possible() && gc_ptr_on_heap(tx_buf)) {
350350
gc_free(tx_buf);
351351
}
352352

py/circuitpy_mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,14 @@ void background_callback_run_all(void);
513513

514514
// USB settings
515515

516+
#ifndef CIRCUITPY_SDCARD_USB
517+
#define CIRCUITPY_SDCARD_USB (1)
518+
#endif
519+
520+
#if CIRCUITPY_SDCARD_USB && !(CIRCUITPY_SDCARDIO)
521+
#error CIRCUITPY_SDCARD_USB requires CIRCUITPY_SDCARDIO
522+
#endif
523+
516524
// Debug level for TinyUSB. Only outputs over debug UART so it doesn't cause
517525
// additional USB logging.
518526
#ifndef CIRCUITPY_DEBUG_TINYUSB

py/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ bool gc_is_locked(void) {
446446
}
447447

448448
// CIRCUITPY-CHANGE: additional function
449-
bool gc_ptr_on_heap(void *ptr) {
449+
bool gc_ptr_on_heap(const void *ptr) {
450450
for (mp_state_mem_area_t *area = &MP_STATE_MEM(area); area != NULL; area = NEXT_AREA(area)) {
451451
if (ptr >= (void *)area->gc_pool_start // must be above start of pool
452452
&& ptr < (void *)area->gc_pool_end) { // must be below end of pool

py/gc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void *gc_realloc(void *ptr, size_t n_bytes, bool allow_move);
8787
// CIRCUITPY-CHANGE
8888
// True if the pointer is on the MP heap. Doesn't require that it is the start
8989
// of a block.
90-
bool gc_ptr_on_heap(void *ptr);
90+
bool gc_ptr_on_heap(const void *ptr);
9191

9292
typedef struct _gc_info_t {
9393
size_t total;

shared-bindings/_bleio/Adapter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args
339339
if (args[ARG_prefixes].u_obj != MP_OBJ_NULL) {
340340
mp_get_buffer_raise(args[ARG_prefixes].u_obj, &prefix_bufinfo, MP_BUFFER_READ);
341341
// An empty buffer may not be on the heap, but that doesn't matter.
342-
if (prefix_bufinfo.len > 0 && gc_nbytes(prefix_bufinfo.buf) == 0) {
342+
if (prefix_bufinfo.len > 0 && !gc_ptr_on_heap(prefix_bufinfo.buf)) {
343343
mp_raise_ValueError(MP_ERROR_TEXT("Prefix buffer must be on the heap"));
344344
}
345345
}

supervisor/shared/usb/usb_msc_flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static fs_user_mount_t *get_vfs(int lun) {
132132
if (lun == SAVES_LUN) {
133133
const char *path_under_mount;
134134
fs_user_mount_t *saves = filesystem_for_path("/saves", &path_under_mount);
135-
if (saves != root && (saves->blockdev.flags & MP_BLOCKDEV_FLAG_NATIVE) != 0 && gc_nbytes(saves) == 0) {
135+
if (saves != root && (saves->blockdev.flags & MP_BLOCKDEV_FLAG_NATIVE) != 0 && !gc_ptr_on_heap(saves)) {
136136
return saves;
137137
}
138138
}

0 commit comments

Comments
 (0)