commit 18a74b617de951286ff40fcd41b8ca68e6179054
parent 559919ef823a756d936be6d7ef5f8ebd6c7beee9
Author: sin <sin@2f30.org>
Date: Tue, 30 Jul 2013 14:37:06 +0100
Add ndebug
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/random/alloc.c b/random/alloc.c
@@ -25,6 +25,8 @@ struct chunk {
enum chunk_state state;
} chunks[NALLOC];
+static int ndebug = 0;
+
static void *
mmap_pages(size_t nbytes)
{
@@ -65,6 +67,9 @@ malloc(size_t nbytes)
chunks[i].base = p;
chunks[i].size = nbytes;
chunks[i].state = ALLOCATED;
+ if (ndebug > 0)
+ fprintf(stderr, "%s: allocated %zu bytes at index %ld\n",
+ __func__, nbytes, i);
return p;
}
}
@@ -98,6 +103,9 @@ realloc(void *oldp, size_t nbytes)
if (chunks[i].base == oldp) {
n = chunks[i].size < nbytes ? chunks[i].size : nbytes;
memcpy(p, chunks[i].base, n);
+ if (ndebug > 0)
+ fprintf(stderr, "%s: reallocated %zu bytes at index %ld\n",
+ __func__, nbytes, i);
free_chunk(&chunks[i]);
return p;
}
@@ -126,6 +134,9 @@ free(void *p)
return;
for (i = 0; i < NALLOC; i++) {
if (chunks[i].base == p) {
+ if (ndebug > 0)
+ fprintf(stderr, "%s: freed chunk of %zu bytes at index %ld\n",
+ __func__, chunks[i].size, i);
free_chunk(&chunks[i]);
break;
}