From 88a8043a27c3f75c7e4e52e4e8b0d47005cd6bef Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 7 Dec 2017 10:52:40 +0200 Subject: py/malloc: MICROPY_MEM_STATS requires MICROPY_MALLOC_USES_ALLOCATED_SIZE. Error out if they're set incompatibly. --- py/malloc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'py/malloc.c') diff --git a/py/malloc.c b/py/malloc.c index ea1d4c4b9..818a3e57a 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 -- cgit v1.2.3 From 9ebc037eee575fd951dea92c82ed9704d9101924 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 7 Dec 2017 17:57:33 +0200 Subject: py/malloc: Allow to use debug logging if !MICROPY_MALLOC_USES_ALLOCATED_SIZE. This is mostly a workaround for forceful rebuilding of mpy-cross on every codebase change. If this file has debug logging enabled (by patching), mpy-cross build failed. --- py/malloc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'py/malloc.c') diff --git a/py/malloc.c b/py/malloc.c index 818a3e57a..6835ed7c9 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -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 -- cgit v1.2.3 From 26d4a6fa45526fa7c267cd9228259642701708f6 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 20 Dec 2017 16:54:31 +1100 Subject: py/malloc: Remove unneeded code checking m_malloc return value. m_malloc already checks for a failed allocation so there's no need to check for it in m_malloc0. --- py/malloc.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'py/malloc.c') diff --git a/py/malloc.c b/py/malloc.c index 6835ed7c9..ba5c952f3 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -117,9 +117,6 @@ void *m_malloc_with_finaliser(size_t num_bytes) { void *m_malloc0(size_t num_bytes) { void *ptr = m_malloc(num_bytes); - 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); -- cgit v1.2.3