Include shellapi.h.
[bpt/emacs.git] / src / ralloc.c
index 9645bfd..183db75 100644 (file)
@@ -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,7 +57,12 @@ typedef unsigned long SIZE;
    overlap.  */
 extern void safe_bcopy ();
 
+#ifdef DOUG_LEA_MALLOC
+#define M_TOP_PAD           -2 
+extern int mallopt ();
+#else
 extern int __malloc_extra_blocks;
+#endif
 
 #else /* not emacs */
 
@@ -357,7 +363,18 @@ relinquish ()
        }
 
       if ((*real_morecore) (- excess) == 0)
-       abort ();
+       {
+         /* If the system didn't want that much memory back, adjust
+             the end of the last heap to reflect that.  This can occur
+             if break_value is still within the original data segment.  */
+         last_heap->end += excess;
+         /* Make sure that the result of the adjustment is accurate.
+             It should be, for the else clause above; the other case,
+             which returns the entire last heap to the system, seems
+             unlikely to trigger this mode of failure.  */
+         if (last_heap->end != (*real_morecore) (0))
+           abort ();
+       }
     }
 }
 
@@ -1118,9 +1135,13 @@ r_alloc_init ()
   page_size = PAGE;
   extra_bytes = ROUNDUP (50000);
 
+#ifdef DOUG_LEA_MALLOC
+    mallopt (M_TOP_PAD, 64 * 4096);
+#else
   /* Give GNU malloc's morecore some hysteresis
      so that we move all the relocatable blocks much less often.  */
   __malloc_extra_blocks = 64;
+#endif
 
   first_heap->end = (POINTER) ROUNDUP (first_heap->start);
 
@@ -1140,6 +1161,24 @@ r_alloc_init ()
   virtual_break_value = break_value = first_heap->bloc_start = first_heap->end;
   use_relocatable_buffers = 1;
 }
+
+#if defined (emacs) && defined (DOUG_LEA_MALLOC)
+
+/* Reinitialize the morecore hook variables after restarting a dumped
+   Emacs.  This is needed when using Doug Lea's malloc from GNU libc.  */
+void
+r_alloc_reinit ()
+{
+  /* Only do this if the hook has been reset, so that we don't get an
+     infinite loop, in case Emacs was linked statically.  */
+  if (__morecore != r_alloc_sbrk)
+    {
+      real_morecore = __morecore;
+      __morecore = r_alloc_sbrk;
+    }
+}
+#endif
+
 #ifdef DEBUG
 #include <assert.h>
 
@@ -1163,7 +1202,11 @@ r_alloc_check ()
     {
       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);