From 34fe2541425db4576e9ec1288241e4da80298f1c Mon Sep 17 00:00:00 2001 From: mquinson Date: Wed, 5 May 2010 21:38:41 +0000 Subject: [PATCH 1/1] Update mmalloc to compile with paranoid flags used in simgrid git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7695 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/xbt/mmalloc/detach.c | 3 ++- src/xbt/mmalloc/mfree.c | 14 +++++++++----- src/xbt/mmalloc/mmalloc.c | 10 +++++----- src/xbt/mmalloc/mmap-sup.c | 2 +- src/xbt/mmalloc/mmemalign.c | 2 +- src/xbt/mmalloc/mmprivate.h | 6 +++--- src/xbt/mmalloc/mmstats.c | 2 +- src/xbt/mmalloc/mrealloc.c | 3 +++ src/xbt/mmalloc/mvalloc.c | 6 ++++-- src/xbt/mmalloc/sbrk-sup.c | 4 ++-- 10 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/xbt/mmalloc/detach.c b/src/xbt/mmalloc/detach.c index 1780679417..b5b5092057 100644 --- a/src/xbt/mmalloc/detach.c +++ b/src/xbt/mmalloc/detach.c @@ -20,6 +20,7 @@ License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include /* close */ #include #include "mmprivate.h" @@ -51,7 +52,7 @@ mmalloc_detach (md) /* Now unmap all the pages associated with this region by asking for a negative increment equal to the current size of the region. */ - if ((mtemp.morecore (&mtemp, mtemp.base - mtemp.breakval)) == NULL) + if ((mtemp.morecore (&mtemp, (char*)mtemp.base - (char*)mtemp.breakval)) == NULL) { /* Deallocating failed. Update the original malloc descriptor with any changes */ diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index a602355f26..d6f1cf9458 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -33,7 +33,7 @@ __mmalloc_free (mdp, ptr) PTR ptr; { int type; - size_t block, blocks; + size_t block;//, blocks; unused variable? register size_t i; struct list *prev, *next; @@ -135,8 +135,8 @@ __mmalloc_free (mdp, ptr) /* Get the address of the first free fragment in this block. */ prev = (struct list *) - ((PTR) ADDRESS(block) + - (mdp -> heapinfo[block].busy.info.frag.first << type)); + ((char*) ADDRESS(block) + + ( mdp -> heapinfo[block].busy.info.frag.first << type)); if (mdp -> heapinfo[block].busy.info.frag.nfree == (BLOCKSIZE >> type) - 1) @@ -233,6 +233,11 @@ mfree (md, ptr) } } + +/* Useless prototype to make gcc happy */ +void free(void* ptr); + + /* When using this package, provide a version of malloc/realloc/free built on top of it, so that if we use the default sbrk() region we will not collide with another malloc package trying to do the same thing, if @@ -240,8 +245,7 @@ mfree (md, ptr) as inside a system library). */ void -free (ptr) - PTR ptr; +free (PTR ptr) { mfree ((PTR) NULL, ptr); } diff --git a/src/xbt/mmalloc/mmalloc.c b/src/xbt/mmalloc/mmalloc.c index a67700096e..ba63e37128 100644 --- a/src/xbt/mmalloc/mmalloc.c +++ b/src/xbt/mmalloc/mmalloc.c @@ -48,7 +48,7 @@ align (mdp, size) { adj = BLOCKSIZE - adj; mdp -> morecore (mdp, adj); - result = (PTR) result + adj; + result = (char*) result + adj; } return (result); } @@ -94,10 +94,10 @@ morecore (mdp, size) } /* Check if we need to grow the info table. */ - if ((size_t) BLOCK ((PTR) result + size) > mdp -> heapsize) + if ((size_t) BLOCK ((char*) result + size) > mdp -> heapsize) { newsize = mdp -> heapsize; - while ((size_t) BLOCK ((PTR) result + size) > newsize) + while ((size_t) BLOCK ((char*) result + size) > newsize) { newsize *= 2; } @@ -119,7 +119,7 @@ morecore (mdp, size) mdp -> heapsize = newsize; } - mdp -> heaplimit = BLOCK ((PTR) result + size); + mdp -> heaplimit = BLOCK ((char*) result + size); return (result); } @@ -214,7 +214,7 @@ mmalloc (md, size) /* Link all fragments but the first into the free list. */ for (i = 1; i < (size_t) (BLOCKSIZE >> log); ++i) { - next = (struct list *) ((PTR) result + (i << log)); + next = (struct list *) ((char*) result + (i << log)); next -> next = mdp -> fraghead[log].next; next -> prev = &mdp -> fraghead[log]; next -> prev -> next = next; diff --git a/src/xbt/mmalloc/mmap-sup.c b/src/xbt/mmalloc/mmap-sup.c index ccaf7bb14f..5c7db2a6d4 100644 --- a/src/xbt/mmalloc/mmap-sup.c +++ b/src/xbt/mmalloc/mmap-sup.c @@ -218,5 +218,5 @@ mmalloc_findbase (size) #else /* defined(HAVE_MMAP) */ /* Prevent "empty translation unit" warnings from the idiots at X3J11. */ -static char ansi_c_idiots = 69; +//static char ansi_c_idiots = 69; #endif /* defined(HAVE_MMAP) */ diff --git a/src/xbt/mmalloc/mmemalign.c b/src/xbt/mmalloc/mmemalign.c index 595cb6cc6e..584f82cc7c 100644 --- a/src/xbt/mmalloc/mmemalign.c +++ b/src/xbt/mmalloc/mmemalign.c @@ -55,7 +55,7 @@ mmemalign (md, alignment, size) mdp -> aligned_blocks = l; } l -> exact = result; - result = l -> aligned = (PTR) result + alignment - adj; + result = l -> aligned = (char*) result + alignment - adj; } } return (result); diff --git a/src/xbt/mmalloc/mmprivate.h b/src/xbt/mmalloc/mmprivate.h index eccffec56a..2bcbd8e308 100644 --- a/src/xbt/mmalloc/mmprivate.h +++ b/src/xbt/mmalloc/mmprivate.h @@ -63,7 +63,7 @@ Boston, MA 02111-1307, USA. sign of the result is machine dependent for negative values, so force it to be treated as an unsigned int. */ -#define ADDR2UINT(addr) ((unsigned int) ((PTR) (addr) - (PTR) NULL)) +#define ADDR2UINT(addr) ((unsigned int) ((char*) (addr) - (char*) NULL)) #define RESIDUAL(addr,bsize) ((unsigned int) (ADDR2UINT (addr) % (bsize))) /* Determine the amount of memory spanned by the initial heap table @@ -85,9 +85,9 @@ Boston, MA 02111-1307, USA. /* Address to block number and vice versa. */ -#define BLOCK(A) (((PTR) (A) - mdp -> heapbase) / BLOCKSIZE + 1) +#define BLOCK(A) (((char*) (A) - (char*) mdp -> heapbase) / BLOCKSIZE + 1) -#define ADDRESS(B) ((PTR) (((B) - 1) * BLOCKSIZE + mdp -> heapbase)) +#define ADDRESS(B) ((PTR) (((ADDR2UINT(B)) - 1) * BLOCKSIZE + (char*) mdp -> heapbase)) /* Data structure giving per-block information. */ diff --git a/src/xbt/mmalloc/mmstats.c b/src/xbt/mmalloc/mmstats.c index ee8ee43e94..b96e6ceb52 100644 --- a/src/xbt/mmalloc/mmstats.c +++ b/src/xbt/mmalloc/mmstats.c @@ -37,7 +37,7 @@ mmstats (md) mdp = MD_TO_MDP (md); result.bytes_total = - (PTR) mdp -> top - (void *)mdp; + (char*) mdp -> top - (char*)mdp; result.chunks_used = mdp -> heapstats.chunks_used; result.bytes_used = mdp -> heapstats.bytes_used; result.chunks_free = mdp -> heapstats.chunks_free; diff --git a/src/xbt/mmalloc/mrealloc.c b/src/xbt/mmalloc/mrealloc.c index e2004aaf47..6e9470b929 100644 --- a/src/xbt/mmalloc/mrealloc.c +++ b/src/xbt/mmalloc/mrealloc.c @@ -145,6 +145,9 @@ mrealloc (md, ptr, size) return (result); } +/* Useless prototype to make gcc happy */ +void *realloc (void *ptr, size_t size); + /* When using this package, provide a version of malloc/realloc/free built on top of it, so that if we use the default sbrk() region we will not collide with another malloc package trying to do the same thing, if diff --git a/src/xbt/mmalloc/mvalloc.c b/src/xbt/mmalloc/mvalloc.c index e44942f5bb..95c19247ef 100644 --- a/src/xbt/mmalloc/mvalloc.c +++ b/src/xbt/mmalloc/mvalloc.c @@ -17,6 +17,7 @@ not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mmprivate.h" +#include /* Cache the pagesize for the current host machine. Note that if the host does not readily provide a getpagesize() function, we need to emulate it @@ -41,10 +42,11 @@ mvalloc (md, size) return (mmemalign (md, cache_pagesize, size)); } +/* Useless prototype to make gcc happy */ +PTR valloc (size_t size); PTR -valloc (size) - size_t size; +valloc (size_t size) { return mvalloc ((PTR) NULL, size); } diff --git a/src/xbt/mmalloc/sbrk-sup.c b/src/xbt/mmalloc/sbrk-sup.c index 10869bd5cb..0211031c96 100644 --- a/src/xbt/mmalloc/sbrk-sup.c +++ b/src/xbt/mmalloc/sbrk-sup.c @@ -53,8 +53,8 @@ sbrk_morecore (mdp, size) } else { - mdp -> breakval += size; - mdp -> top += size; + mdp -> breakval = (char*)mdp -> breakval + size; + mdp -> top = (char*)mdp -> top + size; } return (result); } -- 2.20.1