From: mquinson Date: Fri, 7 May 2010 08:55:40 +0000 (+0000) Subject: let malloc(0) work (and kill debug outputs) X-Git-Tag: SVN~31 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/46d57c352a0d10de969bcdb830e3e0b71d092d67?hp=bbc1569a8f78a6dcdb4511735830587adfa06e87 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 --- 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); }