1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

Expand MALLOC_COPY and MALLOC_ZERO to memcpy and memset.

This commit is contained in:
Ondřej Bílka
2013-12-10 19:36:28 +01:00
parent 5782a80f9f
commit 0dfa665cc1
3 changed files with 14 additions and 19 deletions

View File

@ -1,3 +1,11 @@
2013-12-10 Ondřej Bílka <neleai@seznam.cz>
* 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/hooks.c (realloc_check): Likewise.
2013-12-10 Ondřej Bílka <neleai@seznam.cz> 2013-12-10 Ondřej Bílka <neleai@seznam.cz>
* malloc/Makefile (CPPFLAGS-malloc.c): Remove -DPER_THREAD flag. * malloc/Makefile (CPPFLAGS-malloc.c): Remove -DPER_THREAD flag.

View File

@ -330,7 +330,7 @@ realloc_check(void* oldmem, size_t bytes, const void *caller)
if (top_check() >= 0) if (top_check() >= 0)
newmem = _int_malloc(&main_arena, bytes+1); newmem = _int_malloc(&main_arena, bytes+1);
if (newmem) { if (newmem) {
MALLOC_COPY(newmem, oldmem, oldsize - 2*SIZE_SZ); memcpy(newmem, oldmem, oldsize - 2*SIZE_SZ);
munmap_chunk(oldp); munmap_chunk(oldp);
} }
} }

View File

@ -1072,19 +1072,6 @@ static void* malloc_atfork(size_t sz, const void *caller);
static void free_atfork(void* mem, const void *caller); static void free_atfork(void* mem, const void *caller);
#endif #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 ------------------ */ /* ------------------ MMAP support ------------------ */
@ -2956,7 +2943,7 @@ __libc_realloc(void* oldmem, size_t bytes)
/* Must alloc, copy, free. */ /* Must alloc, copy, free. */
newmem = __libc_malloc(bytes); newmem = __libc_malloc(bytes);
if (newmem == 0) return 0; /* propagate failure */ 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); munmap_chunk(oldp);
return newmem; return newmem;
} }
@ -2987,7 +2974,7 @@ __libc_realloc(void* oldmem, size_t bytes)
newp = __libc_malloc(bytes); newp = __libc_malloc(bytes);
if (newp != NULL) if (newp != NULL)
{ {
MALLOC_COPY (newp, oldmem, oldsize - SIZE_SZ); memcpy (newp, oldmem, oldsize - SIZE_SZ);
_int_free(ar_ptr, oldp, 0); _int_free(ar_ptr, oldp, 0);
} }
} }
@ -3175,7 +3162,7 @@ __libc_calloc(size_t n, size_t elem_size)
if (chunk_is_mmapped (p)) if (chunk_is_mmapped (p))
{ {
if (__builtin_expect (perturb_byte, 0)) if (__builtin_expect (perturb_byte, 0))
return MALLOC_ZERO (mem, sz); return memset (mem, 0, sz);
return mem; return mem;
} }
@ -3197,7 +3184,7 @@ __libc_calloc(size_t n, size_t elem_size)
assert(nclears >= 3); assert(nclears >= 3);
if (nclears > 9) if (nclears > 9)
return MALLOC_ZERO(d, clearsize); return memset(d, 0, clearsize);
else { else {
*(d+0) = 0; *(d+0) = 0;
@ -4201,7 +4188,7 @@ _int_realloc(mstate av, mchunkptr oldp, INTERNAL_SIZE_T oldsize,
assert(ncopies >= 3); assert(ncopies >= 3);
if (ncopies > 9) if (ncopies > 9)
MALLOC_COPY(d, s, copysize); memcpy(d, s, copysize);
else { else {
*(d+0) = *(s+0); *(d+0) = *(s+0);