adenilson / rpms / zlib

Forked from rpms/zlib 8 months ago
Clone

Blame SOURCES/zlib-1.2.11-IBM-Z-hw-accelrated-deflate-compressBound-fix.patch

f3d89c
Source from https://gitlab.com/redhat/centos-stream/rpms/zlib/-/merge_requests/9
f3d89c
Author: Ilya Leoshkevich
f3d89c
f3d89c
--- a/compress.c
f3d89c
+++ b/compress.c
f3d89c
@@ -5,9 +5,15 @@
f3d89c
 
f3d89c
 /* @(#) $Id$ */
f3d89c
 
f3d89c
-#define ZLIB_INTERNAL
f3d89c
+#include "zutil.h"
f3d89c
 #include "zlib.h"
f3d89c
 
f3d89c
+#ifdef DFLTCC
f3d89c
+#  include "contrib/s390/dfltcc.h"
f3d89c
+#else
f3d89c
+#define DEFLATE_BOUND_COMPLEN(source_len) 0
f3d89c
+#endif
f3d89c
+
f3d89c
 /* ===========================================================================
f3d89c
      Compresses the source buffer into the destination buffer. The level
f3d89c
    parameter has the same meaning as in deflateInit.  sourceLen is the byte
f3d89c
@@ -81,6 +87,12 @@ int ZEXPORT compress (dest, destLen, source, sourceLen)
f3d89c
 uLong ZEXPORT compressBound (sourceLen)
f3d89c
     uLong sourceLen;
f3d89c
 {
f3d89c
+    uLong complen = DEFLATE_BOUND_COMPLEN(sourceLen);
f3d89c
+
f3d89c
+    if (complen > 0)
f3d89c
+	/* Architecture-specific code provided an upper bound. */
f3d89c
+	return complen + ZLIB_WRAPLEN;
f3d89c
+
f3d89c
     return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
f3d89c
            (sourceLen >> 25) + 13;
f3d89c
 }
f3d89c
--- a/contrib/s390/dfltcc.h
f3d89c
+++ b/contrib/s390/dfltcc.h
f3d89c
@@ -12,6 +12,28 @@ void ZLIB_INTERNAL dfltcc_reset OF((z_streamp strm, uInt size));
f3d89c
 voidpf ZLIB_INTERNAL dfltcc_alloc_window OF((z_streamp strm, uInt items,
f3d89c
                                              uInt size));
f3d89c
 void ZLIB_INTERNAL dfltcc_free_window OF((z_streamp strm, voidpf w));
f3d89c
+#define DFLTCC_BLOCK_HEADER_BITS 3
f3d89c
+#define DFLTCC_HLITS_COUNT_BITS 5
f3d89c
+#define DFLTCC_HDISTS_COUNT_BITS 5
f3d89c
+#define DFLTCC_HCLENS_COUNT_BITS 4
f3d89c
+#define DFLTCC_MAX_HCLENS 19
f3d89c
+#define DFLTCC_HCLEN_BITS 3
f3d89c
+#define DFLTCC_MAX_HLITS 286
f3d89c
+#define DFLTCC_MAX_HDISTS 30
f3d89c
+#define DFLTCC_MAX_HLIT_HDIST_BITS 7
f3d89c
+#define DFLTCC_MAX_SYMBOL_BITS 16
f3d89c
+#define DFLTCC_MAX_EOBS_BITS 15
f3d89c
+#define DFLTCC_MAX_PADDING_BITS 7
f3d89c
+#define DEFLATE_BOUND_COMPLEN(source_len) \
f3d89c
+    ((DFLTCC_BLOCK_HEADER_BITS + \
f3d89c
+      DFLTCC_HLITS_COUNT_BITS + \
f3d89c
+      DFLTCC_HDISTS_COUNT_BITS + \
f3d89c
+      DFLTCC_HCLENS_COUNT_BITS + \
f3d89c
+      DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \
f3d89c
+      (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \
f3d89c
+      (source_len) * DFLTCC_MAX_SYMBOL_BITS + \
f3d89c
+      DFLTCC_MAX_EOBS_BITS + \
f3d89c
+      DFLTCC_MAX_PADDING_BITS) >> 3)
f3d89c
 int ZLIB_INTERNAL dfltcc_can_inflate OF((z_streamp strm));
f3d89c
 typedef enum {
f3d89c
     DFLTCC_INFLATE_CONTINUE,
f3d89c
diff --git a/contrib/s390/dfltcc_deflate.h b/contrib/s390/dfltcc_deflate.h
f3d89c
index 03f7f53..46acfc5 100644
f3d89c
--- a/contrib/s390/dfltcc_deflate.h
f3d89c
+++ b/contrib/s390/dfltcc_deflate.h
f3d89c
@@ -46,8 +46,7 @@ int ZLIB_INTERNAL dfltcc_deflate_get_dictionary OF((z_streamp strm,
f3d89c
 #define DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, source_len) \
f3d89c
     do { \
f3d89c
         if (dfltcc_can_deflate((strm))) \
f3d89c
-            (complen) = (3 + 5 + 5 + 4 + 19 * 3 + (286 + 30) * 7 + \
f3d89c
-                         (source_len) * 16 + 15 + 7) >> 3; \
f3d89c
+            (complen) = DEFLATE_BOUND_COMPLEN(source_len); \
f3d89c
     } while (0)
f3d89c
 #define DEFLATE_NEED_CONSERVATIVE_BOUND(strm) (dfltcc_can_deflate((strm)))
f3d89c
 #define DEFLATE_HOOK dfltcc_deflate
f3d89c
diff --git a/zutil.h b/zutil.h
f3d89c
index 14277bc..cf90e49 100644
f3d89c
--- a/zutil.h
f3d89c
+++ b/zutil.h
f3d89c
@@ -87,6 +87,8 @@ extern z_const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
f3d89c
 
f3d89c
 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
f3d89c
 
f3d89c
+#define ZLIB_WRAPLEN 6 /* zlib format overhead */
f3d89c
+
f3d89c
         /* target dependencies */
f3d89c
 
f3d89c
 #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))