From 46d57c352a0d10de969bcdb830e3e0b71d092d67 Mon Sep 17 00:00:00 2001 From: mquinson Date: Fri, 7 May 2010 08:55:40 +0000 Subject: [PATCH] let malloc(0) work (and kill debug outputs) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7713 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/mmalloc/mmalloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index c717fe58e7..7d8f8ef083 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -112,12 +112,15 @@ void* mmalloc (void *md, size_t size) { struct list *next; register size_t log; + /* Work even if the user was stupid enough to ask a 0-byte block, ie return a valid block that can be realloced or freed + * glibc malloc does not use this trick but return a constant pointer, but my hack is quicker to implement ;) + */ if (size == 0) - return (NULL); + size=1; mdp = MD_TO_MDP (md); LOCK(mdp); - printf("(%s) Mallocing %d bytes on %p (default: %p)...",xbt_thread_self_name(),size,mdp,__mmalloc_default_mdp);fflush(stdout); +// printf("(%s) Mallocing %d bytes on %p (default: %p)...",xbt_thread_self_name(),size,mdp,__mmalloc_default_mdp);fflush(stdout); if (mdp -> mmalloc_hook != NULL) { @@ -181,9 +184,9 @@ void* mmalloc (void *md, size_t size) { /* No free fragments of the desired size, so get a new block and break it into fragments, returning the first. */ UNLOCK(mdp); - printf("(%s) No free fragment...",xbt_thread_self_name()); + //printf("(%s) No free fragment...",xbt_thread_self_name()); result = mmalloc (md, BLOCKSIZE); - printf("(%s) Fragment: %p...",xbt_thread_self_name(),result); + //printf("(%s) Fragment: %p...",xbt_thread_self_name(),result); LOCK(mdp); if (result == NULL) { @@ -298,7 +301,7 @@ void* mmalloc (void *md, size_t size) { mdp -> heapstats.bytes_used += blocks * BLOCKSIZE; mdp -> heapstats.bytes_free -= blocks * BLOCKSIZE; } - printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout); + //printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout); UNLOCK(mdp); return (result); } -- 2.20.1