]> git.eshelyaron.com Git - emacs.git/commitdiff
(pure_alloc): Rewritten and simplified.
authorKim F. Storm <storm@cua.dk>
Sun, 12 Jan 2003 15:40:23 +0000 (15:40 +0000)
committerKim F. Storm <storm@cua.dk>
Sun, 12 Jan 2003 15:40:23 +0000 (15:40 +0000)
src/ChangeLog
src/alloc.c

index 77468a9d14cfcd67d54ce5323ef6ea2549b5d654..ff63eb318a37a820ab220392a945fb22e93491ac 100644 (file)
@@ -1,8 +1,9 @@
 2003-01-12  Kim F. Storm  <storm@cua.dk>
 
-       * alloc.c (pure_alloc): Corrected last change; now align the
-       pointer and adjust the size rather than aligning the size and
-       adjusting the pointer.  Use a goto to handle overflow exception.
+       * alloc.c (pure_alloc): Fixed 2003-01-10 changed (caused spurious
+       crashes).  Code rewritten and simplified.  Now directly aligns the
+       pointer and recalculates pure_bytes_used, rather than aligning the
+       size and adjusting the pointer.
 
 2003-01-11  Kim F. Storm  <storm@cua.dk>
 
index f19c232889969469e64995c24d52136fad357e57..281288e69db68c54945929df5494b1a12609e7b8 100644 (file)
@@ -3831,46 +3831,34 @@ pure_alloc (size, type)
      size_t size;
      int type;
 {
-  size_t nbytes;
   POINTER_TYPE *result;
-  char *beg;
-
- again:
-  beg = purebeg;
-  result = (POINTER_TYPE *) (beg + pure_bytes_used);
-  nbytes = ALIGN (size, sizeof (EMACS_INT));
+  size_t alignment = sizeof (EMACS_INT);
 
   /* Give Lisp_Floats an extra alignment.  */
   if (type == Lisp_Float)
     {
-      POINTER_TYPE *orig = result;
-      size_t alignment;
 #if defined __GNUC__ && __GNUC__ >= 2
       alignment = __alignof (struct Lisp_Float);
 #else
       alignment = sizeof (struct Lisp_Float);
 #endif
-      /* Make sure result is correctly aligned for a
-        Lisp_Float, which might need stricter alignment than
-        EMACS_INT.  */
-      result = (POINTER_TYPE *)ALIGN((EMACS_UINT)result, alignment);
-      nbytes += (char *)result - (char *)orig;
-    }
-    
-  if (pure_bytes_used + nbytes > pure_size)
-    {
-      /* Don't allocate a large amount here,
-        because it might get mmap'd and then its address
-        might not be usable.  */
-      purebeg = (char *) xmalloc (10000);
-      pure_size = 10000;
-      pure_bytes_used_before_overflow += pure_bytes_used;
-      pure_bytes_used = 0;
-      goto again;
     }
 
-  pure_bytes_used += nbytes;
-  return result;
+ again:
+  result = (POINTER_TYPE *) ALIGN ((EMACS_UINT)purebeg + pure_bytes_used, alignment);
+  pure_bytes_used = ((char *)result - (char *)purebeg) + size;
+
+  if (pure_bytes_used <= pure_size)
+    return result;
+
+  /* Don't allocate a large amount here,
+     because it might get mmap'd and then its address
+     might not be usable.  */
+  purebeg = (char *) xmalloc (10000);
+  pure_size = 10000;
+  pure_bytes_used_before_overflow += pure_bytes_used - size;
+  pure_bytes_used = 0;
+  goto again;
 }