(LIB_MOTIF): New definition.
[bpt/emacs.git] / src / ralloc.c
index 997faf8..179fd31 100644 (file)
@@ -1,11 +1,11 @@
 /* Block-relocating memory allocator. 
-   Copyright (C) 1993 Free Software Foundation, Inc.
+   Copyright (C) 1993, 1995 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
+the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -15,7 +15,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
 
 /* NOTES:
 
@@ -56,9 +57,9 @@ typedef unsigned long SIZE;
    overlap.  */
 extern void safe_bcopy ();
 
-#include "getpagesize.h"
+extern int __malloc_extra_blocks;
 
-#else  /* Not emacs.  */
+#else /* not emacs */
 
 #include <stddef.h>
 
@@ -70,8 +71,11 @@ typedef void *POINTER;
 #include <string.h>
 
 #define safe_bcopy(x, y, z) memmove (y, x, z)
+#define bzero(x, len) memset (x, 0, len)
+
+#endif /* not emacs */
 
-#endif /* emacs.  */
+#include "getpagesize.h"
 
 #define NIL ((POINTER) 0)
 
@@ -128,7 +132,7 @@ static int extra_bytes;
    but they never move.
 
    We try to make just one heap and make it larger as necessary.
-   But sometimes we can't do that, because we can't get continguous
+   But sometimes we can't do that, because we can't get contiguous
    space to add onto the heap.  When that happens, we start a new heap.  */
    
 typedef struct heap
@@ -143,6 +147,10 @@ typedef struct heap
   POINTER bloc_start;
   /* Start of unused space in this heap.  */
   POINTER free;
+  /* First bloc in this heap.  */
+  struct bp *first_bloc;
+  /* Last bloc in this heap.  */
+  struct bp *last_bloc;
 } *heap_ptr;
 
 #define NIL_HEAP ((heap_ptr) 0)
@@ -159,7 +167,13 @@ static heap_ptr first_heap, last_heap;
 /* These structures are allocated in the malloc arena.
    The linked list is kept in order of increasing '.data' members.
    The data blocks abut each other; if b->next is non-nil, then
-   b->data + b->size == b->next->data.  */
+   b->data + b->size == b->next->data.  
+
+   An element with variable==NIL denotes a freed block, which has not yet
+   been collected.  They may only appear while r_alloc_freeze > 0, and will be
+   freed when the arena is thawed.  Currently, these blocs are not reusable,
+   while the arena is frozen.  Very inefficient.  */
+
 typedef struct bp
 {
   struct bp *next;
@@ -167,7 +181,8 @@ typedef struct bp
   POINTER *variable;
   POINTER data;
   SIZE size;
-  POINTER new_data;            /* tmporarily used for relocation */
+  POINTER new_data;            /* temporarily used for relocation */
+  struct heap *heap;           /* Heap this bloc is in.  */
 } *bloc_ptr;
 
 #define NIL_BLOC ((bloc_ptr) 0)
@@ -176,6 +191,11 @@ typedef struct bp
 /* Head and tail of the list of relocatable blocs.  */
 static bloc_ptr first_bloc, last_bloc;
 
+static int use_relocatable_buffers;
+
+/* If >0, no relocation whatsoever takes place.  */
+static int r_alloc_freeze_level;
+
 \f
 /* Functions to get and return memory from the system.  */
 
@@ -201,8 +221,8 @@ find_heap (address)
    if we can get that many within one heap.
 
    If enough space is not presently available in our reserve, this means
-   getting more page-aligned space from the system. If the retuned space
-   is not contiguos to the last heap, allocate a new heap, and append it
+   getting more page-aligned space from the system.  If the returned space
+   is not contiguous to the last heap, allocate a new heap, and append it
 
    obtain does not try to keep track of whether space is in use
    or not in use.  It just returns the address of SIZE bytes that
@@ -267,6 +287,8 @@ obtain (address, size)
          new_heap->free = bloc_start;
          new_heap->next = NIL_HEAP;
          new_heap->prev = last_heap;
