Skip to content

Commit

Permalink
Clean up memory allocation functions that are no longer used, and its…
Browse files Browse the repository at this point in the history
… tests.

Co-authored-by: Ilya Leoshkevich <iii@linux.ibm.com>
  • Loading branch information
Dead2 and iii-i committed May 21, 2024
1 parent 8793724 commit a4b111f
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 178 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,6 @@ if(WITH_OPTIM)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/s390_features.c)
endif()
endif()
if(WITH_DFLTCC_DEFLATE OR WITH_DFLTCC_INFLATE)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/dfltcc_common.c)
endif()
if(WITH_DFLTCC_DEFLATE)
add_definitions(-DS390_DFLTCC_DEFLATE)
list(APPEND ZLIB_ARCH_SRCS ${ARCHDIR}/dfltcc_deflate.c)
Expand Down
6 changes: 0 additions & 6 deletions arch/s390/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ s390_features.o:
s390_features.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/s390_features.c

dfltcc_common.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_common.c

dfltcc_common.lo:
$(CC) $(SFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_common.c

dfltcc_deflate.o:
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/dfltcc_deflate.c

Expand Down
7 changes: 4 additions & 3 deletions arch/s390/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ integrated with the rest of zlib-ng using hook macros.

DFLTCC takes as arguments a parameter block, an input buffer, an output
buffer, and a window. Parameter blocks are stored alongside zlib states;
buffers are forwarded from the caller; and window (which must be page-aligned)
is managed using `ZALLOC_WINDOW()`, `ZCOPY_WINDOW()` and `TRY_FREE_WINDOW()`
macros.
buffers are forwarded from the caller; and window - which must be
4k-aligned and is always 64k large, is managed using the `PAD_WINDOW()`,
`WINDOW_PAD_SIZE`, `HINT_ALIGNED_WINDOW` and `DEFLATE_ADJUST_WINDOW_SIZE()`
and `INFLATE_ADJUST_WINDOW_SIZE()` hooks.

Software and hardware window formats do not match, therefore,
`deflateSetDictionary()`, `deflateGetDictionary()`, `inflateSetDictionary()`
Expand Down
40 changes: 0 additions & 40 deletions arch/s390/dfltcc_common.c

This file was deleted.

12 changes: 0 additions & 12 deletions arch/s390/dfltcc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ typedef struct {
struct dfltcc_state common;
} arch_inflate_state;

void Z_INTERNAL *PREFIX(dfltcc_alloc_window)(PREFIX3(streamp) strm, uInt items, uInt size);
void Z_INTERNAL PREFIX(dfltcc_copy_window)(void *dest, const void *src, size_t n);
void Z_INTERNAL PREFIX(dfltcc_free_window)(PREFIX3(streamp) strm, void *w);

#define ZALLOC_WINDOW PREFIX(dfltcc_alloc_window)

#define ZCOPY_WINDOW PREFIX(dfltcc_copy_window)

#define ZFREE_WINDOW PREFIX(dfltcc_free_window)

#define TRY_FREE_WINDOW PREFIX(dfltcc_free_window)

/*
History buffer size.
*/
Expand Down
5 changes: 0 additions & 5 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -1832,11 +1832,6 @@ EOF
ARCH_SHARED_OBJS="${ARCH_SHARED_OBJS} s390_features.lo"
fi

if test $builddfltccdeflate -eq 1 -o $builddfltccinflate -eq 1; then
ARCH_STATIC_OBJS="${ARCH_STATIC_OBJS} dfltcc_common.o"
ARCH_SHARED_OBJS="${ARCH_SHARED_OBJS} dfltcc_common.lo"
fi

if test $builddfltccdeflate -eq 1; then
CFLAGS="${CFLAGS} -DS390_DFLTCC_DEFLATE"
SFLAGS="${SFLAGS} -DS390_DFLTCC_DEFLATE"
Expand Down
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ if(WITH_GTEST)
if(ZLIBNG_ENABLE_TESTS)
list(APPEND TEST_SRCS
test_adler32.cc # adler32_neon(), etc
test_aligned_alloc.cc # zng_alloc_aligned()
test_compare256.cc # compare256_neon(), etc
test_crc32.cc # crc32_acle(), etc
test_inflate_sync.cc # expects a certain compressed block layout
Expand Down
48 changes: 0 additions & 48 deletions test/test_aligned_alloc.cc

This file was deleted.

8 changes: 4 additions & 4 deletions test/test_compare256.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ static inline void compare256_match_check(compare256_func compare256) {
uint8_t *str1;
uint8_t *str2;

str1 = (uint8_t *)PREFIX3(alloc_aligned)(NULL, NULL, 1, MAX_COMPARE_SIZE, 64);
str1 = (uint8_t *)PREFIX(zcalloc)(NULL, 1, MAX_COMPARE_SIZE);
ASSERT_TRUE(str1 != NULL);
memset(str1, 'a', MAX_COMPARE_SIZE);

str2 = (uint8_t *)PREFIX3(alloc_aligned)(NULL, NULL, 1, MAX_COMPARE_SIZE, 64);
str2 = (uint8_t *)PREFIX(zcalloc)(NULL, 1, MAX_COMPARE_SIZE);
ASSERT_TRUE(str2 != NULL);
memset(str2, 'a', MAX_COMPARE_SIZE);

Expand All @@ -46,8 +46,8 @@ static inline void compare256_match_check(compare256_func compare256) {
str2[i] = 'a';
}

PREFIX3(free_aligned)(NULL, NULL, str1);
PREFIX3(free_aligned)(NULL, NULL, str2);
PREFIX(zcfree)(NULL, str1);
PREFIX(zcfree)(NULL, str2);
}

#define TEST_COMPARE256(name, func, support_flag) \
Expand Down
48 changes: 0 additions & 48 deletions zutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,51 +109,3 @@ void Z_INTERNAL PREFIX(zcfree)(void *opaque, void *ptr) {
Z_UNUSED(opaque);
zng_free(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 *PREFIX3(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;

/* If no custom calloc function used then call zlib-ng's aligned calloc */
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 */
alloc_size = sizeof(void *) + (items * size) + align;
ptr = zalloc(opaque, 1, alloc_size);
if (!ptr)
return NULL;

/* Calculate return pointer address with space enough to store original pointer */
align_diff = align - ((uintptr_t)ptr % align);
return_ptr = (uintptr_t)ptr + align_diff;
if (align_diff < sizeof(void *))
return_ptr += align;

/* Store the original pointer for free() */
original_ptr = return_ptr - sizeof(void *);
memcpy((void *)original_ptr, &ptr, sizeof(void *));

/* Return properly aligned pointer in allocation */
return (void *)return_ptr;
}

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 == NULL || zfree == PREFIX(zcfree)) {
PREFIX(zcfree)(opaque, ptr);
return;
}
if (!ptr)
return;

/* Calculate offset to original memory allocation pointer */
void *original_ptr = (void *)((uintptr_t)ptr - sizeof(void *));
void *free_ptr = *(void **)original_ptr;

/* Free original memory allocation */
zfree(opaque, free_ptr);
}
8 changes: 0 additions & 8 deletions zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,4 @@ void Z_INTERNAL PREFIX(zcfree)(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 *PREFIX3(alloc_aligned)(zng_calloc_func zalloc, void *opaque, unsigned items, unsigned size, unsigned align);
void Z_INTERNAL PREFIX3(free_aligned)(zng_cfree_func zfree, void *opaque, void *ptr);

#define ZALLOC(strm, items, size) PREFIX3(alloc_aligned)((strm)->zalloc, (strm)->opaque, (items), (size), 64)
#define ZFREE(strm, addr) PREFIX3(free_aligned)((strm)->zfree, (strm)->opaque, (void *)(addr))

#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}

#endif /* ZUTIL_H_ */

0 comments on commit a4b111f

Please sign in to comment.