emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/unexmacosx.c


From: YAMAMOTO Mitsuharu
Subject: [Emacs-diffs] Changes to emacs/src/unexmacosx.c
Date: Fri, 13 May 2005 04:41:04 -0400

Index: emacs/src/unexmacosx.c
diff -c emacs/src/unexmacosx.c:1.10 emacs/src/unexmacosx.c:1.11
*** emacs/src/unexmacosx.c:1.10 Fri Oct  8 18:38:17 2004
--- emacs/src/unexmacosx.c      Fri May 13 08:41:03 2005
***************
*** 105,110 ****
--- 105,112 ----
  #include <objc/malloc.h>
  #endif
  
+ #include <assert.h>
+ 
  
  #define VERBOSE 1
  
***************
*** 998,1003 ****
--- 1000,1022 ----
    malloc_set_zone_name (emacs_zone, "EmacsZone");
  }
  
+ #ifndef MACOSX_MALLOC_MULT16
+ #define MACOSX_MALLOC_MULT16 1
+ #endif
+ 
+ typedef struct unexec_malloc_header {
+   union {
+     char c[8];
+     size_t size;
+   } u;
+ } unexec_malloc_header_t;
+ 
+ #if MACOSX_MALLOC_MULT16
+ 
+ #define ptr_in_unexec_regions(p) ((((vm_address_t) (p)) & 8) != 0)
+ 
+ #else
+ 
  int
  ptr_in_unexec_regions (void *ptr)
  {
***************
*** 1011,1046 ****
    return 0;
  }
  
  void *
  unexec_malloc (size_t size)
  {
    if (in_dumped_exec)
!     return malloc (size);
    else
!     return malloc_zone_malloc (emacs_zone, size);
  }
  
  void *
  unexec_realloc (void *old_ptr, size_t new_size)
  {
    if (in_dumped_exec)
!     if (ptr_in_unexec_regions (old_ptr))
!       {
!       char *p = malloc (new_size);
!       /* 2002-04-15 T. Ikegami <address@hidden>.  The original
!          code to get size failed to reallocate read_buffer
!          (lread.c).  */
!       int old_size = malloc_default_zone()->size (emacs_zone, old_ptr);
!       int size = new_size > old_size ? old_size : new_size;
! 
!       if (size)
!         memcpy (p, old_ptr, size);
!       return p;
!       }
!     else
!       return realloc (old_ptr, new_size);
    else
!     return malloc_zone_realloc (emacs_zone, old_ptr, new_size);
  }
  
  void
--- 1030,1104 ----
    return 0;
  }
  
+ #endif
+ 
  void *
  unexec_malloc (size_t size)
  {
    if (in_dumped_exec)
!     {
!       void *p;
! 
!       p = malloc (size);
! #if MACOSX_MALLOC_MULT16
!       assert (((vm_address_t) p % 16) == 0);
! #endif
!       return p;
!     }
    else
!     {
!       unexec_malloc_header_t *ptr;
! 
!       ptr = (unexec_malloc_header_t *)
!       malloc_zone_malloc (emacs_zone, size + sizeof (unexec_malloc_header_t));
!       ptr->u.size = size;
!       ptr++;
! #if MACOSX_MALLOC_MULT16
!       assert (((vm_address_t) ptr % 16) == 8);
! #endif
!       return (void *) ptr;
!     }
  }
  
  void *
  unexec_realloc (void *old_ptr, size_t new_size)
  {
    if (in_dumped_exec)
!     {
!       void *p;
! 
!       if (ptr_in_unexec_regions (old_ptr))
!       {
!         p = (size_t *) malloc (new_size);
!         size_t old_size = ((unexec_malloc_header_t *) old_ptr)[-1].u.size;
!         size_t size = new_size > old_size ? old_size : new_size;
! 
!         if (size)
!           memcpy (p, old_ptr, size);
!       }
!       else
!       {
!         p = realloc (old_ptr, new_size);
!       }
! #if MACOSX_MALLOC_MULT16
!       assert (((vm_address_t) p % 16) == 0);
! #endif
!       return p;
!     }
    else
!     {
!       unexec_malloc_header_t *ptr;
! 
!       ptr = (unexec_malloc_header_t *)
!       malloc_zone_realloc (emacs_zone, (unexec_malloc_header_t *) old_ptr - 1,
!                            new_size + sizeof (unexec_malloc_header_t));
!       ptr->u.size = new_size;
!       ptr++;
! #if MACOSX_MALLOC_MULT16
!       assert (((vm_address_t) ptr % 16) == 8);
! #endif
!       return (void *) ptr;
!     }
  }
  
  void
***************
*** 1052,1058 ****
        free (ptr);
      }
    else
!     malloc_zone_free (emacs_zone, ptr);
  }
  
  /* arch-tag: 1a784f7b-a184-4c4f-9544-da8619593d72
--- 1110,1116 ----
        free (ptr);
      }
    else
!     malloc_zone_free (emacs_zone, (unexec_malloc_header_t *) ptr - 1);
  }
  
  /* arch-tag: 1a784f7b-a184-4c4f-9544-da8619593d72




reply via email to

[Prev in Thread] Current Thread [Next in Thread]