+         new_heap->first_bloc = NIL_BLOC;
+         new_heap->last_bloc = NIL_BLOC;
          last_heap->next = new_heap;
          last_heap = new_heap;
 
@@ -318,6 +340,11 @@ relinquish ()
 
       if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess)
        {
+         /* This heap should have no blocs in it.  */
+         if (last_heap->first_bloc != NIL_BLOC
+             || last_heap->last_bloc != NIL_BLOC)
+           abort ();
+
          /* Return the last heap, with its header, to the system.  */
          excess = (char *)last_heap->end - (char *)last_heap->start;
          last_heap = last_heap->prev;
@@ -334,6 +361,15 @@ relinquish ()
        abort ();
     }
 }
+
+/* Return the total size in use by relocating allocator,
+   above where malloc gets space.  */
+
+long
+r_alloc_size_in_use ()
+{
+  return break_value - virtual_break_value;
+}
 \f
 /* The meat - allocating, freeing, and relocating blocs.  */
 
@@ -388,6 +424,12 @@ get_bloc (size)
   heap = find_heap (new_bloc->data);
   heap->free = break_value;
 
+  /* Maintain the correspondence between heaps and blocs.  */
+  new_bloc->heap = heap;
+  heap->last_bloc = new_bloc;
+  if (heap->first_bloc == NIL_BLOC)
+    heap->first_bloc = new_bloc;
+
   /* Put this bloc on the doubly-linked list of blocs.  */
   if (first_bloc)
     {
@@ -403,7 +445,7 @@ get_bloc (size)
 
   return new_bloc;
 }
-
+\f
 /* Calculate new locations of blocs in the list beginning with BLOC,
    relocating it to start at ADDRESS, in heap HEAP.  If enough space is
    not presently available in our reserve, call obtain for
@@ -420,6 +462,10 @@ relocate_blocs (bloc, heap, address)
 {
   register bloc_ptr b = bloc;
 
+  /* No need to ever call this if arena is frozen, bug somewhere!  */
+  if (r_alloc_freeze_level) 
+    abort();
+
   while (b)
     {
       /* If bloc B won't fit within HEAP,
@@ -442,7 +488,9 @@ relocate_blocs (bloc, heap, address)
          /* Add up the size of all the following blocs.  */
          while (tb != NIL_BLOC)
            {
-             s += tb->size;
+             if (tb->variable) 
+               s += tb->size;
+
              tb = tb->next;
            }
 
@@ -457,49 +505,108 @@ relocate_blocs (bloc, heap, address)
       /* Record the new address of this bloc
         and update where the next bloc can start.  */
       b->new_data = address;
-      address += b->size;
+      if (b->variable) 
+       address += b->size;
       b = b->next;
     }
 
   return 1;
 }
 
-/* Update the free pointers of all heaps starting with HEAP
-   based on the blocs starting with BLOC.  BLOC should be in
-   heap HEAP.  */
+/* Reorder the bloc BLOC to go before bloc BEFORE in the doubly linked list.
+   This is necessary if we put the memory of space of BLOC
+   before that of BEFORE.  */
 
