emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r116661: Follow-up improvements for last change in g


From: Eli Zaretskii
Subject: [Emacs-diffs] trunk r116661: Follow-up improvements for last change in gmalloc.c.
Date: Tue, 04 Mar 2014 17:36:09 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116661
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/16901
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Tue 2014-03-04 19:35:15 +0200
message:
  Follow-up improvements for last change in gmalloc.c.
  
   src/gmalloc.c (aligned_alloc): Don't allocate more memory than
   needed, and don't reallocate if the initial allocation already
   fits the bill.  Suggested by Ken Brown <address@hidden>.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/gmalloc.c                  gmalloc.c-20091113204419-o5vbwnq5f7feedwu-1085
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-03-04 11:02:36 +0000
+++ b/src/ChangeLog     2014-03-04 17:35:15 +0000
@@ -1,3 +1,9 @@
+2014-03-04  Eli Zaretskii  <address@hidden>
+
+       * gmalloc.c (aligned_alloc): Don't allocate more memory than
+       needed, and don't reallocate if the initial allocation already
+       fits the bill.  Suggested by Ken Brown <address@hidden>.
+
 2014-03-04  YAMAMOTO Mitsuharu  <address@hidden>
 
        * xterm.c (x_draw_stretch_glyph_string): Reset clipping.

=== modified file 'src/gmalloc.c'
--- a/src/gmalloc.c     2014-03-03 16:46:36 +0000
+++ b/src/gmalloc.c     2014-03-04 17:35:15 +0000
@@ -38,6 +38,10 @@
 #include <w32heap.h>   /* for sbrk */
 #endif
 
+#ifdef emacs
+extern void emacs_abort (void);
+#endif
+
 #ifdef __cplusplus
 extern "C"
 {
@@ -1594,24 +1598,33 @@
   /* Figure out how much we will need to pad this particular block
      to achieve the required alignment.  */
   adj = (uintptr_t) result % alignment;
+  if (adj == 0)
+    adj = alignment;
 
-  do
+  if (adj != 1)
     {
-      /* Reallocate the block with only as much excess as it needs.  */
-      free (result);
-      result = malloc (size + alignment - adj);
-      if (result == NULL)      /* Impossible unless interrupted.  */
-       return NULL;
-
-      lastadj = adj;
-      adj = (uintptr_t) result % alignment;
-      /* It's conceivable we might have been so unlucky as to get a
-        different block with weaker alignment.  If so, this block is too
-        short to contain SIZE after alignment correction.  So we must
-        try again and get another block, slightly larger.  */
-    } while (adj < lastadj);
-
-  if (adj != 0)
+      do
+       {
+         /* Reallocate the block with only as much excess as it
+            needs.  */
+         free (result);
+         result = malloc (size + alignment - adj);
+         if (result == NULL)   /* Impossible unless interrupted.  */
+           return NULL;
+
+         lastadj = adj;
+         adj = (uintptr_t) result % alignment;
+         if (adj == 0)
+           adj = alignment;
+         /* It's conceivable we might have been so unlucky as to get
+            a different block with weaker alignment.  If so, this
+            block is too short to contain SIZE after alignment
+            correction.  So we must try again and get another block,
+            slightly larger.  */
+       } while (adj < lastadj);
+    }
+
+  if (adj != alignment)
     {
       /* Record this block in the list of aligned blocks, so that `free'
         can identify the pointer it is passed, which will be in the middle


reply via email to

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