*** empty log message ***
[bpt/emacs.git] / src / gmalloc.c
index 751e90b..71df287 100644 (file)
@@ -5,7 +5,8 @@
 /* The malloc headers and source files from the C library follow here.  */
 
 /* Declarations for `malloc' and friends.
-   Copyright 1990, 91, 92, 93, 95, 96, 99 Free Software Foundation, Inc.
+   Copyright (C) 1990, 1991, 1992, 1993, 1995, 1996, 1999, 2002, 2003, 2004,
+                 2005, 2006 Free Software Foundation, Inc.
                  Written May 1989 by Mike Haertel.
 
 This library is free software; you can redistribute it and/or
@@ -20,8 +21,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -36,8 +37,9 @@ Cambridge, MA 02139, USA.
 #include <config.h>
 #endif
 
-#if defined __cplusplus || (defined (__STDC__) && __STDC__) || \
-  defined STDC_HEADERS || defined PROTOTYPES
+#if ((defined __cplusplus || (defined (__STDC__) && __STDC__) \
+      || defined STDC_HEADERS || defined PROTOTYPES) \
+     && ! defined (BROKEN_PROTOTYPES))
 #undef PP
 #define        PP(args)        args
 #undef __ptr_t
@@ -84,7 +86,15 @@ extern "C"
 #define        __malloc_size_t         size_t
 #define        __malloc_ptrdiff_t      ptrdiff_t
 #else
+#ifdef __GNUC__
+#include <stddef.h>
+#ifdef __SIZE_TYPE__
+#define        __malloc_size_t         __SIZE_TYPE__
+#endif
+#endif
+#ifndef __malloc_size_t
 #define        __malloc_size_t         unsigned int
+#endif
 #define        __malloc_ptrdiff_t      int
 #endif
 
@@ -330,8 +340,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -343,6 +353,10 @@ Cambridge, MA 02139, USA.
 #include <errno.h>
 
 /* How to really get more memory.  */
+#if defined(CYGWIN)
+extern __ptr_t bss_sbrk PP ((ptrdiff_t __size));
+extern int bss_sbrk_did_unexec;
+#endif
 __ptr_t (*__morecore) PP ((ptrdiff_t __size)) = __default_morecore;
 
 /* Debugging hook for `malloc'.  */
@@ -411,7 +425,7 @@ protect_malloc_state (protect_p)
 
   last_state_size = _heaplimit * sizeof *_heapinfo;
   last_heapinfo   = _heapinfo;
-  
+
   if (protect_p != state_protected_p)
     {
       state_protected_p = protect_p;
@@ -437,7 +451,14 @@ align (size)
   __ptr_t result;
   unsigned long int adj;
 
-  result = (*__morecore) (size);
+  /* align accepts an unsigned argument, but __morecore accepts a
+     signed one.  This could lead to trouble if SIZE overflows a
+     signed int type accepted by __morecore.  We just punt in that
+     case, since they are requesting a ludicrous amount anyway.  */
+  if ((__malloc_ptrdiff_t)size < 0)
+    result = 0;
+  else
+    result = (*__morecore) (size);
   adj = (unsigned long int) ((unsigned long int) ((char *) result -
                                                  (char *) NULL)) % BLOCKSIZE;
   if (adj != 0)
@@ -922,8 +943,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -976,7 +997,7 @@ _free_internal (ptr)
     return;
 
   PROTECT_MALLOC_STATE (0);
-  
+
   for (l = _aligned_blocks; l != NULL; l = l->next)
     if (l->aligned == ptr)
       {
@@ -1198,7 +1219,7 @@ _free_internal (ptr)
        }
       break;
     }
-  
+
   PROTECT_MALLOC_STATE (1);
 }
 
@@ -1241,8 +1262,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -1364,7 +1385,7 @@ _realloc_internal (ptr, size)
   block = BLOCK (ptr);
 
   PROTECT_MALLOC_STATE (0);
-  
+
   type = _heapinfo[block].busy.type;
   switch (type)
     {
@@ -1486,8 +1507,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -1526,7 +1547,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with the GNU C Library; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+MA 02110-1301, USA.  */
 
 #ifndef        _MALLOC_INTERNAL
 #define        _MALLOC_INTERNAL
@@ -1556,7 +1578,14 @@ __ptr_t
 __default_morecore (increment)
      __malloc_ptrdiff_t increment;
 {
-  __ptr_t result = (__ptr_t) __sbrk (increment);
+  __ptr_t result;
+#if defined(CYGWIN)
+  if (!bss_sbrk_did_unexec)
+    {
+      return bss_sbrk (increment);
+    }
+#endif
+  result = (__ptr_t) __sbrk (increment);
   if (result == (__ptr_t) -1)
     return NULL;
   return result;
@@ -1575,8 +1604,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.  */
 
 #ifndef        _MALLOC_INTERNAL
 #define _MALLOC_INTERNAL
@@ -1590,7 +1619,8 @@ Cambridge, MA 02139, USA.  */
 
 #else
 
-__ptr_t (*__memalign_hook) PP ((size_t __size, size_t __alignment));
+__ptr_t (*__memalign_hook) PP ((__malloc_size_t __size,
+                               __malloc_size_t __alignment));
 
 __ptr_t
 memalign (alignment, size)
@@ -1674,8 +1704,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -1741,8 +1771,8 @@ Library General Public License for more details.
 
 You should have received a copy of the GNU Library General Public
 License along with this library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.
+not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+Fifth Floor, Boston, MA 02110-1301, USA.
 
    The author may be reached (Email) at the address mike@ai.mit.edu,
    or (US mail) as Mike Haertel c/o Free Software Foundation.  */
@@ -1826,7 +1856,7 @@ freehook (ptr)
      __ptr_t ptr;
 {
   struct hdr *hdr;
-    
+
   if (ptr)
     {
       hdr = ((struct hdr *) ptr) - 1;
@@ -1836,7 +1866,7 @@ freehook (ptr)
     }
   else
     hdr = NULL;
-  
+
   __free_hook = old_free_hook;
   free (hdr);
   __free_hook = freehook;
@@ -1870,7 +1900,7 @@ reallochook (ptr, size)
 {
   struct hdr *hdr = NULL;
   __malloc_size_t osize = 0;
-    
+
   if (ptr)
     {
       hdr = ((struct hdr *) ptr) - 1;
@@ -1880,7 +1910,7 @@ reallochook (ptr, size)
       if (size < osize)
        flood ((char *) ptr + size, FREEFLOOD, osize - size);
     }
-  
+
   __free_hook = old_free_hook;
   __malloc_hook = old_malloc_hook;
   __realloc_hook = old_realloc_hook;
@@ -1961,3 +1991,6 @@ mprobe (__ptr_t ptr)
 }
 
 #endif /* GC_MCHECK */
+
+/* arch-tag: 93dce5c0-f49a-41b5-86b1-f91c4169c02e
+   (do not change this comment) */