-static
-update_heap_free_pointers (bloc, heap)
+static void
+reorder_bloc (bloc, before)
+     bloc_ptr bloc, before;
+{
+  bloc_ptr prev, next;
+
+  /* Splice BLOC out from where it is.  */
+  prev = bloc->prev;
+  next = bloc->next;
+
+  if (prev)
+    prev->next = next;
+  if (next)
+    next->prev = prev;
+
+  /* Splice it in before BEFORE.  */
+  prev = before->prev;
+
+  if (prev)
+    prev->next = bloc;
+  bloc->prev = prev;
+
+  before->prev = bloc;
+  bloc->next = before;
+}
+\f
+/* Update the records of which heaps contain which blocs, starting
+   with heap HEAP and bloc BLOC.  */
+
+static void
+update_heap_bloc_correspondence (bloc, heap)
      bloc_ptr bloc;
      heap_ptr heap;
 {
   register bloc_ptr b;
 
+  /* Initialize HEAP's status to reflect blocs before BLOC.  */
+  if (bloc != NIL_BLOC && bloc->prev != NIL_BLOC && bloc->prev->heap == heap)
+    {
+      /* The previous bloc is in HEAP.  */
+      heap->last_bloc = bloc->prev;
+      heap->free = bloc->prev->data + bloc->prev->size;
+    }
+  else
+    {
+      /* HEAP contains no blocs before BLOC.  */
+      heap->first_bloc = NIL_BLOC;
+      heap->last_bloc = NIL_BLOC;
+      heap->free = heap->bloc_start;
+    }
+
   /* Advance through blocs one by one.  */
   for (b = bloc; b != NIL_BLOC; b = b->next)
     {
-      /* Advance through heaps in sync with the blocs that are in them.  */
+      /* Advance through heaps, marking them empty,
+        till we get to the one that B is in.  */
       while (heap)
        {
          if (heap->bloc_start <= b->data && b->data <= heap->end)
            break;
          heap = heap->next;
+         /* We know HEAP is not null now,
+            because there has to be space for bloc B.  */
+         heap->first_bloc = NIL_BLOC;
+         heap->last_bloc = NIL_BLOC;
          heap->free = heap->bloc_start;
        }
-      /* In each heap, record the end of the last bloc in it.  */
+
+      /* Update HEAP's status for bloc B.  */
       heap->free = b->data + b->size;
+      heap->last_bloc = b;
+      if (heap->first_bloc == NIL_BLOC)
+       heap->first_bloc = b;
+
+      /* Record that B is in HEAP.  */
+      b->heap = heap;
     }
 
   /* If there are any remaining heaps and no blocs left,
-     update the `free' slot assuming they contain no blocs.  */
+     mark those heaps as empty.  */
   heap = heap->next;
   while (heap)
     {
+      heap->first_bloc = NIL_BLOC;
+      heap->last_bloc = NIL_BLOC;
       heap->free = heap->bloc_start;
       heap = heap->next;
     }
 }
-
+\f
 /* Resize BLOC to SIZE bytes.  This relocates the blocs
    that come after BLOC in memory.  */
 
@@ -513,6 +620,10 @@ resize_bloc (bloc, size)
   POINTER address;
   SIZE old_size;
 
+  /* No need to ever call this if arena is frozen, bug somewhere!  */
+  if (r_alloc_freeze_level) 
+    abort();
+
   if (bloc == NIL_BLOC || size == bloc->size)
     return 1;
 
@@ -548,29 +659,53 @@ resize_bloc (bloc, size)
     {
       for (b = last_bloc; b != bloc; b = b->prev)
        {
-         safe_bcopy (b->data, b->new_data, b->size);
-         *b->variable = b->data = b->new_data;
+         if (!b->variable)
+           {
+             b->size = 0;
+             b->data = b->new_data;
+            } 
+         else 
+           {
+             safe_bcopy (b->data, b->new_data, b->size);
+             *b->variable = b->data = b->new_data;
+            }
+       }
+      if (!bloc->variable)
+       {
+         bloc->size = 0;
+         bloc->data = bloc->new_data;
+       }
+      else
+       {
+         safe_bcopy (bloc->data, bloc->new_data, old_size);
+         bzero (bloc->new_data + old_size, size - old_size);
+         *bloc->variable = bloc->data = bloc->new_data;
        }
-      safe_bcopy (bloc->data, bloc->new_data, old_size);
-      bzero (bloc->new_data + old_size, size - old_size);
-      *bloc->variable = bloc->data = bloc->new_data;
     }
   else
     {
       for (b = bloc; b != NIL_BLOC; b = b->next)
        {
-         safe_bcopy (b->data, b->new_data, b->size);
-         *b->variable = b->data = b->new_data;
+         if (!b->variable)
+           {
+             b->size = 0;
+             b->data = b->new_data;
+            } 
+         else 
+           {
+             safe_bcopy (b->data, b->new_data, b->size);
+             *b->variable = b->data = b->new_data;
+           }
        }
     }
 
