[gnu.emacs.bug] allocator bug fix

eric@snark.uu.net (08/19/89)

Here is a fix for the allocator bug I encountered. It separates the function
of initializing the allocator from the function of setting the allocator
warning hook (this is a good idea just on cleanliness grounds). The new
malloc_set_warning() entry point is used to disable warnings during the
very first malloc, preventing the lose.

I'm still getting a bus error, but at least now it's an honest one due to the
initial malloc() returning zero. Now I have to figure out why the *%$#!@ 
malloc code thinks it's run out of memory at *startup* time. Stay tuned...

*** malloc.c-orig	Sat Aug 19 10:38:56 1989
--- malloc.c	Sat Aug 19 11:22:27 1989
***************
*** 286,300 ****
  /* Cause reinitialization based on job parameters;
    also declare where the end of pure storage is. */
  void
! malloc_init (start, warnfun)
       char *start;
-      void (*warnfun) ();
  {
    if (start)
      data_space_start = start;
    lim_data = 0;
    warnlevel = 0;
!   warnfunction = warnfun;
  }
  
  /* Return the maximum size to which MEM can be realloc'd
--- 286,310 ----
  /* Cause reinitialization based on job parameters;
    also declare where the end of pure storage is. */
  void
! malloc_init (start)
       char *start;
  {
    if (start)
      data_space_start = start;
    lim_data = 0;
+ }
+ 
+ typedef void whook_t();
+ 
+ whook_t
+ *malloc_set_warning(warnhook)
+      void (*warnhook)();
+ {
+   void (*oldwarn)() = warnfunction;
+ 
    warnlevel = 0;
!   warnfunction = warnhook;
!   return(oldwarn);
  }
  
  /* Return the maximum size to which MEM can be realloc'd
*** alloc.c-orig	Sat Aug 19 10:31:52 1989
--- alloc.c	Sat Aug 19 11:09:28 1989
***************
*** 455,461 ****
--- 455,465 ----
  void
  init_strings ()
  {
+   extern void (*malloc_set_warning())();
+   void (*oldwarn)() = malloc_set_warning((void(*)())0);
+     
    current_string_block = (struct string_block *) malloc (sizeof (struct string_block));
+   (void) malloc_set_warning(oldwarn);
    first_string_block = current_string_block;
    consing_since_gc += sizeof (struct string_block);
    current_string_block->next = 0;
*** emacs.c-orig	Sat Aug 19 10:42:03 1989
--- emacs.c	Sat Aug 19 11:07:07 1989
***************
*** 173,178 ****
--- 173,179 ----
    int skip_args = 0;
    extern int errno;
    extern void malloc_warning ();
+   extern void (*malloc_set_warning())();
  
  #ifdef VMS
  #ifdef LINK_CRTL_SHARE
***************
*** 216,222 ****
  
  #ifndef SYSTEM_MALLOC
    /* Arrange for warnings when nearly out of space.  */
!   malloc_init (0, malloc_warning);
  #endif
  
  #ifdef HIGHPRI
--- 217,224 ----
  
  #ifndef SYSTEM_MALLOC
    /* Arrange for warnings when nearly out of space.  */
!   malloc_init (0);
!   (void) malloc_set_warning(malloc_warning);
  #endif
  
  #ifdef HIGHPRI
***************
*** 565,571 ****
    /* Tell malloc where start of impure now is */
    /* Also arrange for warnings when nearly out of space.  */
  #ifndef SYSTEM_MALLOC
!   malloc_init (&my_edata, malloc_warning);
  #endif
    unexec (XSTRING (intoname)->data, a_name, &my_edata, 0, 0);
  #endif /* not VMS */
--- 567,574 ----
    /* Tell malloc where start of impure now is */
    /* Also arrange for warnings when nearly out of space.  */
  #ifndef SYSTEM_MALLOC
!   malloc_init (&my_edata);
!   (void) malloc_set_warning(malloc_warning);
  #endif
    unexec (XSTRING (intoname)->data, a_name, &my_edata, 0, 0);
  #endif /* not VMS */

eric@snark.uu.net = eric%snark@uunet.uu.net     -->     Eric S. Raymond