From 91c1aecb51b5b6e28b96e83456cf7737c2009981 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Mon, 11 Jan 2021 19:04:18 +0200 Subject: [PATCH] Make xalloc exception more useful. * Add the number of bytes to the exception message, could be very helpful to the user in debugging stuff. --- src/omv/alloc/xalloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/omv/alloc/xalloc.c b/src/omv/alloc/xalloc.c index 70e2bd3f9..03a3c18f0 100644 --- a/src/omv/alloc/xalloc.c +++ b/src/omv/alloc/xalloc.c @@ -14,10 +14,10 @@ #include "py/mphal.h" #include "xalloc.h" -NORETURN static void xalloc_fail() +NORETURN static void xalloc_fail(uint32_t size) { - mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("Out of normal MicroPython Heap Memory!" - " Please reduce the resolution of the image you are running this algorithm on to bypass this issue!")); + mp_raise_msg_varg(&mp_type_MemoryError, + MP_ERROR_TEXT("memory allocation failed, allocating %u bytes"), (uint)size); } // returns null pointer without error if size==0 @@ -25,7 +25,7 @@ void *xalloc(uint32_t size) { void *mem = gc_alloc(size, false); if (size && (mem == NULL)) { - xalloc_fail(); + xalloc_fail(size); } return mem; } @@ -41,7 +41,7 @@ void *xalloc0(uint32_t size) { void *mem = gc_alloc(size, false); if (size && (mem == NULL)) { - xalloc_fail(); + xalloc_fail(size); } memset(mem, 0, size); return mem; @@ -60,7 +60,7 @@ void *xrealloc(void *mem, uint32_t size) { mem = gc_realloc(mem, size, true); if (size && (mem == NULL)) { - xalloc_fail(); + xalloc_fail(size); } return mem; }