summaryrefslogtreecommitdiff
path: root/py/malloc.c
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2018-07-11 16:45:30 -0400
committerDan Halbert <halbert@halwitz.org>2018-07-11 16:45:30 -0400
commit7c219600a246d8956d0b23ea3f5d125a820e6b6a (patch)
tree4cf793a66284322d48a8f430815c31cd1c9ffa1d /py/malloc.c
parent4962468ffffac9ec4e36b2b1fc3f132516df3127 (diff)
parent25ae98f07cb3c4488cb955403dfe56b8bb8db6f0 (diff)
WIP: after merge; before testing
Diffstat (limited to 'py/malloc.c')
-rw-r--r--py/malloc.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/py/malloc.c b/py/malloc.c
index d6983ffdf..f190582ab 100644
--- a/py/malloc.c
+++ b/py/malloc.c
@@ -39,6 +39,9 @@
#endif
#if MICROPY_MEM_STATS
+#if !MICROPY_MALLOC_USES_ALLOCATED_SIZE
+#error MICROPY_MEM_STATS requires MICROPY_MALLOC_USES_ALLOCATED_SIZE
+#endif
#define UPDATE_PEAK() { if (MP_STATE_MEM(current_bytes_allocated) > MP_STATE_MEM(peak_bytes_allocated)) MP_STATE_MEM(peak_bytes_allocated) = MP_STATE_MEM(current_bytes_allocated); }
#endif
@@ -117,9 +120,6 @@ void *m_malloc_with_finaliser(size_t num_bytes) {
void *m_malloc0(size_t num_bytes, bool long_lived) {
void *ptr = m_malloc(num_bytes, long_lived);
- if (ptr == NULL && num_bytes != 0) {
- m_malloc_fail(num_bytes);
- }
// If this config is set then the GC clears all memory, so we don't need to.
#if !MICROPY_GC_CONSERVATIVE_CLEAR
memset(ptr, 0, num_bytes);
@@ -147,7 +147,11 @@ void *m_realloc(void *ptr, size_t new_num_bytes) {
MP_STATE_MEM(current_bytes_allocated) += diff;
UPDATE_PEAK();
#endif
+ #if MICROPY_MALLOC_USES_ALLOCATED_SIZE
DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
+ #else
+ DEBUG_printf("realloc %p, %d : %p\n", ptr, new_num_bytes, new_ptr);
+ #endif
return new_ptr;
}
@@ -171,7 +175,11 @@ void *m_realloc_maybe(void *ptr, size_t new_num_bytes, bool allow_move) {
UPDATE_PEAK();
}
#endif
+ #if MICROPY_MALLOC_USES_ALLOCATED_SIZE
DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, old_num_bytes, new_num_bytes, new_ptr);
+ #else
+ DEBUG_printf("realloc %p, %d, %d : %p\n", ptr, new_num_bytes, new_ptr);
+ #endif
return new_ptr;
}
@@ -184,7 +192,11 @@ void m_free(void *ptr) {
#if MICROPY_MEM_STATS
MP_STATE_MEM(current_bytes_allocated) -= num_bytes;
#endif
+ #if MICROPY_MALLOC_USES_ALLOCATED_SIZE
DEBUG_printf("free %p, %d\n", ptr, num_bytes);
+ #else
+ DEBUG_printf("free %p\n", ptr);
+ #endif
}
#if MICROPY_MEM_STATS