diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2018-09-12 16:31:13 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2020-04-21 11:09:03 -0700 |
commit | c495c3af26b73cb1d444fdd67cc6c1f0226bd168 (patch) | |
tree | 2bd4bf42527fb442496f81c99ece898b1a1787f4 /src/util | |
parent | bb560f2d653dd5d080c7f03859936ce50bea5b72 (diff) |
replace imports memory functions with utils memory functions
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3024>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/imports.c | 148 | ||||
-rw-r--r-- | src/util/imports.h | 13 |
2 files changed, 0 insertions, 161 deletions
diff --git a/src/util/imports.c b/src/util/imports.c index f264e725cc4..2744ee988d3 100644 --- a/src/util/imports.c +++ b/src/util/imports.c @@ -61,154 +61,6 @@ extern int vsnprintf(char *str, size_t count, const char *fmt, va_list arg); #endif -/**********************************************************************/ -/** \name Memory */ -/*@{*/ - -/** - * Allocate aligned memory. - * - * \param bytes number of bytes to allocate. - * \param alignment alignment (must be greater than zero). - * - * Allocates extra memory to accommodate rounding up the address for - * alignment and to record the real malloc address. - * - * \sa _mesa_align_free(). - */ -void * -_mesa_align_malloc(size_t bytes, unsigned long alignment) -{ -#if defined(HAVE_POSIX_MEMALIGN) - void *mem; - int err = posix_memalign(& mem, alignment, bytes); - if (err) - return NULL; - return mem; -#elif defined(_WIN32) - return _aligned_malloc(bytes, alignment); -#else - uintptr_t ptr, buf; - - assert( alignment > 0 ); - - ptr = (uintptr_t)malloc(bytes + alignment + sizeof(void *)); - if (!ptr) - return NULL; - - buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); - *(uintptr_t *)(buf - sizeof(void *)) = ptr; - -#ifndef NDEBUG - /* mark the non-aligned area */ - while ( ptr < buf - sizeof(void *) ) { - *(unsigned long *)ptr = 0xcdcdcdcd; - ptr += sizeof(unsigned long); - } -#endif - - return (void *) buf; -#endif /* defined(HAVE_POSIX_MEMALIGN) */ -} - -/** - * Same as _mesa_align_malloc(), but using calloc(1, ) instead of - * malloc() - */ -void * -_mesa_align_calloc(size_t bytes, unsigned long alignment) -{ -#if defined(HAVE_POSIX_MEMALIGN) - void *mem; - - mem = _mesa_align_malloc(bytes, alignment); - if (mem != NULL) { - (void) memset(mem, 0, bytes); - } - - return mem; -#elif defined(_WIN32) - void *mem; - - mem = _aligned_malloc(bytes, alignment); - if (mem != NULL) { - (void) memset(mem, 0, bytes); - } - - return mem; -#else - uintptr_t ptr, buf; - - assert( alignment > 0 ); - - ptr = (uintptr_t)calloc(1, bytes + alignment + sizeof(void *)); - if (!ptr) - return NULL; - - buf = (ptr + alignment + sizeof(void *)) & ~(uintptr_t)(alignment - 1); - *(uintptr_t *)(buf - sizeof(void *)) = ptr; - -#ifndef NDEBUG - /* mark the non-aligned area */ - while ( ptr < buf - sizeof(void *) ) { - *(unsigned long *)ptr = 0xcdcdcdcd; - ptr += sizeof(unsigned long); - } -#endif - - return (void *)buf; -#endif /* defined(HAVE_POSIX_MEMALIGN) */ -} - -/** - * Free memory which was allocated with either _mesa_align_malloc() - * or _mesa_align_calloc(). - * \param ptr pointer to the memory to be freed. - * The actual address to free is stored in the word immediately before the - * address the client sees. - * Note that it is legal to pass NULL pointer to this function and will be - * handled accordingly. - */ -void -_mesa_align_free(void *ptr) -{ -#if defined(HAVE_POSIX_MEMALIGN) - free(ptr); -#elif defined(_WIN32) - _aligned_free(ptr); -#else - if (ptr) { - void **cubbyHole = (void **) ((char *) ptr - sizeof(void *)); - void *realAddr = *cubbyHole; - free(realAddr); - } -#endif /* defined(HAVE_POSIX_MEMALIGN) */ -} - -/** - * Reallocate memory, with alignment. - */ -void * -_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, - unsigned long alignment) -{ -#if defined(_WIN32) - (void) oldSize; - return _aligned_realloc(oldBuffer, newSize, alignment); -#else - const size_t copySize = (oldSize < newSize) ? oldSize : newSize; - void *newBuf = _mesa_align_malloc(newSize, alignment); - if (newBuf && oldBuffer && copySize > 0) { - memcpy(newBuf, oldBuffer, copySize); - } - - _mesa_align_free(oldBuffer); - return newBuf; -#endif -} - -/*@}*/ - /** Needed due to #ifdef's, above. */ int diff --git a/src/util/imports.h b/src/util/imports.h index 47c7d5931c4..4d7405dbf55 100644 --- a/src/util/imports.h +++ b/src/util/imports.h @@ -76,19 +76,6 @@ typedef union { float f; int i; unsigned u; } fi_type; * Functions */ -extern void * -_mesa_align_malloc( size_t bytes, unsigned long alignment ); - -extern void * -_mesa_align_calloc( size_t bytes, unsigned long alignment ); - -extern void -_mesa_align_free( void *ptr ); - -extern void * -_mesa_align_realloc(void *oldBuffer, size_t oldSize, size_t newSize, - unsigned long alignment); - extern int _mesa_snprintf( char *str, size_t size, const char *fmt, ... ) PRINTFLIKE(3, 4); |