]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
IBM Z DFLTCC: Split deflate and inflate states
authorIlya Leoshkevich <iii@linux.ibm.com>
Wed, 13 Apr 2022 11:46:24 +0000 (13:46 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 28 Apr 2022 10:01:57 +0000 (12:01 +0200)
Currently deflate and inflate both use a common state struct. There are
several variables in this struct that we don't need for inflate, and
more may be coming in the future. Therefore split them in two separate
structs. This in turn requires splitting ZALLOC_STATE and ZCOPY_STATE
macros.

12 files changed:
arch/s390/README.md
arch/s390/dfltcc_common.c
arch/s390/dfltcc_common.h
arch/s390/dfltcc_deflate.c
arch/s390/dfltcc_deflate.h
arch/s390/dfltcc_detail.h
arch/s390/dfltcc_inflate.c
arch/s390/dfltcc_inflate.h
deflate.c
infback.c
inflate.c
inflate_p.h

index 90066f0f96f0d61cb60e5267fc00983a1e2315fe..18a7ca8cd9c13a086d2e2703c2ff4d9575e35831 100644 (file)
@@ -61,7 +61,8 @@ integrated with the rest of zlib-ng using hook macros.
 ## Hook macros
 
 DFLTCC takes as arguments a parameter block, an input buffer, an output
-buffer and a window. `ZALLOC_STATE()`, `ZFREE_STATE()`, `ZCOPY_STATE()`,
+buffer and a window. `ZALLOC_DEFLATE_STATE()`, `ZALLOC_INFLATE_STATE()`,
+`ZFREE_STATE()`, `ZCOPY_DEFLATE_STATE()`, `ZCOPY_INFLATE_STATE()`,
 `ZALLOC_WINDOW()` and `TRY_FREE_WINDOW()` macros encapsulate allocation
 details for the parameter block (which is allocated alongside zlib-ng
 state) and the window (which must be page-aligned).
index a5b5e1f3f31ad40e3987f5a4e3295ce8b55112c9..2937d8d645d703f9cf00664fa2f4b44aa8dd87eb 100644 (file)
    `posix_memalign' is not an option. Thus, we overallocate and take the
    aligned portion of the buffer.
 */
-static inline int is_dfltcc_enabled(void) {
-    uint64_t facilities[(DFLTCC_FACILITY / 64) + 1];
-    Z_REGISTER uint8_t r0 __asm__("r0");
-
-    memset(facilities, 0, sizeof(facilities));
-    r0 = sizeof(facilities) / sizeof(facilities[0]) - 1;
-    /* STFLE is supported since z9-109 and only in z/Architecture mode. When
-     * compiling with -m31, gcc defaults to ESA mode, however, since the kernel
-     * is 64-bit, it's always z/Architecture mode at runtime.
-     */
-    __asm__ volatile(
-#ifndef __clang__
-                     ".machinemode push\n"
-                     ".machinemode zarch\n"
-#endif
-                     "stfle %[facilities]\n"
-#ifndef __clang__
-                     ".machinemode pop\n"
-#endif
-                     : [facilities] "=Q" (facilities), [r0] "+r" (r0) :: "cc");
-    return is_bit_set((const char *)facilities, DFLTCC_FACILITY);
-}
-
-void Z_INTERNAL PREFIX(dfltcc_reset)(PREFIX3(streamp) strm, uInt size) {
-    struct dfltcc_state *dfltcc_state = (struct dfltcc_state *)((char *)strm->state + ALIGN_UP(size, 8));
-    struct dfltcc_qaf_param *param = (struct dfltcc_qaf_param *)&dfltcc_state->param;
-
-    /* Initialize available functions */
-    if (is_dfltcc_enabled()) {
-        dfltcc(DFLTCC_QAF, param, NULL, NULL, NULL, NULL, NULL);
-        memmove(&dfltcc_state->af, param, sizeof(dfltcc_state->af));
-    } else
-        memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af));
-
-    /* Initialize parameter block */
-    memset(&dfltcc_state->param, 0, sizeof(dfltcc_state->param));
-    dfltcc_state->param.nt = 1;
-
-    /* Initialize tuning parameters */
-    dfltcc_state->level_mask = DFLTCC_LEVEL_MASK;
-    dfltcc_state->block_size = DFLTCC_BLOCK_SIZE;
-    dfltcc_state->block_threshold = DFLTCC_FIRST_FHT_BLOCK_SIZE;
-    dfltcc_state->dht_threshold = DFLTCC_DHT_MIN_SAMPLE_SIZE;
-    dfltcc_state->param.ribm = DFLTCC_RIBM;
-}
-
-void Z_INTERNAL *PREFIX(dfltcc_alloc_state)(PREFIX3(streamp) strm, uInt items, uInt size) {
-    return ZALLOC(strm, ALIGN_UP(items * size, 8) + sizeof(struct dfltcc_state), sizeof(unsigned char));
-}
-
-void Z_INTERNAL PREFIX(dfltcc_copy_state)(void *dst, const void *src, uInt size) {
-    memcpy(dst, src, ALIGN_UP(size, 8) + sizeof(struct dfltcc_state));
-}
 
 static const int PAGE_ALIGN = 0x1000;
 
index 374e06e27161c32d9c2fddda63d717a9f38b38a3..4f48bd9a4f89799d3971e9d2d2ddab266bd4f5b1 100644 (file)
@@ -3,18 +3,11 @@
 
 #include "zutil.h"
 
-void Z_INTERNAL *PREFIX(dfltcc_alloc_state)(PREFIX3(streamp) strm, uInt items, uInt size);
-void Z_INTERNAL PREFIX(dfltcc_copy_state)(void *dst, const void *src, uInt size);
-void Z_INTERNAL PREFIX(dfltcc_reset)(PREFIX3(streamp) strm, uInt size);
 void Z_INTERNAL *PREFIX(dfltcc_alloc_window)(PREFIX3(streamp) strm, uInt items, uInt size);
 void Z_INTERNAL PREFIX(dfltcc_free_window)(PREFIX3(streamp) strm, void *w);
 
-#define ZALLOC_STATE PREFIX(dfltcc_alloc_state)
-
 #define ZFREE_STATE ZFREE
 
-#define ZCOPY_STATE PREFIX(dfltcc_copy_state)
-
 #define ZALLOC_WINDOW PREFIX(dfltcc_alloc_window)
 
 #define ZFREE_WINDOW PREFIX(dfltcc_free_window)
index b0889130176bf524ad4d8dc2e802a8fe08b1170c..0210ddc17f9432ff5ad2b520789a81f3ec48ce4b 100644 (file)
 #include "dfltcc_deflate.h"
 #include "dfltcc_detail.h"
 
+struct dfltcc_deflate_state {
+    struct dfltcc_state common;
+    uint16_t level_mask;               /* Levels on which to use DFLTCC */
+    uint32_t block_size;               /* New block each X bytes */
+    size_t block_threshold;            /* New block after total_in > X */
+    uint32_t dht_threshold;            /* New block only if avail_in >= X */
+};
+
+#define GET_DFLTCC_DEFLATE_STATE(state) ((struct dfltcc_deflate_state *)GET_DFLTCC_STATE(state))
+
+void Z_INTERNAL *PREFIX(dfltcc_alloc_deflate_state)(PREFIX3(streamp) strm) {
+    return dfltcc_alloc_state(strm, sizeof(deflate_state), sizeof(struct dfltcc_deflate_state));
+}
+
+void Z_INTERNAL PREFIX(dfltcc_reset_deflate_state)(PREFIX3(streamp) strm) {
+    deflate_state *state = (deflate_state *)strm->state;
+    struct dfltcc_deflate_state *dfltcc_state = GET_DFLTCC_DEFLATE_STATE(state);
+
+    dfltcc_reset_state(&dfltcc_state->common);
+
+    /* Initialize tuning parameters */
+    dfltcc_state->level_mask = DFLTCC_LEVEL_MASK;
+    dfltcc_state->block_size = DFLTCC_BLOCK_SIZE;
+    dfltcc_state->block_threshold = DFLTCC_FIRST_FHT_BLOCK_SIZE;
+    dfltcc_state->dht_threshold = DFLTCC_DHT_MIN_SAMPLE_SIZE;
+}
+
+void Z_INTERNAL PREFIX(dfltcc_copy_deflate_state)(void *dst, const void *src) {
+    dfltcc_copy_state(dst, src, sizeof(deflate_state), sizeof(struct dfltcc_deflate_state));
+}
+
 static inline int dfltcc_can_deflate_with_params(PREFIX3(streamp) strm, int level, uInt window_bits, int strategy,
                                        int reproducible) {
     deflate_state *state = (deflate_state *)strm->state;
-    struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
+    struct dfltcc_deflate_state *dfltcc_state = GET_DFLTCC_DEFLATE_STATE(state);
 
     /* Unsupported compression settings */
     if ((dfltcc_state->level_mask & (1 << level)) == 0)
@@ -35,9 +66,9 @@ static inline int dfltcc_can_deflate_with_params(PREFIX3(streamp) strm, int leve
         return 0;
 
     /* Unsupported hardware */
-    if (!is_bit_set(dfltcc_state->af.fns, DFLTCC_GDHT) ||
-            !is_bit_set(dfltcc_state->af.fns, DFLTCC_CMPR) ||
-            !is_bit_set(dfltcc_state->af.fmts, DFLTCC_FMT0))
+    if (!is_bit_set(dfltcc_state->common.af.fns, DFLTCC_GDHT) ||
+            !is_bit_set(dfltcc_state->common.af.fns, DFLTCC_CMPR) ||
+            !is_bit_set(dfltcc_state->common.af.fmts, DFLTCC_FMT0))
         return 0;
 
     return 1;
@@ -96,8 +127,8 @@ static inline void send_eobs(PREFIX3(streamp) strm, const struct dfltcc_param_v0
 
 int Z_INTERNAL PREFIX(dfltcc_deflate)(PREFIX3(streamp) strm, int flush, block_state *result) {
     deflate_state *state = (deflate_state *)strm->state;
-    struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
-    struct dfltcc_param_v0 *param = &dfltcc_state->param;
+    struct dfltcc_deflate_state *dfltcc_state = GET_DFLTCC_DEFLATE_STATE(state);
+    struct dfltcc_param_v0 *param = &dfltcc_state->common.param;
     uInt masked_avail_in;
     dfltcc_cc cc;
     int need_empty_block;
@@ -234,7 +265,7 @@ again:
     } while (cc == DFLTCC_CC_AGAIN);
 
     /* Translate parameter block to stream */
-    strm->msg = oesc_msg(dfltcc_state->msg, param->oesc);
+    strm->msg = oesc_msg(dfltcc_state->common.msg, param->oesc);
     state->bi_valid = param->sbb;
     if (state->bi_valid == 0)
         state->bi_buf = 0; /* Avoid accessing next_out */
index 15473540c9d5bb223c04ccaeaa408ef38b54b131..d12523017df37c76e2e1760771f9cd263f366e6e 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "dfltcc_common.h"
 
+void Z_INTERNAL *PREFIX(dfltcc_alloc_deflate_state)(PREFIX3(streamp));
+void Z_INTERNAL PREFIX(dfltcc_reset_deflate_state)(PREFIX3(streamp));
+void Z_INTERNAL PREFIX(dfltcc_copy_deflate_state)(void *dst, const void *src);
 int Z_INTERNAL PREFIX(dfltcc_can_deflate)(PREFIX3(streamp) strm);
 int Z_INTERNAL PREFIX(dfltcc_deflate)(PREFIX3(streamp) strm, int flush, block_state *result);
 int Z_INTERNAL PREFIX(dfltcc_deflate_params)(PREFIX3(streamp) strm, int level, int strategy, int *flush);
@@ -12,6 +15,9 @@ int Z_INTERNAL PREFIX(dfltcc_deflate_set_dictionary)(PREFIX3(streamp) strm,
                                                 const unsigned char *dictionary, uInt dict_length);
 int Z_INTERNAL PREFIX(dfltcc_deflate_get_dictionary)(PREFIX3(streamp) strm, unsigned char *dictionary, uInt* dict_length);
 
+#define ZALLOC_DEFLATE_STATE PREFIX(dfltcc_alloc_deflate_state)
+#define ZCOPY_DEFLATE_STATE PREFIX(dfltcc_copy_deflate_state)
+
 #define DEFLATE_SET_DICTIONARY_HOOK(strm, dict, dict_len) \
     do { \
         if (PREFIX(dfltcc_can_deflate)((strm))) \
@@ -24,8 +30,7 @@ int Z_INTERNAL PREFIX(dfltcc_deflate_get_dictionary)(PREFIX3(streamp) strm, unsi
             return PREFIX(dfltcc_deflate_get_dictionary)((strm), (dict), (dict_len)); \
     } while (0)
 
-#define DEFLATE_RESET_KEEP_HOOK(strm) \
-    PREFIX(dfltcc_reset)((strm), sizeof(deflate_state))
+#define DEFLATE_RESET_KEEP_HOOK PREFIX(dfltcc_reset_deflate_state)
 
 #define DEFLATE_PARAMS_HOOK(strm, level, strategy, hook_flush) \
     do { \
index 4ec03f8097dc650b80086ae91bc9a21c9f4eb1eb..82924231eac9d204f4d54ef64d3bae86b2c85c2b 100644 (file)
@@ -1,6 +1,7 @@
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
+#include <string.h>
 
 #ifdef HAVE_SYS_SDT_H
 #include <sys/sdt.h>
@@ -115,6 +116,29 @@ static inline void clear_bit(char *bits, int n) {
     bits[n / 8] &= ~(1 << (7 - (n % 8)));
 }
 
+static inline int is_dfltcc_enabled(void) {
+    uint64_t facilities[(DFLTCC_FACILITY / 64) + 1];
+    Z_REGISTER uint8_t r0 __asm__("r0");
+
+    memset(facilities, 0, sizeof(facilities));
+    r0 = sizeof(facilities) / sizeof(facilities[0]) - 1;
+    /* STFLE is supported since z9-109 and only in z/Architecture mode. When
+     * compiling with -m31, gcc defaults to ESA mode, however, since the kernel
+     * is 64-bit, it's always z/Architecture mode at runtime.
+     */
+    __asm__ volatile(
+#ifndef __clang__
+                     ".machinemode push\n"
+                     ".machinemode zarch\n"
+#endif
+                     "stfle %[facilities]\n"
+#ifndef __clang__
+                     ".machinemode pop\n"
+#endif
+                     : [facilities] "=Q" (facilities), [r0] "+r" (r0) :: "cc");
+    return is_bit_set((const char *)facilities, DFLTCC_FACILITY);
+}
+
 #define DFLTCC_FMT0 0
 
 /*
@@ -187,13 +211,31 @@ static inline z_const char *oesc_msg(char *buf, int oesc) {
 struct dfltcc_state {
     struct dfltcc_param_v0 param;      /* Parameter block. */
     struct dfltcc_qaf_param af;        /* Available functions. */
-    uint16_t level_mask;               /* Levels on which to use DFLTCC */
-    uint32_t block_size;               /* New block each X bytes */
-    size_t block_threshold;            /* New block after total_in > X */
-    uint32_t dht_threshold;            /* New block only if avail_in >= X */
     char msg[64];                      /* Buffer for strm->msg */
 };
 
 #define ALIGN_UP(p, size) (__typeof__(p))(((uintptr_t)(p) + ((size) - 1)) & ~((size) - 1))
 
 #define GET_DFLTCC_STATE(state) ((struct dfltcc_state *)((char *)(state) + ALIGN_UP(sizeof(*state), 8)))
+
+static inline void *dfltcc_alloc_state(PREFIX3(streamp) strm, uInt size, uInt extension_size) {
+    return ZALLOC(strm, 1, ALIGN_UP(size, 8) + extension_size);
+}
+
+static inline void dfltcc_reset_state(struct dfltcc_state *dfltcc_state) {
+    /* Initialize available functions */
+    if (is_dfltcc_enabled()) {
+        dfltcc(DFLTCC_QAF, &dfltcc_state->param, NULL, NULL, NULL, NULL, NULL);
+        memmove(&dfltcc_state->af, &dfltcc_state->param, sizeof(dfltcc_state->af));
+    } else
+        memset(&dfltcc_state->af, 0, sizeof(dfltcc_state->af));
+
+    /* Initialize parameter block */
+    memset(&dfltcc_state->param, 0, sizeof(dfltcc_state->param));
+    dfltcc_state->param.nt = 1;
+    dfltcc_state->param.ribm = DFLTCC_RIBM;
+}
+
+static inline void dfltcc_copy_state(void *dst, const void *src, uInt size, uInt extension_size) {
+    memcpy(dst, src, ALIGN_UP(size, 8) + extension_size);
+}
index 99024dc9c5898c8960d0a3e507afdb31b37ea377..7a422d97e4a833ed353d80e8fe1e46a9df3202a1 100644 (file)
 #include "dfltcc_inflate.h"
 #include "dfltcc_detail.h"
 
+struct inflate_state Z_INTERNAL *PREFIX(dfltcc_alloc_inflate_state)(PREFIX3(streamp) strm) {
+    return (struct inflate_state *)dfltcc_alloc_state(strm, sizeof(struct inflate_state), sizeof(struct dfltcc_state));
+}
+
+void Z_INTERNAL PREFIX(dfltcc_reset_inflate_state)(PREFIX3(streamp) strm) {
+    struct inflate_state *state = (struct inflate_state *)strm->state;
+    struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
+
+    dfltcc_reset_state(dfltcc_state);
+}
+
+void Z_INTERNAL PREFIX(dfltcc_copy_inflate_state)(struct inflate_state *dst, const struct inflate_state *src) {
+    dfltcc_copy_state(dst, src, sizeof(struct inflate_state), sizeof(struct dfltcc_state));
+}
+
 int Z_INTERNAL PREFIX(dfltcc_can_inflate)(PREFIX3(streamp) strm) {
     struct inflate_state *state = (struct inflate_state *)strm->state;
     struct dfltcc_state *dfltcc_state = GET_DFLTCC_STATE(state);
index 69158ef03205a9b42f3b0aa535b2f71843fbc66d..5e86fe87f4409c0c265f03cf6390f0583ec78c94 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "dfltcc_common.h"
 
+struct inflate_state Z_INTERNAL *PREFIX(dfltcc_alloc_inflate_state)(PREFIX3(streamp) strm);
+void Z_INTERNAL PREFIX(dfltcc_reset_inflate_state)(PREFIX3(streamp) strm);
+void Z_INTERNAL PREFIX(dfltcc_copy_inflate_state)(struct inflate_state *dst, const struct inflate_state *src);
 int Z_INTERNAL PREFIX(dfltcc_can_inflate)(PREFIX3(streamp) strm);
 typedef enum {
     DFLTCC_INFLATE_CONTINUE,
@@ -13,8 +16,10 @@ dfltcc_inflate_action Z_INTERNAL PREFIX(dfltcc_inflate)(PREFIX3(streamp) strm, i
 int Z_INTERNAL PREFIX(dfltcc_was_inflate_used)(PREFIX3(streamp) strm);
 int Z_INTERNAL PREFIX(dfltcc_inflate_disable)(PREFIX3(streamp) strm);
 
-#define INFLATE_RESET_KEEP_HOOK(strm) \
-    PREFIX(dfltcc_reset)((strm), sizeof(struct inflate_state))
+#define ZALLOC_INFLATE_STATE PREFIX(dfltcc_alloc_inflate_state)
+#define ZCOPY_INFLATE_STATE PREFIX(dfltcc_copy_inflate_state)
+
+#define INFLATE_RESET_KEEP_HOOK PREFIX(dfltcc_reset_inflate_state)
 
 #define INFLATE_PRIME_HOOK(strm, bits, value) \
     do { if (PREFIX(dfltcc_inflate_disable)((strm))) return Z_STREAM_ERROR; } while (0)
index cbf2b1cb4d36ca672663c12e19ffe9ed0d77a366..a98988a831fbbdc6030c2dd44abfe92067d14804 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -68,9 +68,9 @@ const char PREFIX(deflate_copyright)[] = " deflate 1.2.11.f Copyright 1995-2016
 #  include "arch/s390/dfltcc_deflate.h"
 #else
 /* Memory management for the deflate state. Useful for allocating arch-specific extension blocks. */
-#  define ZALLOC_STATE(strm, items, size) ZALLOC(strm, items, size)
+#  define ZALLOC_DEFLATE_STATE(strm) ((deflate_state *)ZALLOC(strm, 1, sizeof(deflate_state)))
 #  define ZFREE_STATE(strm, addr) ZFREE(strm, addr)
-#  define ZCOPY_STATE(dst, src, size) memcpy(dst, src, size)
+#  define ZCOPY_DEFLATE_STATE(dst, src) memcpy(dst, src, sizeof(deflate_state))
 /* Memory management for the window. Useful for allocation the aligned window. */
 #  define ZALLOC_WINDOW(strm, items, size) ZALLOC(strm, items, size)
 #  define TRY_FREE_WINDOW(strm, addr) TRY_FREE(strm, addr)
@@ -230,7 +230,7 @@ int32_t Z_EXPORT PREFIX(deflateInit2_)(PREFIX3(stream) *strm, int32_t level, int
     if (windowBits == 8)
         windowBits = 9;  /* until 256-byte window bug fixed */
 
-    s = (deflate_state *) ZALLOC_STATE(strm, 1, sizeof(deflate_state));
+    s = ZALLOC_DEFLATE_STATE(strm);
     if (s == NULL)
         return Z_MEM_ERROR;
     strm->state = (struct internal_state *)s;
@@ -1024,11 +1024,11 @@ int32_t Z_EXPORT PREFIX(deflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
 
     memcpy((void *)dest, (void *)source, sizeof(PREFIX3(stream)));
 
-    ds = (deflate_state *) ZALLOC_STATE(dest, 1, sizeof(deflate_state));
+    ds = ZALLOC_DEFLATE_STATE(dest);
     if (ds == NULL)
         return Z_MEM_ERROR;
     dest->state = (struct internal_state *) ds;
-    ZCOPY_STATE((void *)ds, (void *)ss, sizeof(deflate_state));
+    ZCOPY_DEFLATE_STATE(ds, ss);
     ds->strm = dest;
 
 #ifdef X86_PCLMULQDQ_CRC
index c3f0fccc8a73affa8b555c40eced502840e0344d..5112a332b466f65e73c4f46b2e72231a85a33411 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -40,7 +40,7 @@ int32_t Z_EXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int32_t windowB
     }
     if (strm->zfree == NULL)
         strm->zfree = zng_cfree;
-    state = (struct inflate_state *)ZALLOC_STATE(strm, 1, sizeof(struct inflate_state));
+    state = ZALLOC_INFLATE_STATE(strm);
     if (state == NULL)
         return Z_MEM_ERROR;
     Tracev((stderr, "inflate: allocated\n"));
index 86f02cc4bf85e904cce0ce7c2a07397d90ad8ec9..8ada6466afa85b456f1ecb0046e52238ee84fc03 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -145,7 +145,7 @@ int32_t Z_EXPORT PREFIX(inflateInit2_)(PREFIX3(stream) *strm, int32_t windowBits
     }
     if (strm->zfree == NULL)
         strm->zfree = zng_cfree;
-    state = (struct inflate_state *) ZALLOC_STATE(strm, 1, sizeof(struct inflate_state));
+    state = ZALLOC_INFLATE_STATE(strm);
     if (state == NULL)
         return Z_MEM_ERROR;
     Tracev((stderr, "inflate: allocated\n"));
@@ -1278,7 +1278,7 @@ int32_t Z_EXPORT PREFIX(inflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
     state = (struct inflate_state *)source->state;
 
     /* allocate space */
-    copy = (struct inflate_state *)ZALLOC_STATE(source, 1, sizeof(struct inflate_state));
+    copy = ZALLOC_INFLATE_STATE(source);
     if (copy == NULL)
         return Z_MEM_ERROR;
     window = NULL;
@@ -1293,7 +1293,7 @@ int32_t Z_EXPORT PREFIX(inflateCopy)(PREFIX3(stream) *dest, PREFIX3(stream) *sou
 
     /* copy state */
     memcpy((void *)dest, (void *)source, sizeof(PREFIX3(stream)));
-    ZCOPY_STATE((void *)copy, (void *)state, sizeof(struct inflate_state));
+    ZCOPY_INFLATE_STATE(copy, state);
     copy->strm = dest;
     if (state->lencode >= state->codes && state->lencode <= state->codes + ENOUGH - 1) {
         copy->lencode = copy->codes + (state->lencode - state->codes);
index ecc1060642e7d4319a126a79a318cae7e79b996e..a0b6aa8fb585af66f5cd6657a9aeeec9a696a049 100644 (file)
@@ -10,9 +10,9 @@
 #  include "arch/s390/dfltcc_inflate.h"
 #else
 /* Memory management for the inflate state. Useful for allocating arch-specific extension blocks. */
-#  define ZALLOC_STATE(strm, items, size) ZALLOC(strm, items, size)
+#  define ZALLOC_INFLATE_STATE(strm) ((struct inflate_state *)ZALLOC(strm, 1, sizeof(struct inflate_state)))
 #  define ZFREE_STATE(strm, addr) ZFREE(strm, addr)
-#  define ZCOPY_STATE(dst, src, size) memcpy(dst, src, size)
+#  define ZCOPY_INFLATE_STATE(dst, src) memcpy(dst, src, sizeof(struct inflate_state))
 /* Memory management for the window. Useful for allocation the aligned window. */
 #  define ZALLOC_WINDOW(strm, items, size) ZALLOC(strm, items, size)
 #  define ZFREE_WINDOW(strm, addr) ZFREE(strm, addr)