diff --git a/src/.umm_malloc_cfg.h.swo b/src/.umm_malloc_cfg.h.swo new file mode 100644 index 0000000..574272d Binary files /dev/null and b/src/.umm_malloc_cfg.h.swo differ diff --git a/src/umm_info.c b/src/umm_info.c index bf4d68d..0139501 100644 --- a/src/umm_info.c +++ b/src/umm_info.c @@ -24,12 +24,10 @@ UMM_HEAP_INFO ummHeapInfo; void *umm_info(void *ptr, bool force) { - if (UMM_HEAP == NULL) { - umm_init(); - } - uint16_t blockNo = 0; + UMM_CHECK_INITIALIZED(); + /* Protect the critical section... */ UMM_CRITICAL_ENTRY(); diff --git a/src/umm_integrity.c b/src/umm_integrity.c index 6b6906a..d26931f 100644 --- a/src/umm_integrity.c +++ b/src/umm_integrity.c @@ -31,9 +31,7 @@ bool umm_integrity_check(void) { uint16_t prev; uint16_t cur; - if (UMM_HEAP == NULL) { - umm_init(); - } + UMM_CHECK_INITIALIZED(); /* Iterate through all free blocks */ prev = 0; diff --git a/src/umm_malloc.c b/src/umm_malloc.c index c71c25c..fce5d17 100644 --- a/src/umm_malloc.c +++ b/src/umm_malloc.c @@ -360,9 +360,7 @@ static void umm_free_core(void *ptr) { void umm_free(void *ptr) { - if (UMM_HEAP == NULL) { - umm_init(); - } + UMM_CHECK_INITIALIZED(); /* If we're being asked to free a NULL pointer, well that's just silly! */ @@ -501,9 +499,7 @@ void *umm_malloc(size_t size) { void *ptr = NULL; - if (UMM_HEAP == NULL) { - umm_init(); - } + UMM_CHECK_INITIALIZED(); /* * the very first thing we do is figure out if we're being asked to allocate @@ -542,9 +538,7 @@ void *umm_realloc(void *ptr, size_t size) { size_t curSize; - if (UMM_HEAP == NULL) { - umm_init(); - } + UMM_CHECK_INITIALIZED(); /* * This code looks after the case of a NULL value for ptr. The ANSI C diff --git a/src/umm_malloc_cfg.h b/src/umm_malloc_cfg.h index 3d48b1d..dffb4fa 100644 --- a/src/umm_malloc_cfg.h +++ b/src/umm_malloc_cfg.h @@ -37,10 +37,6 @@ * sure that the configuration makes sense. For example the UMM_BLOCK_BODY_SIZE * is a minimum of 8 and a multiple of 4. * - * UMM_TEST_BUILD - * - * Set this if you want to compile in the test suite - * * UMM_BLOCK_BODY_SIZE * * Defines the umm_block[].body size - it is 8 by default @@ -82,6 +78,16 @@ * Setting this at compile time will automatically set UMM_INFO. * Note that enabling this define will add a slight runtime penalty. * + * UMM_CHECK_INITIALIZED + * + * Set if you want to be able to verify that the heap is intialized + * before any operation - the default is no check. You may set the + * UMM_CHECK_INITIALIZED macro to the following provided macros, or + * write your own handler: + * + * UMM_INIT_IF_UNINITIALIZED + * UMM_HANG_IF_UNINITIALIZED + * * UMM_INTEGRITY_CHECK * * Set if you want to be able to verify that the heap is semantically correct @@ -106,6 +112,9 @@ * Set n to a value from 0 to 6 depending on how verbose you want the debug * log to be * + * UMM_TEST_BUILD + * + * Set this if you want to compile in the test suite * ---------------------------------------------------------------------------- * * Support for this library in a multitasking environment is provided when @@ -128,6 +137,20 @@ /* -------------------------------------------------------------------------- */ +#ifndef UMM_INIT_IF_UNINITIALIZED + #define UMM_INIT_IF_UNINITIALIZED() do { if (UMM_HEAP == NULL) { umm_init(); } } while(0) +#endif + +#ifndef UMM_HANG_IF_UNINITIALIZED + #define UMM_HANG_IF_UNINITIALIZED() do { if (UMM_HEAP == NULL) { while(1) {} } } while(0) +#endif + +#ifndef UMM_CHECK_INITIALIZED + #define UMM_CHECK_INITIALIZED() +#endif + +/* -------------------------------------------------------------------------- */ + #ifndef UMM_BLOCK_BODY_SIZE #define UMM_BLOCK_BODY_SIZE (8) #endif diff --git a/src/umm_poison.c b/src/umm_poison.c index e7c4e42..d565674 100644 --- a/src/umm_poison.c +++ b/src/umm_poison.c @@ -207,9 +207,7 @@ bool umm_poison_check(void) { bool ok = true; unsigned short int cur; - if (UMM_HEAP == NULL) { - umm_init(); - } + UMM_CHECK_INITIALIZED(); /* Now iterate through the blocks list */ cur = UMM_NBLOCK(0) & UMM_BLOCKNO_MASK;