]> code.delx.au - gnu-emacs/blobdiff - src/w32heap.c
Update copyright year to 2016
[gnu-emacs] / src / w32heap.c
index 2a766419b25daaa30db9d7e1558cdb87eb327538..54646bfbe3e8b8b7de12c9fe0e744cce108bda21 100644 (file)
@@ -1,5 +1,5 @@
-/* Heap management routines for GNU Emacs on the Microsoft Windows
-   API.  Copyright (C) 1994, 2001-2014 Free Software Foundation, Inc.
+/* Heap management routines for GNU Emacs on the Microsoft Windows API.
+   Copyright (C) 1994, 2001-2016 Free Software Foundation, Inc.
 
    This file is part of GNU Emacs.
 
@@ -52,7 +52,7 @@
 #include <sys/mman.h>
 #include "w32common.h"
 #include "w32heap.h"
-#include "lisp.h"  /* for VALMASK */
+#include "lisp.h"
 
 /* We chose to leave those declarations here.  They are used only in
    this file.  The RtlCreateHeap is available since XP.  It is located
@@ -114,10 +114,10 @@ typedef struct _RTL_HEAP_PARAMETERS {
    than half of the size stated below.  It would be nice to find a way
    to build only the first bootstrap-emacs.exe with the large size,
    and reset that to a lower value afterwards.  */
-#ifdef _WIN64
-# define DUMPED_HEAP_SIZE (18*1024*1024)
+#if defined _WIN64 || defined WIDE_EMACS_INT
+# define DUMPED_HEAP_SIZE (20*1024*1024)
 #else
-# define DUMPED_HEAP_SIZE (11*1024*1024)
+# define DUMPED_HEAP_SIZE (12*1024*1024)
 #endif
 
 static unsigned char dumped_data[DUMPED_HEAP_SIZE];
@@ -305,9 +305,10 @@ init_heap (void)
 #undef free
 
 /* FREEABLE_P checks if the block can be safely freed.  */
-#define FREEABLE_P(addr)                                        \
-    ((unsigned char *)(addr) < dumped_data                      \
-     || (unsigned char *)(addr) >= dumped_data + DUMPED_HEAP_SIZE)
+#define FREEABLE_P(addr)                                               \
+    ((unsigned char *)(addr) > 0                                       \
+     && ((unsigned char *)(addr) < dumped_data                         \
+        || (unsigned char *)(addr) >= dumped_data + DUMPED_HEAP_SIZE))
 
 void *
 malloc_after_dump (size_t size)
@@ -407,10 +408,10 @@ realloc_after_dump (void *ptr, size_t size)
       /* If the block lies in the dumped data, do not free it.  Only
          allocate a new one.  */
       p = HeapAlloc (heap, 0, size);
-      if (p)
-       CopyMemory (p, ptr, size);
-      else
+      if (!p)
        errno = ENOMEM;
+      else if (ptr)
+       CopyMemory (p, ptr, size);
     }
   /* After dump, keep track of the "brk value" for sbrk(0).  */
   if (p)
@@ -449,7 +450,7 @@ realloc_before_dump (void *ptr, size_t size)
         of failing the call as below.  But this doesn't seem to be
         worth the added complexity, as loadup allocates only a very
         small number of large blocks, and never reallocates them.  */
-      if (p)
+      if (p && ptr)
        {
          CopyMemory (p, ptr, size);
          free_before_dump (ptr);
@@ -473,6 +474,9 @@ free_after_dump (void *ptr)
 void
 free_before_dump (void *ptr)
 {
+  if (!ptr)
+    return;
+
   /* Before dumping.  */
   if (dumped_data < (unsigned char *)ptr
       && (unsigned char *)ptr < bc_limit)