From: Nathan Moinvaziri Date: Sun, 7 Jan 2024 01:55:25 +0000 (-0800) Subject: Use zng_alloc_aligned in unit tests to prevent having to use C++17. X-Git-Tag: 2.2.0~81 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d33c8163d69452079918676453b65f780b11de8;p=thirdparty%2Fzlib-ng.git Use zng_alloc_aligned in unit tests to prevent having to use C++17. 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. --- diff --git a/test/test_compare256.cc b/test/test_compare256.cc index 8900902f..b85dc1b4 100644 --- a/test/test_compare256.cc +++ b/test/test_compare256.cc @@ -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) \ diff --git a/test/test_compare256_rle.cc b/test/test_compare256_rle.cc index da60d6f9..4123ef20 100644 --- a/test/test_compare256_rle.cc +++ b/test/test_compare256_rle.cc @@ -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) \ diff --git a/test/test_crc32.cc b/test/test_crc32.cc index 0cdc3179..23711274 100644 --- a/test/test_crc32.cc +++ b/test/test_crc32.cc @@ -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 270a28c7..ce620e36 100644 --- 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; }