diff --git a/CMakeLists.txt b/CMakeLists.txt index 1807c474d..aaadecb72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -434,7 +434,6 @@ check_function_exists( sendfile HAVE_SENDFILE ) check_function_exists( rindex HAVE_RINDEX ) check_function_exists( putenv HAVE_PUTENV ) check_function_exists( poll HAVE_POLL ) -check_function_exists( memcpy HAVE_MEMCPY ) check_function_exists( madvise HAVE_MADVISE ) check_function_exists( getgroups HAVE_GETGROUPS ) check_function_exists( getcwd HAVE_GETCWD ) @@ -461,7 +460,6 @@ if( NOT HAVE_CRYPT ) set( CRYPT_LIBRARIES c ) endif( HAVE_CRYPT_LIBC ) endif( NOT HAVE_CRYPT ) -check_function_exists( bcopy HAVE_BCOPY ) check_function_exists( mmap HAVE_MMAP ) check_function_exists( munmap HAVE_MUNMAP ) diff --git a/config.h.cmake b/config.h.cmake index 76c299e08..7285a1bd5 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -119,9 +119,6 @@ /* Define to 1 if libbfd provides demangle.h header */ #cmakedefine HAVE_DEMANGLE_H 1 -/* Define to 1 if you have the `bcopy' function. */ -#cmakedefine HAVE_BCOPY 1 - /* You _must_ have bool */ #undef HAVE_BOOL @@ -383,9 +380,6 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_MALLOC_H 1 -/* Define to 1 if you have the `memcpy' function. */ -#cmakedefine HAVE_MEMCPY 1 - /* Define to 1 if you have the header file. */ #cmakedefine HAVE_MEMORY_H 1 diff --git a/tdecore/malloc/malloc.c b/tdecore/malloc/malloc.c index 8f9fbb79b..5cdab5ac7 100644 --- a/tdecore/malloc/malloc.c +++ b/tdecore/malloc/malloc.c @@ -16,7 +16,6 @@ int kde_malloc_is_used = 0; #define USE_MALLOC_LOCK #define INLINE __inline__ /*#define INLINE*/ -#define USE_MEMCPY 0 #define MMAP_CLEARS 1 /* @@ -193,8 +192,6 @@ int kde_malloc_is_used = 0; __STD_C derived from C compiler defines WIN32 NOT defined - HAVE_MEMCPY defined - USE_MEMCPY 1 if HAVE_MEMCPY is defined HAVE_MMAP defined as 1 MMAP_CLEARS 1 HAVE_MREMAP 0 unless linux defined @@ -563,34 +560,6 @@ extern "C" { #endif /* USE_DL_PREFIX */ -/* - HAVE_MEMCPY should be defined if you are not otherwise using - ANSI STD C, but still have memcpy and memset in your C library - and want to use them in calloc and realloc. Otherwise simple - macro versions are defined below. - - USE_MEMCPY should be defined as 1 if you actually want to - have memset and memcpy called. People report that the macro - versions are faster than libc versions on some systems. - - Even if USE_MEMCPY is set to 1, loops to copy/clear small chunks - (of <= 36 bytes) are manually unrolled in realloc and calloc. -*/ - -/* If it's available it's defined in config.h. */ -/* #define HAVE_MEMCPY */ - -#ifndef USE_MEMCPY -#ifdef HAVE_MEMCPY -#define USE_MEMCPY 1 -#else -#define USE_MEMCPY 0 -#endif -#endif - - -#if (__STD_C || defined(HAVE_MEMCPY)) - #ifdef WIN32 /* On Win32 memset and memcpy are already declared in windows.h */ #else @@ -602,7 +571,6 @@ Void_t* memset(); Void_t* memcpy(); #endif #endif -#endif /* MALLOC_FAILURE_ACTION is the action to take before "return 0" when @@ -1747,64 +1715,6 @@ int public_mALLOPt(int p, int v) { #endif - - -/* ------------- Optional versions of memcopy ---------------- */ - - -#if USE_MEMCPY - -/* - 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) - -#else /* !USE_MEMCPY */ - -/* Use Duff's device for good zeroing/copying performance. */ - -#define MALLOC_ZERO(charp, nbytes) \ -do { \ - INTERNAL_SIZE_T* mzp = (INTERNAL_SIZE_T*)(charp); \ - unsigned long mctmp = (nbytes)/sizeof(INTERNAL_SIZE_T); \ - long mcn; \ - if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \ - switch (mctmp) { \ - case 0: for(;;) { *mzp++ = 0; \ - case 7: *mzp++ = 0; \ - case 6: *mzp++ = 0; \ - case 5: *mzp++ = 0; \ - case 4: *mzp++ = 0; \ - case 3: *mzp++ = 0; \ - case 2: *mzp++ = 0; \ - case 1: *mzp++ = 0; if(mcn <= 0) break; mcn--; } \ - } \ -} while(0) - -#define MALLOC_COPY(dest,src,nbytes) \ -do { \ - INTERNAL_SIZE_T* mcsrc = (INTERNAL_SIZE_T*) src; \ - INTERNAL_SIZE_T* mcdst = (INTERNAL_SIZE_T*) dest; \ - unsigned long mctmp = (nbytes)/sizeof(INTERNAL_SIZE_T); \ - long mcn; \ - if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp %= 8; } \ - switch (mctmp) { \ - case 0: for(;;) { *mcdst++ = *mcsrc++; \ - case 7: *mcdst++ = *mcsrc++; \ - case 6: *mcdst++ = *mcsrc++; \ - case 5: *mcdst++ = *mcsrc++; \ - case 4: *mcdst++ = *mcsrc++; \ - case 3: *mcdst++ = *mcsrc++; \ - case 2: *mcdst++ = *mcsrc++; \ - case 1: *mcdst++ = *mcsrc++; if(mcn <= 0) break; mcn--; } \ - } \ -} while(0) - -#endif - /* ------------------ MMAP support ------------------ */ @@ -4006,9 +3916,9 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; ncopies = copysize / sizeof(INTERNAL_SIZE_T); assert(ncopies >= 3); - if (ncopies > 9) - MALLOC_COPY(d, s, copysize); - + if (ncopies > 9) { + memcpy(d, s, copysize); + } else { *(d+0) = *(s+0); *(d+1) = *(s+1); @@ -4106,7 +4016,7 @@ Void_t* rEALLOc(oldmem, bytes) Void_t* oldmem; size_t bytes; /* Must alloc, copy, free. */ newmem = mALLOc(nb - MALLOC_ALIGN_MASK); if (newmem != 0) { - MALLOC_COPY(newmem, oldmem, oldsize - 2*SIZE_SZ); + memcpy(newmem, oldmem, oldsize - 2*SIZE_SZ); fREe(oldmem); } } @@ -4264,9 +4174,9 @@ Void_t* cALLOc(n_elements, elem_size) size_t n_elements; size_t elem_size; nclears = clearsize / sizeof(INTERNAL_SIZE_T); assert(nclears >= 3); - if (nclears > 9) - MALLOC_ZERO(d, clearsize); - + if (nclears > 9) { + memset(d, 0, clearsize); + } else { *(d+0) = 0; *(d+1) = 0; @@ -4290,7 +4200,7 @@ Void_t* cALLOc(n_elements, elem_size) size_t n_elements; size_t elem_size; { d = (INTERNAL_SIZE_T*)mem; clearsize = chunksize(p) - 2 * SIZE_SZ; - MALLOC_ZERO(d, clearsize); + memset(d, 0, clearsize); } #endif } @@ -4396,7 +4306,7 @@ static Void_t** iALLOc(n_elements, sizes, opts, chunks) size_t n_elements; size_ remainder_size = chunksize(p); if (opts & 0x2) { /* optionally clear the elements */ - MALLOC_ZERO(mem, remainder_size - SIZE_SZ - array_size); + memset(mem, 0, remainder_size - SIZE_SZ - array_size) } /* If not provided, allocate the pointer array as final part of chunk */