summaryrefslogtreecommitdiffstatshomepage
path: root/py/malloc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-05 20:35:48 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-05 20:35:48 +0100
commit12bab72d93498958ddef26c1a2dd7c69a9f9cf8d (patch)
tree7415b5201b6dca0daf60a9968543b398fab49baa /py/malloc.c
parent8123a3339dc7381a079afa90649ce140075eb2e2 (diff)
downloadmicropython-12bab72d93498958ddef26c1a2dd7c69a9f9cf8d.tar.gz
micropython-12bab72d93498958ddef26c1a2dd7c69a9f9cf8d.zip
Improve GC finalisation code; add option to disable it.
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/py/malloc.c b/py/malloc.c
index a07d360020..45e939b6c2 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -30,8 +30,8 @@ STATIC int peak_bytes_allocated = 0;
#undef malloc
#undef free
#undef realloc
-#define malloc gc_alloc
-#define malloc_mp_obj gc_alloc_mp_obj
+#define malloc(b) gc_alloc((b), false)
+#define malloc_with_finaliser(b) gc_alloc((b), true)
#define free gc_free
#define realloc gc_realloc
#endif // MICROPY_ENABLE_GC
@@ -53,14 +53,14 @@ void *m_malloc(int num_bytes) {
return ptr;
}
-void *m_malloc_mp_obj(int num_bytes) {
+#if MICROPY_ENABLE_FINALISER
+void *m_malloc_with_finaliser(int num_bytes) {
if (num_bytes == 0) {
return NULL;
}
- void *ptr = malloc_mp_obj(num_bytes);
+ void *ptr = malloc_with_finaliser(num_bytes);
if (ptr == NULL) {
- printf("could not allocate memory, allocating %d bytes\n", num_bytes);
- return NULL;
+ return m_malloc_fail(num_bytes);
}
#if MICROPY_MEM_STATS
total_bytes_allocated += num_bytes;
@@ -70,6 +70,7 @@ void *m_malloc_mp_obj(int num_bytes) {
DEBUG_printf("malloc %d : %p\n", num_bytes, ptr);
return ptr;
}
+#endif
void *m_malloc0(int num_bytes) {
void *ptr = m_malloc(num_bytes);