lib: rename the aligned allocation functions

In preparation for adding libdeflate_malloc() and libdeflate_free(),
rename the aligned allocation functions to match.
This commit is contained in:
Eric Biggers 2020-04-02 23:49:00 -07:00
parent 64b4e8191e
commit 66bd59c4be
3 changed files with 10 additions and 12 deletions

View File

@ -2681,7 +2681,7 @@ libdeflate_alloc_compressor(int compression_level)
#endif #endif
size = offsetof(struct libdeflate_compressor, p) + sizeof(c->p.g); size = offsetof(struct libdeflate_compressor, p) + sizeof(c->p.g);
c = aligned_malloc(MATCHFINDER_ALIGNMENT, size); c = libdeflate_aligned_malloc(MATCHFINDER_ALIGNMENT, size);
if (!c) if (!c)
return NULL; return NULL;
@ -2765,7 +2765,7 @@ libdeflate_alloc_compressor(int compression_level)
break; break;
#endif #endif
default: default:
aligned_free(c); libdeflate_aligned_free(c);
return NULL; return NULL;
} }
@ -2801,7 +2801,7 @@ libdeflate_deflate_compress(struct libdeflate_compressor *c,
LIBDEFLATEEXPORT void LIBDEFLATEAPI LIBDEFLATEEXPORT void LIBDEFLATEAPI
libdeflate_free_compressor(struct libdeflate_compressor *c) libdeflate_free_compressor(struct libdeflate_compressor *c)
{ {
aligned_free(c); libdeflate_aligned_free(c);
} }
unsigned int unsigned int

View File

@ -15,9 +15,9 @@
#include "common_defs.h" #include "common_defs.h"
/* /*
* Prefix with "_libdeflate_" all global symbols which are not part of the API. * Prefix with "_libdeflate_" all global symbols which are not part of the API
* This avoids exposing overly generic names when libdeflate is built as a * and don't already have a "libdeflate" prefix. This avoids exposing overly
* static library. * generic names when libdeflate is built as a static library.
* *
* Note that the chosen prefix is not really important and can be changed * Note that the chosen prefix is not really important and can be changed
* without breaking library users. It was just chosen so that the resulting * without breaking library users. It was just chosen so that the resulting
@ -26,13 +26,11 @@
* shared library, since these symbols are not exported. * shared library, since these symbols are not exported.
*/ */
#define SYM_FIXUP(sym) _libdeflate_##sym #define SYM_FIXUP(sym) _libdeflate_##sym
#define aligned_malloc SYM_FIXUP(aligned_malloc)
#define aligned_free SYM_FIXUP(aligned_free)
#define deflate_get_compression_level SYM_FIXUP(deflate_get_compression_level) #define deflate_get_compression_level SYM_FIXUP(deflate_get_compression_level)
#define _cpu_features SYM_FIXUP(_cpu_features) #define _cpu_features SYM_FIXUP(_cpu_features)
#define setup_cpu_features SYM_FIXUP(setup_cpu_features) #define setup_cpu_features SYM_FIXUP(setup_cpu_features)
void *aligned_malloc(size_t alignment, size_t size); void *libdeflate_aligned_malloc(size_t alignment, size_t size);
void aligned_free(void *ptr); void libdeflate_aligned_free(void *ptr);
#endif /* LIB_LIB_COMMON_H */ #endif /* LIB_LIB_COMMON_H */

View File

@ -30,7 +30,7 @@
#include "lib_common.h" #include "lib_common.h"
void * void *
aligned_malloc(size_t alignment, size_t size) libdeflate_aligned_malloc(size_t alignment, size_t size)
{ {
void *ptr = malloc(sizeof(void *) + alignment - 1 + size); void *ptr = malloc(sizeof(void *) + alignment - 1 + size);
if (ptr) { if (ptr) {
@ -42,7 +42,7 @@ aligned_malloc(size_t alignment, size_t size)
} }
void void
aligned_free(void *ptr) libdeflate_aligned_free(void *ptr)
{ {
if (ptr) if (ptr)
free(((void **)ptr)[-1]); free(((void **)ptr)[-1]);