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.
This commit is contained in:
Nathan Moinvaziri 2024-01-06 17:55:25 -08:00 committed by Hans Kristian Rosbach
parent 2a03576b34
commit 9d33c8163d
4 changed files with 10 additions and 11 deletions

View 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) \

View 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) \

View File

@ -11,7 +11,6 @@
extern "C" {
# include "zbuild.h"
# include "zutil_p.h"
# include "test_cpu_features.h"
}

View File

@ -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;
}