adenilson / rpms / zlib

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