]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Use zng_alloc_aligned in unit tests to prevent having to use C++17.
authorNathan Moinvaziri <nathan@nathanm.com>
Sun, 7 Jan 2024 01:55:25 +0000 (17:55 -0800)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 7 Feb 2024 18:16:28 +0000 (19:16 +0100)
alloc_aligned when using in C++ requires C++17 standard. zutil_p.h
include removed from test_crc32 since it was causing the same issue and was
not really needed.

test/test_compare256.cc
test/test_compare256_rle.cc
test/test_crc32.cc
zutil.c

index 8900902f912ff556377b37c14aa69f24e196a049..b85dc1b40b6eb0d18becb640546a7104a910f88c 100644 (file)
@@ -9,7 +9,7 @@
 
 extern "C" {
 #  include "zbuild.h"
-#  include "zutil_p.h"
+#  include "zutil.h"
 #  include "test_cpu_features.h"
 }
 
@@ -26,11 +26,11 @@ static inline void compare256_match_check(compare256_func compare256) {
     uint8_t *str1;
     uint8_t *str2;
 
-    str1 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
+    str1 = (uint8_t *)PREFIX3(alloc_aligned)(NULL, NULL, 1, MAX_COMPARE_SIZE, 64);
     ASSERT_TRUE(str1 != NULL);
     memset(str1, 'a', MAX_COMPARE_SIZE);
 
-    str2 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
+    str2 = (uint8_t *)PREFIX3(alloc_aligned)(NULL, NULL, 1, MAX_COMPARE_SIZE, 64);
     ASSERT_TRUE(str2 != NULL);
     memset(str2, 'a', MAX_COMPARE_SIZE);
 
@@ -45,8 +45,8 @@ static inline void compare256_match_check(compare256_func compare256) {
             str2[i] = 'a';
     }
 
-    zng_free(str1);
-    zng_free(str2);
+    PREFIX3(free_aligned)(NULL, NULL, str1);
+    PREFIX3(free_aligned)(NULL, NULL, str2);
 }
 
 #define TEST_COMPARE256(name, func, support_flag) \
index da60d6f975ddda717b7924a7b0076e2f1469c3b7..4123ef202bc3cc2f6cb877336bf9dab3ff8f75cb 100644 (file)
@@ -9,7 +9,7 @@
 
 extern "C" {
 #  include "zbuild.h"
-#  include "zutil_p.h"
+#  include "zutil.h"
 #  include "compare256_rle.h"
 }
 
@@ -23,7 +23,7 @@ static inline void compare256_rle_match_check(compare256_rle_func compare256_rle
     uint8_t str1[] = {'a', 'a', 0};
     uint8_t *str2;
 
-    str2 = (uint8_t *)zng_alloc(MAX_COMPARE_SIZE);
+    str2 = (uint8_t *)PREFIX3(alloc_aligned)(NULL, NULL, 1, MAX_COMPARE_SIZE, 64);
     ASSERT_TRUE(str2 != NULL);
     memset(str2, 'a', MAX_COMPARE_SIZE);
 
@@ -38,7 +38,7 @@ static inline void compare256_rle_match_check(compare256_rle_func compare256_rle
             str2[i] = 'a';
     }
 
-    zng_free(str2);
+    PREFIX3(free_aligned)(NULL, NULL, str2);
 }
 
 #define TEST_COMPARE256_RLE(name, func, support_flag) \
index 0cdc31791bad5958eb5b96dec56ff74244a2a96e..237112741ed6456463c51fc2a9dc9d24470d6ef3 100644 (file)
@@ -11,7 +11,6 @@
 
 extern "C" {
 #  include "zbuild.h"
-#  include "zutil_p.h"
 #  include "test_cpu_features.h"
 }
 
diff --git a/zutil.c b/zutil.c
index 270a28c742014767008bcaf6cd64b295c0658df6..ce620e36ba55cd8e02c065f55e8c16445ad3245c 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -118,7 +118,7 @@ void Z_INTERNAL *PREFIX3(alloc_aligned)(zng_calloc_func zalloc, void *opaque, un
     void *ptr;
 
     /* If no custom calloc function used then call zlib-ng's aligned calloc */
-    if (zalloc == PREFIX(zcalloc))
+    if (zalloc == NULL || zalloc == PREFIX(zcalloc))
         return PREFIX(zcalloc)(opaque, items, size);
 
     /* Allocate enough memory for proper alignment and to store the original memory pointer */
@@ -143,7 +143,7 @@ void Z_INTERNAL *PREFIX3(alloc_aligned)(zng_calloc_func zalloc, void *opaque, un
 
 void Z_INTERNAL PREFIX3(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 == PREFIX(zcfree)) {
+    if (zfree == NULL || zfree == PREFIX(zcfree)) {
         PREFIX(zcfree)(opaque, ptr);
         return;
     }