]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Rename memory alignment functions because they handle custom allocator which is the...
authorNathan Moinvaziri <nathan@nathanm.com>
Mon, 11 Apr 2022 02:20:23 +0000 (19:20 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 13 Apr 2022 22:00:22 +0000 (00:00 +0200)
test/test_aligned_alloc.cc
zutil.c
zutil.h

index 5d8517163f6e8bbabfd62ecb3efdf79a849cdd36..259d474b87745d7ff6e89f36c09634f4902dacb4 100644 (file)
@@ -1,4 +1,4 @@
-/* test_aligned_alloc.cc - Test zng_calloc_aligned and zng_cfree_aligned */
+/* test_aligned_alloc.cc - Test zng_alloc_aligned and zng_free_aligned */
 
 #include <stdlib.h>
 #include <errno.h>
@@ -39,8 +39,8 @@ void zng_cfree_unaligned(void *opaque, void *ptr) {
 }
 
 TEST(zalloc, aligned_64) {
-    void *return_ptr = zng_calloc_aligned(zng_calloc_unaligned, 0, 1, 100, 64);
+    void *return_ptr = zng_alloc_aligned(zng_calloc_unaligned, 0, 1, 100, 64);
     ASSERT_TRUE(return_ptr != NULL);
     EXPECT_EQ((intptr_t)return_ptr % 64, 0);
-    zng_cfree_aligned(zng_cfree_unaligned, 0, return_ptr);
+    zng_free_aligned(zng_cfree_unaligned, 0, return_ptr);
 }
diff --git a/zutil.c b/zutil.c
index 2ca6aae4b2e8a0836feb6030f2de219e66a1bcf4..5583578615cc412e5b12d728ef0916179488bbef 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -112,7 +112,7 @@ void Z_INTERNAL zng_cfree(void *opaque, void *ptr) {
 
 /* Since we support custom memory allocators, some which might not align memory as we expect,
  * we have to ask for extra memory and return an aligned pointer. */
-void Z_INTERNAL *zng_calloc_aligned(zng_calloc_func zalloc, void *opaque, unsigned items, unsigned size, unsigned align) {
+void Z_INTERNAL *zng_alloc_aligned(zng_calloc_func zalloc, void *opaque, unsigned items, unsigned size, unsigned align) {
     uintptr_t return_ptr, original_ptr;
     uint32_t alloc_size, align_diff;
     void *ptr;
@@ -141,7 +141,7 @@ void Z_INTERNAL *zng_calloc_aligned(zng_calloc_func zalloc, void *opaque, unsign
     return (void *)return_ptr;
 }
 
-void Z_INTERNAL zng_cfree_aligned(zng_cfree_func zfree, void *opaque, void *ptr) {
+void Z_INTERNAL zng_free_aligned(zng_cfree_func zfree, void *opaque, void *ptr) {
     /* If no custom cfree function used then call zlib-ng's aligned cfree */
     if (zfree == zng_cfree) {
         zng_cfree(opaque, ptr);
diff --git a/zutil.h b/zutil.h
index 5022b36f54336c892ad18aa92b254ed739f91a42..f70eb4bdbbfa4466a4e484a80b6df6fcfbd1ace3 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -120,7 +120,7 @@ extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
 #  define OS_CODE  3  /* assume Unix */
 #endif
 
-         /* functions */
+         /* memory allocation functions */
 
 void Z_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size);
 void Z_INTERNAL   zng_cfree(void *opaque, void *ptr);
@@ -128,11 +128,11 @@ void Z_INTERNAL   zng_cfree(void *opaque, void *ptr);
 typedef void *zng_calloc_func(void *opaque, unsigned items, unsigned size);
 typedef void  zng_cfree_func(void *opaque, void *ptr);
 
-void Z_INTERNAL *zng_calloc_aligned(zng_calloc_func zalloc, void *opaque, unsigned items, unsigned size, unsigned align);
-void Z_INTERNAL  zng_cfree_aligned(zng_cfree_func zfree, void *opaque, void *ptr);
+void Z_INTERNAL *zng_alloc_aligned(zng_calloc_func zalloc, void *opaque, unsigned items, unsigned size, unsigned align);
+void Z_INTERNAL  zng_free_aligned(zng_cfree_func zfree, void *opaque, void *ptr);
 
-#define ZALLOC(strm, items, size) zng_calloc_aligned((strm)->zalloc, (strm)->opaque, (items), (size), 64)
-#define ZFREE(strm, addr)         zng_cfree_aligned((strm)->zfree, (strm)->opaque, (void *)(addr))
+#define ZALLOC(strm, items, size) zng_alloc_aligned((strm)->zalloc, (strm)->opaque, (items), (size), 64)
+#define ZFREE(strm, addr)         zng_free_aligned((strm)->zfree, (strm)->opaque, (void *)(addr))
 
 #define TRY_FREE(s, p)            {if (p) ZFREE(s, p);}