This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] malloc: Turn unlink_chunk into a function


Also clean up uses of __builtin_expect.

2018-11-08  Florian Weimer  <fweimer@redhat.com>

	* malloc/malloc.c (unlink_chunk): Turn macro into function.  Move
	after the definition of in_smallbin_range.  Do not use
	__builtin_expect for paths that lead to a noreturn function.  Drop
	remaining __builtin_expect (p->fd_nextsize != NULL, 0) because it
	is unclear whether this is in fact an unlikely condition.

diff --git a/malloc/malloc.c b/malloc/malloc.c
index e2546870e7..fcfe0811f3 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1384,39 +1384,6 @@ typedef struct malloc_chunk *mbinptr;
 #define first(b)     ((b)->fd)
 #define last(b)      ((b)->bk)
 
-/* Take a chunk off a bin list */
-#define unlink_chunk(AV, P) ({						\
-    if (__builtin_expect (chunksize(P) != prev_size (next_chunk(P)), 0))      \
-      malloc_printerr ("corrupted size vs. prev_size");			      \
-    mchunkptr FD = P->fd;						      \
-    mchunkptr BK = P->bk;						      \
-    if (__builtin_expect (FD->bk != P || BK->fd != P, 0))		      \
-      malloc_printerr ("corrupted double-linked list");			      \
-    else {								      \
-        FD->bk = BK;							      \
-        BK->fd = FD;							      \
-        if (!in_smallbin_range (chunksize_nomask (P))			      \
-            && __builtin_expect (P->fd_nextsize != NULL, 0)) {		      \
-	    if (__builtin_expect (P->fd_nextsize->bk_nextsize != P, 0)	      \
-		|| __builtin_expect (P->bk_nextsize->fd_nextsize != P, 0))    \
-	      malloc_printerr ("corrupted double-linked list (not small)");   \
-            if (FD->fd_nextsize == NULL) {				      \
-                if (P->fd_nextsize == P)				      \
-                  FD->fd_nextsize = FD->bk_nextsize = FD;		      \
-                else {							      \
-                    FD->fd_nextsize = P->fd_nextsize;			      \
-                    FD->bk_nextsize = P->bk_nextsize;			      \
-                    P->fd_nextsize->bk_nextsize = FD;			      \
-                    P->bk_nextsize->fd_nextsize = FD;			      \
-                  }							      \
-              } else {							      \
-                P->fd_nextsize->bk_nextsize = P->bk_nextsize;		      \
-                P->bk_nextsize->fd_nextsize = P->fd_nextsize;		      \
-              }								      \
-          }								      \
-      }									      \
-})
-
 /*
    Indexing
 
@@ -1489,6 +1456,46 @@ typedef struct malloc_chunk *mbinptr;
 #define bin_index(sz) \
   ((in_smallbin_range (sz)) ? smallbin_index (sz) : largebin_index (sz))
 
+/* Take a chunk off a bin list.  */
+static void
+unlink_chunk (mstate av, mchunkptr p)
+{
+    if (chunksize (p) != prev_size (next_chunk (p)))
+      malloc_printerr ("corrupted size vs. prev_size");
+
+    mchunkptr fd = p->fd;
+    mchunkptr bk = p->bk;
+
+    if (__builtin_expect (fd->bk != p || bk->fd != p, 0))
+      malloc_printerr ("corrupted double-linked list");
+
+    fd->bk = bk;
+    bk->fd = fd;
+    if (!in_smallbin_range (chunksize_nomask (p)) && p->fd_nextsize != NULL)
+      {
+	if (p->fd_nextsize->bk_nextsize != p
+	    || p->bk_nextsize->fd_nextsize != p)
+	  malloc_printerr ("corrupted double-linked list (not small)");
+
+	if (fd->fd_nextsize == NULL)
+	  {
+	    if (p->fd_nextsize == p)
+	      fd->fd_nextsize = fd->bk_nextsize = fd;
+	    else
+	      {
+		fd->fd_nextsize = p->fd_nextsize;
+		fd->bk_nextsize = p->bk_nextsize;
+		p->fd_nextsize->bk_nextsize = fd;
+		p->bk_nextsize->fd_nextsize = fd;
+	      }
+	  }
+	else
+	  {
+	    p->fd_nextsize->bk_nextsize = p->bk_nextsize;
+	    p->bk_nextsize->fd_nextsize = p->fd_nextsize;
+	  }
+      }
+}
 
 /*
    Unsorted chunks


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]