This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Expand MALLOC_COPY and MALLOC_ZERO to memcpy/memset.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Mon, 9 Dec 2013 19:39:40 +0100
- Subject: [PATCH] Expand MALLOC_COPY and MALLOC_ZERO to memcpy/memset.
- Authentication-results: sourceware.org; auth=none
Hi,
Continuing cleaning malloc we also expand MALLOC_COPY and MALLOC_ZERO
to their bodies.
* malloc/malloc.c (MALLOC_COPY, MALLOC_ZERO): Delete.
(__malloc_assert, __libc_realloc, __libc_calloc,
_int_realloc): Expand MALLOC_COPY and MALLOC_ZERO to memcpy and
memset.
---
malloc/malloc.c | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 622a606..3e7bbc9 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -1029,19 +1029,6 @@ static void* malloc_atfork(size_t sz, const void *caller);
static void free_atfork(void* mem, const void *caller);
#endif
-
-/* ------------- Optional versions of memcopy ---------------- */
-
-
-/*
- Note: memcpy is ONLY invoked with non-overlapping regions,
- so the (usually slower) memmove is not needed.
-*/
-
-#define MALLOC_COPY(dest, src, nbytes) memcpy(dest, src, nbytes)
-#define MALLOC_ZERO(dest, nbytes) memset(dest, 0, nbytes)
-
-
/* ------------------ MMAP support ------------------ */
@@ -2921,7 +2908,7 @@ __libc_realloc(void* oldmem, size_t bytes)
/* Must alloc, copy, free. */
newmem = __libc_malloc(bytes);
if (newmem == 0) return 0; /* propagate failure */
- MALLOC_COPY(newmem, oldmem, oldsize - 2*SIZE_SZ);
+ memcpy(newmem, oldmem, oldsize - 2*SIZE_SZ);
munmap_chunk(oldp);
return newmem;
}
@@ -2957,7 +2944,7 @@ __libc_realloc(void* oldmem, size_t bytes)
newp = __libc_malloc(bytes);
if (newp != NULL)
{
- MALLOC_COPY (newp, oldmem, oldsize - SIZE_SZ);
+ memcpy (newp, oldmem, oldsize - SIZE_SZ);
_int_free(ar_ptr, oldp, 0);
}
}
@@ -3145,7 +3132,7 @@ __libc_calloc(size_t n, size_t elem_size)
if (chunk_is_mmapped (p))
{
if (__builtin_expect (perturb_byte, 0))
- return MALLOC_ZERO (mem, sz);
+ return memset (mem, 0, sz);
return mem;
}
@@ -3167,7 +3154,7 @@ __libc_calloc(size_t n, size_t elem_size)
assert(nclears >= 3);
if (nclears > 9)
- return MALLOC_ZERO(d, clearsize);
+ return memset(d, 0, clearsize);
else {
*(d+0) = 0;
@@ -4171,7 +4158,7 @@ _int_realloc(mstate av, mchunkptr oldp, size_t oldsize,
assert(ncopies >= 3);
if (ncopies > 9)
- MALLOC_COPY(d, s, copysize);
+ memcpy(d, s, copysize);
else {
*(d+0) = *(s+0);
--
1.8.4.rc3