merge from gcc
[deliverable/binutils-gdb.git] / mmalloc / mmalloc.c
index 885a8ea643ca7c10ff790f540f753a1347d3e99c..7c60fe2d57b95bbc9ea8751e8d1df7399800058f 100644 (file)
@@ -2,7 +2,7 @@
    Copyright 1990, 1991, 1992 Free Software Foundation
 
    Written May 1989 by Mike Haertel.
-   Heavily modified Mar 1992 by Fred Fish for mmap'c version.
+   Heavily modified Mar 1992 by Fred Fish for mmap'd version.
 
 The GNU C Library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Library General Public License as
@@ -16,13 +16,15 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation. */
 
-#include "mmalloc.h"
+#include <string.h>    /* Prototypes for memcpy, memmove, memset, etc */
+
+#include "mmprivate.h"
 
 /* Prototypes for local functions */
 
@@ -45,7 +47,7 @@ align (mdp, size)
   if (adj != 0)
     {
       adj = BLOCKSIZE - adj;
-      (void) mdp -> morecore (mdp, adj);
+      mdp -> morecore (mdp, adj);
       result = (char *) result + adj;
     }
   return (result);
@@ -105,8 +107,8 @@ morecore (mdp, size)
          mdp -> morecore (mdp, -size);
          return (NULL);
        }
-      memset ((PTR)newinfo, 0, newsize * sizeof (malloc_info));
-      memcpy ((PTR)newinfo, (PTR)mdp -> heapinfo,
+      memset ((PTR) newinfo, 0, newsize * sizeof (malloc_info));
+      memcpy ((PTR) newinfo, (PTR) mdp -> heapinfo,
              mdp -> heapsize * sizeof (malloc_info));
       oldinfo = mdp -> heapinfo;
       newinfo[BLOCK (oldinfo)].busy.type = 0;
@@ -256,7 +258,12 @@ mmalloc (md, size)
                  mdp -> morecore (mdp, 0) == ADDRESS(block + lastblocks) &&
                  (morecore (mdp, (blocks - lastblocks) * BLOCKSIZE)) != NULL)
                {
-                 mdp -> heapinfo[block].free.size = blocks;
+                 /* Which block we are extending (the `final free
+                    block' referred to above) might have changed, if
+                    it got combined with a freed info table.  */
+                 block = mdp -> heapinfo[0].free.prev;
+
+                 mdp -> heapinfo[block].free.size += (blocks - lastblocks);
                  mdp -> heapstats.bytes_free +=
                      (blocks - lastblocks) * BLOCKSIZE;
                  continue;
@@ -323,5 +330,8 @@ PTR
 malloc (size)
   size_t size;
 {
-  return (mmalloc ((void *) NULL, size));
+  PTR result;
+
+  result = mmalloc ((PTR) NULL, size);
+  return (result);
 }
This page took 0.030264 seconds and 4 git commands to generate.