(X_WINDOWS_SUPPORT): Don't include term/x-win.
[bpt/emacs.git] / src / ralloc.c
index 47300ef..50b1af8 100644 (file)
@@ -1,5 +1,5 @@
 /* Block-relocating memory allocator. 
-   Copyright (C) 1992 Free Software Foundation, Inc.
+   Copyright (C) 1993 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -19,13 +19,13 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 /* NOTES:
 
-   Only relocate the blocs neccessary for SIZE in r_alloc_sbrk,
+   Only relocate the blocs necessary for SIZE in r_alloc_sbrk,
    rather than all of them.  This means allowing for a possible
    hole between the first bloc and the end of malloc storage. */
 
 #ifdef emacs
 
-#include "config.h"
+#include <config.h>
 #include "lisp.h"              /* Needed for VALBITS.  */
 
 #undef NULL
@@ -33,6 +33,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 /* The important properties of this type are that 1) it's a pointer, and
    2) arithmetic on it should work as if the size of the object pointed
    to has a size of 1.  */
+#if 0 /* Arithmetic on void* is a GCC extension.  */
 #ifdef __STDC__
 typedef void *POINTER;
 #else
@@ -44,6 +45,10 @@ typedef void *POINTER;
 typedef char *POINTER;
 
 #endif
+#endif /* 0 */
+
+/* Unconditionally use char * for this.  */
+typedef char *POINTER;
 
 typedef unsigned long SIZE;
 
@@ -104,8 +109,9 @@ static int extra_bytes;
 /* Macros for rounding.  Note that rounding to any value is possible
    by changing the definition of PAGE. */
 #define PAGE (getpagesize ())
-#define ALIGNED(addr) (((unsigned int) (addr) & (page_size - 1)) == 0)
-#define ROUNDUP(size) (((unsigned int) (size) + page_size - 1) & ~(page_size - 1))
+#define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0)
+#define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \
+                      & ~(page_size - 1))
 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
 \f
 /* Functions to get and return memory from the system.  */
@@ -346,7 +352,10 @@ r_alloc_sbrk (size)
   /* This is the first address not currently available for the heap.  */
   POINTER top;
   /* Amount of empty space below that.  */
-  SIZE already_available;
+  /* It is not correct to use SIZE here, because that is usually unsigned.
+     ptrdiff_t would be okay, but is not always available.
+     `long' will work in all cases, in practice.  */
+  long already_available;
   POINTER ptr;
 
   if (! use_relocatable_buffers)
@@ -477,7 +486,7 @@ r_re_alloc (ptr, size)
    from the system.  */
 extern POINTER (*__morecore) ();
 
-/* Intialize various things for memory allocation. */
+/* Initialize various things for memory allocation. */
 
 static void
 r_alloc_init ()
@@ -497,8 +506,20 @@ r_alloc_init ()
   extra_bytes = ROUNDUP (50000);
 
   page_break_value = (POINTER) ROUNDUP (break_value);
+
+  /* The extra call to real_morecore guarantees that the end of the
+     address space is a multiple of page_size, even if page_size is
+     not really the page size of the system running the binary in
+     which page_size is stored.  This allows a binary to be built on a
+     system with one page size and run on a system with a smaller page
+     size. */
+  (*real_morecore) (page_break_value - break_value);
+
   /* Clear the rest of the last page; this memory is in our address space
      even though it is after the sbrk value.  */
+  /* Doubly true, with the additional call that explicitly adds the
+     rest of that page to the address space.  */
   bzero (break_value, (page_break_value - break_value));
+  virtual_break_value = break_value = page_break_value;
   use_relocatable_buffers = 1;
 }