Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update mmalloc to compile with paranoid flags used in simgrid
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 5 May 2010 21:38:41 +0000 (21:38 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Wed, 5 May 2010 21:38:41 +0000 (21:38 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@7695 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/xbt/mmalloc/detach.c
src/xbt/mmalloc/mfree.c
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mmap-sup.c
src/xbt/mmalloc/mmemalign.c
src/xbt/mmalloc/mmprivate.h
src/xbt/mmalloc/mmstats.c
src/xbt/mmalloc/mrealloc.c
src/xbt/mmalloc/mvalloc.c
src/xbt/mmalloc/sbrk-sup.c

index 1780679..b5b5092 100644 (file)
@@ -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 <unistd.h>   /* close */
 #include <sys/types.h>
 #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 */
index a602355..d6f1cf9 100644 (file)
@@ -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);
 }
index a677000..ba63e37 100644 (file)
@@ -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;
index ccaf7bb..5c7db2a 100644 (file)
@@ -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) */
index 595cb6c..584f82c 100644 (file)
@@ -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);
index eccffec..2bcbd8e 100644 (file)
@@ -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.  */
 
index ee8ee43..b96e6ce 100644 (file)
@@ -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;
index e2004aa..6e9470b 100644 (file)
@@ -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
index e44942f..95c1924 100644 (file)
@@ -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 <unistd.h>
 
 /* 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);
 }
index 10869bd..0211031 100644 (file)
@@ -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);
 }