Merge branch 'malloc-print' (#2061)

* origin/malloc-print:
  vere: print arg to c3_malloc() et. al. on failure

Signed-off-by: Jared Tobin <jared@tlon.io>
This commit is contained in:
Jared Tobin 2019-12-10 16:19:11 +08:00
commit 69c2f5517c
No known key found for this signature in database
GPG Key ID: 0E4647D58F8A69E4

View File

@ -86,21 +86,27 @@
/* Asserting allocators.
*/
# define c3_free(s) free(s)
# define c3_malloc(s) ({ \
void* rut = malloc(s); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
# define c3_malloc(s) ({ \
void* rut = malloc(s); \
if ( 0 == rut ) { \
fprintf(stderr, "c3_malloc(%" PRIu64 ") failed\r\n", \
(c3_d)s); \
c3_assert(!"memory lost"); \
} \
rut;})
# define c3_calloc(s) ({ \
void* rut = calloc(1,s); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
# define c3_calloc(s) ({ \
void* rut = calloc(1,s); \
if ( 0 == rut ) { \
fprintf(stderr, "c3_calloc(%" PRIu64 ") failed\r\n", \
(c3_d)s); \
c3_assert(!"memory lost"); \
} \
rut;})
# define c3_realloc(a, b) ({ \
void* rut = realloc(a, b); \
if ( 0 == rut ) { \
c3_assert(!"memory lost"); \
} \
# define c3_realloc(a, b) ({ \
void* rut = realloc(a, b); \
if ( 0 == rut ) { \
fprintf(stderr, "c3_realloc(%" PRIu64 ") failed\r\n", \
(c3_d)b); \
c3_assert(!"memory lost"); \
} \
rut;})