From patchwork Thu Nov 8 15:51:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 30078 Received: (qmail 32191 invoked by alias); 8 Nov 2018 15:52:06 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 32178 invoked by uid 89); 8 Nov 2018 15:52:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=fwd, bck, victim X-HELO: mx1.redhat.com From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Rename unlink macro to unlink_check Date: Thu, 08 Nov 2018 16:51:57 +0100 Message-ID: <87wopn8t42.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 This commit is in preparation of turning the macro into a proper function. The output arguments of the macro were unused. 2018-11-08 Florian Weimer * malloc/malloc.c (unlink_chunk): Rename from unlink. Remove BK, FD arguments. Turn into statement expression. (_int_malloc, _int_free): Adjust. (malloc_consolidate, _int_realloc): Adjust. Remove bck, fwd variables. * malloc/arena.c (heap_trim): Likewise. diff --git a/malloc/arena.c b/malloc/arena.c index 497ae475e7..ff8fd5d2a7 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -596,7 +596,7 @@ heap_trim (heap_info *heap, size_t pad) { mstate ar_ptr = heap->ar_ptr; unsigned long pagesz = GLRO (dl_pagesize); - mchunkptr top_chunk = top (ar_ptr), p, bck, fwd; + mchunkptr top_chunk = top (ar_ptr), p; heap_info *prev_heap; long new_size, top_size, top_area, extra, prev_size, misalign; @@ -625,7 +625,7 @@ heap_trim (heap_info *heap, size_t pad) if (!prev_inuse (p)) /* consolidate backward */ { p = prev_chunk (p); - unlink (ar_ptr, p, bck, fwd); + unlink_chunk (ar_ptr, p); } assert (((unsigned long) ((char *) p + new_size) & (pagesz - 1)) == 0); assert (((char *) p + new_size) == ((char *) heap + heap->size)); diff --git a/malloc/malloc.c b/malloc/malloc.c index 67cdfd0ad2..e2546870e7 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1385,11 +1385,11 @@ typedef struct malloc_chunk *mbinptr; #define last(b) ((b)->bk) /* Take a chunk off a bin list */ -#define unlink(AV, P, BK, FD) { \ +#define unlink_chunk(AV, P) ({ \ if (__builtin_expect (chunksize(P) != prev_size (next_chunk(P)), 0)) \ malloc_printerr ("corrupted size vs. prev_size"); \ - FD = P->fd; \ - BK = P->bk; \ + 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 { \ @@ -1415,7 +1415,7 @@ typedef struct malloc_chunk *mbinptr; } \ } \ } \ -} +}) /* Indexing @@ -3920,7 +3920,7 @@ _int_malloc (mstate av, size_t bytes) victim = victim->fd; remainder_size = size - nb; - unlink (av, victim, bck, fwd); + unlink_chunk (av, victim); /* Exhaust */ if (remainder_size < MINSIZE) @@ -4022,7 +4022,7 @@ _int_malloc (mstate av, size_t bytes) remainder_size = size - nb; /* unlink */ - unlink (av, victim, bck, fwd); + unlink_chunk (av, victim); /* Exhaust */ if (remainder_size < MINSIZE) @@ -4294,7 +4294,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) p = chunk_at_offset(p, -((long) prevsize)); if (__glibc_unlikely (chunksize(p) != prevsize)) malloc_printerr ("corrupted size vs. prev_size while consolidating"); - unlink(av, p, bck, fwd); + unlink_chunk (av, p); } if (nextchunk != av->top) { @@ -4303,7 +4303,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) /* consolidate forward */ if (!nextinuse) { - unlink(av, nextchunk, bck, fwd); + unlink_chunk (av, nextchunk); size += nextsize; } else clear_inuse_bit_at_offset(nextchunk, 0); @@ -4416,8 +4416,6 @@ static void malloc_consolidate(mstate av) INTERNAL_SIZE_T nextsize; INTERNAL_SIZE_T prevsize; int nextinuse; - mchunkptr bck; - mchunkptr fwd; atomic_store_relaxed (&av->have_fastchunks, false); @@ -4457,7 +4455,7 @@ static void malloc_consolidate(mstate av) p = chunk_at_offset(p, -((long) prevsize)); if (__glibc_unlikely (chunksize(p) != prevsize)) malloc_printerr ("corrupted size vs. prev_size in fastbins"); - unlink(av, p, bck, fwd); + unlink_chunk (av, p); } if (nextchunk != av->top) { @@ -4465,7 +4463,7 @@ static void malloc_consolidate(mstate av) if (!nextinuse) { size += nextsize; - unlink(av, nextchunk, bck, fwd); + unlink_chunk (av, nextchunk); } else clear_inuse_bit_at_offset(nextchunk, 0); @@ -4513,9 +4511,6 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize, mchunkptr remainder; /* extra space at end of newp */ unsigned long remainder_size; /* its size */ - mchunkptr bck; /* misc temp for linking */ - mchunkptr fwd; /* misc temp for linking */ - unsigned long copysize; /* bytes to copy */ unsigned int ncopies; /* INTERNAL_SIZE_T words to copy */ INTERNAL_SIZE_T* s; /* copy source */ @@ -4565,7 +4560,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize, (unsigned long) (nb)) { newp = oldp; - unlink (av, next, bck, fwd); + unlink_chunk (av, next); } /* allocate, copy, free */