summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2021-02-25 16:50:57 -0800
committerScott Shawcroft <scott@tannewt.org>2021-02-25 16:50:57 -0800
commit52bc935fa7aa9e5c94f75fec8b2fa746c83f0be7 (patch)
tree6167dbc2b9e3c51a3322975ec303c0d9155a9356 /py
parent8170e26a869b1f00e2dc7aade84cb459155bf920 (diff)
A few minor fixes for corner cases
* Always clear the peripheral interrupt so we don't hang when full * Store the ringbuf in the object so it gets collected when we're alive * Make UART objects have a finaliser so they are deinit when their memory is freed * Copy bytes into the ringbuf from the FIFO after we read to ensure the interrupt is enabled ASAP * Copy bytes into the ringbuf from the FIFO before measuring our rx available because the interrupt is based on a threshold (not > 0). For example, a single byte won't trigger an interrupt.
Diffstat (limited to 'py')
-rwxr-xr-xpy/gc.c2
-rw-r--r--py/malloc.c6
-rw-r--r--py/misc.h8
3 files changed, 9 insertions, 7 deletions
diff --git a/py/gc.c b/py/gc.c
index 69327060f..2aa2668dc 100755
--- a/py/gc.c
+++ b/py/gc.c
@@ -192,7 +192,7 @@ void gc_init(void *start, void *end) {
}
void gc_deinit(void) {
- // Run any finalizers before we stop using the heap.
+ // Run any finalisers before we stop using the heap.
gc_sweep_all();
MP_STATE_MEM(gc_pool_start) = 0;
diff --git a/py/malloc.c b/py/malloc.c
index 8d5141ee0..c923e89a6 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -57,7 +57,7 @@
#undef free
#undef realloc
#define malloc_ll(b, ll) gc_alloc((b), false, (ll))
-#define malloc_with_finaliser(b) gc_alloc((b), true, false)
+#define malloc_with_finaliser(b, ll) gc_alloc((b), true, (ll))
#define free gc_free
#define realloc(ptr, n) gc_realloc(ptr, n, true)
#define realloc_ext(ptr, n, mv) gc_realloc(ptr, n, mv)
@@ -103,8 +103,8 @@ void *m_malloc_maybe(size_t num_bytes, bool long_lived) {
}
#if MICROPY_ENABLE_FINALISER
-void *m_malloc_with_finaliser(size_t num_bytes) {
- void *ptr = malloc_with_finaliser(num_bytes);
+void *m_malloc_with_finaliser(size_t num_bytes, bool long_lived) {
+ void *ptr = malloc_with_finaliser(num_bytes, long_lived);
if (ptr == NULL && num_bytes != 0) {
m_malloc_fail(num_bytes);
}
diff --git a/py/misc.h b/py/misc.h
index 6ed256e70..0fef7e249 100644
--- a/py/misc.h
+++ b/py/misc.h
@@ -72,11 +72,13 @@ typedef unsigned int uint;
#define m_new_obj_var_maybe(obj_type, var_type, var_num) ((obj_type*)m_malloc_maybe(sizeof(obj_type) + sizeof(var_type) * (var_num), false))
#define m_new_ll_obj_var_maybe(obj_type, var_type, var_num) ((obj_type*)m_malloc_maybe(sizeof(obj_type) + sizeof(var_type) * (var_num), true))
#if MICROPY_ENABLE_FINALISER
-#define m_new_obj_with_finaliser(type) ((type*)(m_malloc_with_finaliser(sizeof(type))))
-#define m_new_obj_var_with_finaliser(type, var_type, var_num) ((type*)m_malloc_with_finaliser(sizeof(type) + sizeof(var_type) * (var_num)))
+#define m_new_obj_with_finaliser(type) ((type*)(m_malloc_with_finaliser(sizeof(type), false)))
+#define m_new_obj_var_with_finaliser(type, var_type, var_num) ((type*)m_malloc_with_finaliser(sizeof(type) + sizeof(var_type) * (var_num), false))
+#define m_new_ll_obj_with_finaliser(type) ((type*)(m_malloc_with_finaliser(sizeof(type), true)))
#else
#define m_new_obj_with_finaliser(type) m_new_obj(type)
#define m_new_obj_var_with_finaliser(type, var_type, var_num) m_new_obj_var(type, var_type, var_num)
+#define m_new_ll_obj_with_finaliser(type) m_new_ll_obj(type)
#endif
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
#define m_renew(type, ptr, old_num, new_num) ((type*)(m_realloc((ptr), sizeof(type) * (old_num), sizeof(type) * (new_num))))
@@ -93,7 +95,7 @@ typedef unsigned int uint;
void *m_malloc(size_t num_bytes, bool long_lived);
void *m_malloc_maybe(size_t num_bytes, bool long_lived);
-void *m_malloc_with_finaliser(size_t num_bytes);
+void *m_malloc_with_finaliser(size_t num_bytes, bool long_lived);
void *m_malloc0(size_t num_bytes, bool long_lived);
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
void *m_realloc(void *ptr, size_t old_num_bytes, size_t new_num_bytes);