]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Clean up memory allocation functions that are no longer used, and its tests.
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Thu, 18 Apr 2024 13:28:56 +0000 (15:28 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Tue, 28 May 2024 14:35:13 +0000 (16:35 +0200)
Co-authored-by: Ilya Leoshkevich <iii@linux.ibm.com>
CMakeLists.txt
arch/s390/Makefile.in
arch/s390/README.md
arch/s390/dfltcc_common.c [deleted file]
arch/s390/dfltcc_common.h
configure
test/CMakeLists.txt
test/test_aligned_alloc.cc [deleted file]
test/test_compare256.cc
zutil.c
zutil.h

index 060f6cf56e1af4a6910bc8631e6a47cd3f0457c8..719673fbf34a1a313620855af212d94db21517fd 100644 (file)
@@ -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)
index 6b4fba7775c4a9dab198c6f647a6aea802fbcfa3..e994157df2d34a8e37de3b78c2aabf24a1c659cc 100644 (file)
@@ -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
 
index 0f3329108dc3df9ccff05d9a95387f56369c9c7e..57e9ee8f1471a54ba45069bee5330bf76a28861e 100644 (file)
@@ -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()`
diff --git a/arch/s390/dfltcc_common.c b/arch/s390/dfltcc_common.c
deleted file mode 100644 (file)
index 78be718..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* dfltcc_deflate.c - IBM Z DEFLATE CONVERSION CALL general support. */
-
-#include "zbuild.h"
-#include "dfltcc_common.h"
-#include "dfltcc_detail.h"
-
-/*
-   Memory management.
-
-   DFLTCC requires parameter blocks and window to be aligned. zlib-ng allows
-   users to specify their own allocation functions, so using e.g.
-   `posix_memalign' is not an option. Thus, we overallocate and take the
-   aligned portion of the buffer.
-*/
-
-static const int PAGE_ALIGN = 0x1000;
-
-void Z_INTERNAL *PREFIX(dfltcc_alloc_window)(PREFIX3(streamp) strm, uInt items, uInt size) {
-    void *p;
-    void *w;
-
-    /* To simplify freeing, we store the pointer to the allocated buffer right
-     * before the window. Note that DFLTCC always uses HB_SIZE bytes.
-     */
-    p = ZALLOC(strm, sizeof(void *) + MAX(items * size, HB_SIZE) + PAGE_ALIGN, sizeof(unsigned char));
-    if (p == NULL)
-        return NULL;
-    w = ALIGN_UP((char *)p + sizeof(void *), PAGE_ALIGN);
-    *(void **)((char *)w - sizeof(void *)) = p;
-    return w;
-}
-
-void Z_INTERNAL PREFIX(dfltcc_copy_window)(void *dest, const void *src, size_t n) {
-    memcpy(dest, src, MAX(n, HB_SIZE));
-}
-
-void Z_INTERNAL PREFIX(dfltcc_free_window)(PREFIX3(streamp) strm, void *w) {
-    if (w)
-        ZFREE(strm, *(void **)((unsigned char *)w - sizeof(void *)));
-}
index 8aec9e9453ea3a313ccf30ad0e2470a196a14079..a6527ab5df126ae3665a47eee777ba8490bafe2a 100644 (file)
@@ -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.
  */
index 4efe9cbd872b0760df543c1f693270e77a221ea8..6cf61da20f711376e534aa1fac2b76d32bed2970 100755 (executable)
--- a/configure
+++ b/configure
@@ -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"
index 3f0d023eb0c0ba828d4cab94fedc8bf18017dc0c..a57fb618022d536d4b143dfad136d46a54bc565a 100644 (file)
@@ -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
diff --git a/test/test_aligned_alloc.cc b/test/test_aligned_alloc.cc
deleted file mode 100644 (file)
index 07f99a9..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/* test_aligned_alloc.cc - Test zng_alloc_aligned and zng_free_aligned */
-
-#include <stdlib.h>
-#include <errno.h>
-#include <stdio.h>
-
-extern "C" {
-#  include "zbuild.h"
-#  include "zutil.h"
-}
-
-#include <gtest/gtest.h>
-
-#include "test_shared.h"
-
-void *zng_calloc_unaligned(void *opaque, unsigned items, unsigned size) {
-    uint8_t *pointer = (uint8_t *)calloc(1, (items * size) + 2);
-    Z_UNUSED(opaque);
-    if (pointer == NULL)
-        return pointer;
-    /* Store whether or not our allocation is aligned */
-    *pointer = ((uint64_t)(intptr_t)pointer + 1) % 2 == 0;
-    pointer++;
-    if (*pointer) {
-        /* Return pointer that is off by one */
-        pointer++;
-    }
-    return (void *)pointer;
-}
-
-void zng_cfree_unaligned(void *opaque, void *ptr) {
-    uint8_t *pointer = (uint8_t *)ptr;
-    Z_UNUSED(opaque);
-    pointer--;
-    /* Get whether or not our original memory pointer was aligned */
-    if (*pointer) {
-        /* Return original aligned pointer to free() */
-        pointer--;
-    }
-    free(pointer);
-}
-
-TEST(zalloc, aligned_64) {
-    void *return_ptr = PREFIX3(alloc_aligned)(zng_calloc_unaligned, 0, 1, 100, 64);
-    ASSERT_TRUE(return_ptr != NULL);
-    EXPECT_EQ((intptr_t)return_ptr % 64, 0);
-    PREFIX3(free_aligned)(zng_cfree_unaligned, 0, return_ptr);
-}
index ec2136aebadc67e08d39c8dc166abb6ae5a8777b..e1662cdf04953938752f44f37c4cdc4ee8159cd7 100644 (file)
@@ -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);
 
@@ -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) \
diff --git a/zutil.c b/zutil.c
index ce620e36ba55cd8e02c065f55e8c16445ad3245c..3dba7f78fd6f8d9cfa657736922df83477c64f68 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -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);
-}
diff --git a/zutil.h b/zutil.h
index fb27c08ee7b27cef0eb535f7c5112bf76f179d4c..a6284502d047e8af74a5d0159da9825b80625208 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -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_ */