-  update_heap_free_pointers (bloc, heap);
+  update_heap_bloc_correspondence (bloc, heap);
 
   break_value = (last_bloc ? last_bloc->data + last_bloc->size
                 : first_heap->bloc_start);
   return 1;
 }
-
+\f
 /* Free BLOC from the chain of blocs, relocating any blocs above it.
    This may return space to the system.  */
 
@@ -578,6 +713,14 @@ static void
 free_bloc (bloc)
      bloc_ptr bloc;
 {
+  heap_ptr heap = bloc->heap;
+
+  if (r_alloc_freeze_level)
+    {
+      bloc->variable = (POINTER *) NIL;
+      return;
+    }
+  
   resize_bloc (bloc, 0);
 
   if (bloc == first_bloc && bloc == last_bloc)
@@ -600,15 +743,28 @@ free_bloc (bloc)
       bloc->prev->next = bloc->next;
     }
 
+  /* Update the records of which blocs are in HEAP.  */
+  if (heap->first_bloc == bloc)
+    {
+      if (bloc->next != 0 && bloc->next->heap == heap)
+       heap->first_bloc = bloc->next;
+      else
+       heap->first_bloc = heap->last_bloc = NIL_BLOC;
+    }
+  if (heap->last_bloc == bloc)
+    {
+      if (bloc->prev != 0 && bloc->prev->heap == heap)
+       heap->last_bloc = bloc->prev;
+      else
+       heap->first_bloc = heap->last_bloc = NIL_BLOC;
+    }
+
   relinquish ();
   free (bloc);
 }
 \f
 /* Interface routines.  */
 
-static int use_relocatable_buffers;
-static int r_alloc_freeze_level;
-
 /* Obtain SIZE bytes of storage from the free pool, or the system, as
    necessary.  If relocatable blocs are in use, this means relocating
    them.  This function gets plugged into the GNU malloc's __morecore
@@ -627,6 +783,9 @@ r_alloc_sbrk (size)
   register bloc_ptr b;
   POINTER address;
 
+  if (! r_alloc_initialized)
+    r_alloc_init ();
+
   if (! use_relocatable_buffers)
     return (*real_morecore) (size);
 
@@ -637,7 +796,7 @@ r_alloc_sbrk (size)
     {
       /* Allocate a page-aligned space.  GNU malloc would reclaim an
         extra space if we passed an unaligned one.  But we could
-        not always find a space which is contiguos to the previous.  */
+        not always find a space which is contiguous to the previous.  */
       POINTER new_bloc_start;
       heap_ptr h = first_heap;
       SIZE get = ROUNDUP (size);
