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

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