diff src/gmalloc.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents b8cc9ab3f761
children
line wrap: on
line diff
--- a/src/gmalloc.c	Mon Aug 13 11:19:22 2007 +0200
+++ b/src/gmalloc.c	Mon Aug 13 11:20:41 2007 +0200
@@ -25,6 +25,8 @@
 # define STDC_HEADERS
 #endif
 
+#define __const const
+
 
 /* DO NOT EDIT THIS FILE -- it is automagically generated.  -*- C -*- */
 /* Bwaa-haa-haa!  Not a chance that this is actually true! */
@@ -271,7 +273,7 @@
 
 /* Call WARNFUN with a warning message when memory usage is high.  */
 extern void memory_warnings __P ((__ptr_t __start,
-				  void (*__warnfun) __P ((const char *))));
+				  void (*__warnfun) __P ((__const char *))));
 
 
 #if 0 /* unused in this file, and conflicting prototypes anyway */
@@ -367,7 +369,7 @@
 #endif
 
 /* How to really get more memory.  */
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
+#ifdef HEAP_IN_DATA
 /* once dumped, free() & realloc() on static heap space will fail */
 #define PURE_DATA(x) \
 ((static_heap_dumped && (char*)x >= static_heap_base \
@@ -446,7 +448,7 @@
 static int
 initialize ()
 {
-#if defined (HEAP_IN_DATA) && !defined(PDUMP)
+#ifdef HEAP_IN_DATA
   if (static_heap_dumped && __morecore == more_static_core)
     {
       __morecore = __default_morecore;
@@ -1016,6 +1018,79 @@
 #include <malloc.h>
 #endif
 
+#if 0 /* FSFmacs */
+/* XEmacs requires an ANSI compiler, and memmove() is part of the ANSI-
+   mandated functions.  For losing systems like SunOS 4, we provide
+   our own memmove(). */
+
+#if  (defined (MEMMOVE_MISSING) || \
+      !defined(_LIBC) && !defined(STDC_HEADERS) && !defined(USG))
+
+/* Snarfed directly from Emacs src/dispnew.c:
+   XXX Should use system bcopy if it handles overlap.  */
+#ifndef emacs
+
+/* Like bcopy except never gets confused by overlap.  */
+
+static void
+safe_bcopy (char *from, char *to, int size)
+{
+  if (size <= 0 || from == to)
+    return;
+
+  /* If the source and destination don't overlap, then bcopy can
+     handle it.  If they do overlap, but the destination is lower in
+     memory than the source, we'll assume bcopy can handle that.  */
+  if (to < from || from + size <= to)
+    bcopy (from, to, size);
+
+  /* Otherwise, we'll copy from the end.  */
+  else
+    {
+      char *endf = from + size;
+      char *endt = to + size;
+
+      /* If TO - FROM is large, then we should break the copy into
+	 nonoverlapping chunks of TO - FROM bytes each.  However, if
+	 TO - FROM is small, then the bcopy function call overhead
+	 makes this not worth it.  The crossover point could be about
+	 anywhere.  Since I don't think the obvious copy loop is too
+	 bad, I'm trying to err in its favor.  */
+      if (to - from < 64)
+	{
+	  do
+	    *--endt = *--endf;
+	  while (endf != from);
+	}
+      else
+	{
+	  for (;;)
+	    {
+	      endt -= (to - from);
+	      endf -= (to - from);
+
+	      if (endt < to)
+		break;
+
+	      bcopy (endf, endt, to - from);
+	    }
+
+	  /* If SIZE wasn't a multiple of TO - FROM, there will be a
+	     little left over.  The amount left over is
+	     (endt + (to - from)) - to, which is endt - from.  */
+	  bcopy (from, to, endt - from);
+	}
+    }
+}
+#endif	/* Not emacs.  */
+
+#define memmove(to, from, size) safe_bcopy ((from), (to), (size))
+
+#endif
+
+#endif /* FSFmacs */
+
+
 #ifndef min
 #define min(A, B) ((A) < (B) ? (A) : (B))
 #endif
@@ -1036,7 +1111,7 @@
   int type;
   __malloc_size_t block, blocks, oldlimit;
 
-  if (PURE_DATA (ptr))
+  if (PURE_DATA(ptr))
     {
       result = malloc (size);
       memcpy(result, ptr, size);