@@ -658,7 +817,7 @@ r_alloc_sbrk (size)
        {
          get += extra_bytes + page_size;
 
-         if (r_alloc_freeze_level > 0 || ! obtain (address, get))
+         if (! obtain (address, get))
            return 0;
 
          if (first_heap == last_heap)
@@ -672,9 +831,16 @@ r_alloc_sbrk (size)
 
       if (first_heap->bloc_start < new_bloc_start)
        {
+         /* This is no clean solution - no idea how to do it better.  */
+         if (r_alloc_freeze_level) 
+           return NIL;
+
+         /* There is a bug here: if the above obtain call succeeded, but the
+            relocate_blocs call below does not succeed, we need to free
+            the memory that we got with obtain.  */
+
          /* Move all blocs upward.  */
-         if (r_alloc_freeze_level > 0
-             || ! relocate_blocs (first_bloc, h, new_bloc_start))
+         if (! relocate_blocs (first_bloc, h, new_bloc_start))
            return 0;
 
          /* Note that (POINTER)(h+1) <= new_bloc_start since
@@ -688,9 +854,8 @@ r_alloc_sbrk (size)
 
          h->bloc_start = new_bloc_start;
 
-         update_heap_free_pointers (first_bloc, h);
+         update_heap_bloc_correspondence (first_bloc, h);
        }
-
       if (h != first_heap)
        {
          /* Give up managing heaps below the one the new
@@ -700,6 +865,8 @@ r_alloc_sbrk (size)
          first_heap->start = h->start;
          first_heap->end = h->end;
          first_heap->free = h->free;
+         first_heap->first_bloc = h->first_bloc;
+         first_heap->last_bloc = h->last_bloc;
          first_heap->bloc_start = h->bloc_start;
 
          if (first_heap->next)
@@ -721,7 +888,7 @@ r_alloc_sbrk (size)
        {
          excess -= extra_bytes;
          first_heap->bloc_start
-             = (POINTER) MEM_ROUNDUP ((char *)first_heap->bloc_start - excess);
+           = (POINTER) MEM_ROUNDUP ((char *)first_heap->bloc_start - excess);
 
          relocate_blocs (first_bloc, first_heap, first_heap->bloc_start);
 
@@ -740,8 +907,9 @@ r_alloc_sbrk (size)
     }
 
   virtual_break_value = (POINTER) ((char *)address + size);
-  break_value = last_bloc ? last_bloc->data + last_bloc->size
-                   : first_heap->bloc_start;
+  break_value = (last_bloc
+                ? last_bloc->data + last_bloc->size
+                : first_heap->bloc_start);
   if (size < 0)
     relinquish ();
 
@@ -752,6 +920,10 @@ r_alloc_sbrk (size)
    the data is returned in *PTR.  PTR is thus the address of some variable
    which will use the data area.
 
+   The allocation of 0 bytes is valid.
+   In case r_alloc_freeze is set, a best fit of unused blocs could be done
+   before allocating a new area.  Not yet done.
+
    If we can't allocate the necessary memory, set *PTR to zero, and
    return zero.  */
 
@@ -786,12 +958,19 @@ r_alloc_free (ptr)
 {
   register bloc_ptr dead_bloc;
 
+  if (! r_alloc_initialized)
+    r_alloc_init ();
+
   dead_bloc = find_bloc (ptr);
   if (dead_bloc == NIL_BLOC)
     abort ();
 
   free_bloc (dead_bloc);
   *ptr = 0;
+
+#ifdef emacs
+  refill_memory_reserve ();
+#endif
 }
 
 /* Given a pointer at address PTR to relocatable data, resize it to SIZE.
@@ -799,6 +978,10 @@ r_alloc_free (ptr)
    SIZE is less than or equal to the current bloc size, in which case
    do nothing.
 
+   In case r_alloc_freeze is set, a new bloc is allocated, and the
+   memory copied to it.  Not very efficient.  We could traverse the
+   bloc_list for a best fit of free blocs first.
+
    Change *PTR to reflect the new bloc, and return this value.
 
    If more memory cannot be allocated, then leave *PTR unchanged, and
@@ -811,17 +994,54 @@ r_re_alloc (ptr, size)
 {
   register bloc_ptr bloc;
 
+  if (! r_alloc_initialized)
+    r_alloc_init ();
+
+  if (!*ptr)
+    return r_alloc (ptr, size);
+  if (!size) 
+    {
+      r_alloc_free (ptr);
+      return r_alloc (ptr, 0);
+    }
+
   bloc = find_bloc (ptr);
   if (bloc == NIL_BLOC)
     abort ();
 
-  if (size <= bloc->size)
-    /* Wouldn't it be useful to actually resize the bloc here?  */
-    return *ptr;
-
-  if (! resize_bloc (bloc, MEM_ROUNDUP (size)))
-    return 0;
-
+  if (size < bloc->size) 
+    {
+      /* Wouldn't it be useful to actually resize the bloc here?  */
+      /* I think so too, but not if it's too expensive...  */
+      if ((bloc->size - MEM_ROUNDUP (size) >= page_size) 
+          && r_alloc_freeze_level == 0) 
+       {
+         resize_bloc (bloc, MEM_ROUNDUP (size));
+         /* Never mind if this fails, just do nothing...  */
+         /* It *should* be infallible!  */
+       }
+    }
+  else if (size > bloc->size)
+    {
+      if (r_alloc_freeze_level)
+       {
+         bloc_ptr new_bloc;
+         new_bloc = get_bloc (MEM_ROUNDUP (size));
+         if (new_bloc)
+           {
+             new_bloc->variable = ptr;
+             *ptr = new_bloc->data;
+             bloc->variable = (POINTER *) NIL;
+           }
+          else
+           return NIL;
+       }
+      else 
+       {
+         if (! resize_bloc (bloc, MEM_ROUNDUP (size)))
+           return NIL;
+        }
+    }
   return *ptr;
 }
 
@@ -834,6 +1054,9 @@ void
 r_alloc_freeze (size)
      long size;
 {
+  if (! r_alloc_initialized)
+    r_alloc_init ();
+
   /* If already frozen, we can't make any more room, so don't try.  */
   if (r_alloc_freeze_level > 0)
     size = 0;
@@ -848,9 +1071,27 @@ r_alloc_freeze (size)
 void
 r_alloc_thaw ()
 {
+
+  if (! r_alloc_initialized) 
+    r_alloc_init ();
+
   if (--r_alloc_freeze_level < 0)
     abort ();
+
+  /* This frees all unused blocs.  It is not too inefficient, as the resize 
+     and bcopy is done only once.  Afterwards, all unreferenced blocs are 
+     already shrunk to zero size.  */
+  if (!r_alloc_freeze_level) 
+    {
+      bloc_ptr *b = &first_bloc;
+      while (*b) 
+       if (!(*b)->variable) 
+         free_bloc (*b); 
+       else 
+         b = &(*b)->next;
+    }
 }
+
 \f
 /* The hook `malloc' uses for the function which gets more space
    from the system.  */
@@ -861,8 +1102,6 @@ extern POINTER (*__morecore) ();
 static void
 r_alloc_init ()
 {
-  POINTER end;
-
   if (r_alloc_initialized)
     return;
 
@@ -880,6 +1119,10 @@ r_alloc_init ()
   page_size = PAGE;
   extra_bytes = ROUNDUP (50000);
 
+  /* Give GNU malloc's morecore some hysteresis
+     so that we move all the relocatable blocks much less often.  */
+  __malloc_extra_blocks = 64;
+
   first_heap->end = (POINTER) ROUNDUP (first_heap->start);
 
   /* The extra call to real_morecore guarantees that the end of the
@@ -901,87 +1144,91 @@ r_alloc_init ()
 #ifdef DEBUG
 #include <assert.h>
 
-int
+void
 r_alloc_check ()
 {
-    int found = 0;
-    heap_ptr h, ph = 0;
-    bloc_ptr b, pb = 0;
+  int found = 0;
+  heap_ptr h, ph = 0;
+  bloc_ptr b, pb = 0;
 
-    if (!r_alloc_initialized)
-      return;
+  if (!r_alloc_initialized)
+    return;
+
+  assert (first_heap);
+  assert (last_heap->end <= (POINTER) sbrk (0));
+  assert ((POINTER) first_heap < first_heap->start);
+  assert (first_heap->start <= virtual_break_value);
+  assert (virtual_break_value <= first_heap->end);
+
+  for (h = first_heap; h; h = h->next)
+    {
+      assert (h->prev == ph);
+      assert ((POINTER) ROUNDUP (h->end) == h->end);
+#if 0 /* ??? The code in ralloc.c does not really try to ensure
+        the heap start has any sort of alignment.
+        Perhaps it should.  */
+      assert ((POINTER) MEM_ROUNDUP (h->start) == h->start);
+#endif
+      assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start);
+      assert (h->start <= h->bloc_start && h->bloc_start <= h->end);
+
+      if (ph)
+       {
+         assert (ph->end < h->start);
+         assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start);
+       }
+
+      if (h->bloc_start <= break_value && break_value <= h->end)
+       found = 1;
 
-    assert (first_heap);
-    assert (last_heap->end <= (POINTER) sbrk (0));
-    assert ((POINTER) first_heap < first_heap->start);
-    assert (first_heap->start <= virtual_break_value);
-    assert (virtual_break_value <= first_heap->end);
-
-    for (h = first_heap; h; h = h->next)
-      {
-       assert (h->prev == ph);
-       assert ((POINTER) ROUNDUP (h->end) == h->end);
-       assert ((POINTER) MEM_ROUNDUP (h->start) == h->start);
-       assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start);
-       assert (h->start <= h->bloc_start && h->bloc_start <= h->end);
-
-       if (ph)
-         {
-           assert (ph->end < h->start);
-           assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start);
-         }
-
-       if (h->bloc_start <= break_value && break_value <= h->end)
-           found = 1;
-
-       ph = h;
-      }
-
-    assert (found);
-    assert (last_heap == ph);
-
-    for (b = first_bloc; b; b = b->next)
-      {
-       assert (b->prev == pb);
-       assert ((POINTER) MEM_ROUNDUP (b->data) == b->data);
-       assert ((SIZE) MEM_ROUNDUP (b->size) == b->size);
-
-       ph = 0;
-       for (h = first_heap; h; h = h->next)
-         {
-           if (h->bloc_start <= b->data && b->data + b->size <= h->end)
-               break;
-           ph = h;
-         }
-
-       assert (h);
-
-       if (pb && pb->data + pb->size != b->data)
-         {
-           assert (ph && b->data == h->bloc_start);
-           while (ph)
-             {
-               if (ph->bloc_start <= pb->data
-                   && pb->data + pb->size <= ph->end)
-                 {
-                   assert (pb->data + pb->size + b->size > ph->end);
-                   break;
-                 }
-               else
-                 {
-                   assert (ph->bloc_start + b->size > ph->end);
-                 }
-               ph = ph->prev;
-             }
-         }
-       pb = b;
-      }
-
-    assert (last_bloc == pb);
-
-    if (last_bloc)
-       assert (last_bloc->data + last_bloc->size == break_value);
-    else
-       assert (first_heap->bloc_start == break_value);
+      ph = h;
+    }
+
+  assert (found);
+  assert (last_heap == ph);
+
+  for (b = first_bloc; b; b = b->next)
+    {
+      assert (b->prev == pb);
+      assert ((POINTER) MEM_ROUNDUP (b->data) == b->data);
+      assert ((SIZE) MEM_ROUNDUP (b->size) == b->size);
+
+      ph = 0;
+      for (h = first_heap; h; h = h->next)
+       {
+         if (h->bloc_start <= b->data && b->data + b->size <= h->end)
+           break;
+         ph = h;
+       }
+
+      assert (h);
+
+      if (pb && pb->data + pb->size != b->data)
+       {
+         assert (ph && b->data == h->bloc_start);
+         while (ph)
+           {
+             if (ph->bloc_start <= pb->data
+                 && pb->data + pb->size <= ph->end)
+               {
+                 assert (pb->data + pb->size + b->size > ph->end);
+                 break;
+               }
+             else
+               {
+                 assert (ph->bloc_start + b->size > ph->end);
+               }
+             ph = ph->prev;
+           }
+       }
+      pb = b;
+    }
+
+  assert (last_bloc == pb);
+
+  if (last_bloc)
+    assert (last_bloc->data + last_bloc->size == break_value);
+  else
+    assert (first_heap->bloc_start == break_value);
 }
 #endif /* DEBUG */