]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Reintroduce support for ZLIB_CONST in compat mode. (#704)
authorMika Lindqvist <postmaster@raasu.org>
Sun, 23 Aug 2020 07:58:57 +0000 (10:58 +0300)
committerGitHub <noreply@github.com>
Sun, 23 Aug 2020 07:58:57 +0000 (09:58 +0200)
* Reintroduce support for ZLIB_CONST in compat mode.

15 files changed:
compress.c
deflate.c
gzwrite.c
infback.c
inffast.c
inflate_p.h
test/example.c
test/infcover.c
test/minideflate.c
uncompr.c
zconf-ng.h.in
zconf.h.in
zlib.h
zutil.c
zutil.h

index bbbed658ed33bce58bc63f93daba5bd08886a0dd..453bdea1b09f21505a1a591ce6b252190b46d6f4 100644 (file)
@@ -42,7 +42,7 @@ int ZEXPORT PREFIX(compress2)(unsigned char *dest, z_size_t *destLen, const unsi
 
     stream.next_out = dest;
     stream.avail_out = 0;
-    stream.next_in = (const unsigned char *)source;
+    stream.next_in = (z_const unsigned char *)source;
     stream.avail_in = 0;
 
     do {
index a7d9a5a09f5594be90b15f5c8877ed81e45244bc..cb88d55dcaf0054b85b0ae4bc3adf927c0e14900 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -458,7 +458,7 @@ int32_t ZEXPORT PREFIX(deflateSetDictionary)(PREFIX3(stream) *strm, const uint8_
     avail = strm->avail_in;
     next = strm->next_in;
     strm->avail_in = dictLength;
-    strm->next_in = (const unsigned char *)dictionary;
+    strm->next_in = (z_const unsigned char *)dictionary;
     fill_window(s);
     while (s->lookahead >= MIN_MATCH) {
         str = s->strstart;
@@ -474,7 +474,7 @@ int32_t ZEXPORT PREFIX(deflateSetDictionary)(PREFIX3(stream) *strm, const uint8_
     s->lookahead = 0;
     s->prev_length = MIN_MATCH-1;
     s->match_available = 0;
-    strm->next_in = next;
+    strm->next_in = (z_const unsigned char *)next;
     strm->avail_in = avail;
     s->wrap = wrap;
     return Z_OK;
index b98022e621ec0b1f35440a9f9c8e7835ccb80791..dacca6b607f61b0f45c19be1a7e704b6a2bc6222 100644 (file)
--- a/gzwrite.c
+++ b/gzwrite.c
@@ -212,7 +212,7 @@ static size_t gz_write(gz_state *state, void const *buf, size_t len) {
             return 0;
 
         /* directly compress user buffer to file */
-        state->strm.next_in = (const unsigned char *)buf;
+        state->strm.next_in = (z_const unsigned char *) buf;
         do {
             unsigned n = (unsigned)-1;
             if (n > len)
index 5691c2bfed9e37bcd868b5626e2d2b16003819c7..f0f3fa59a68d73ceafe1ec686cca2c4d16087d4c 100644 (file)
--- a/infback.c
+++ b/infback.c
@@ -129,17 +129,17 @@ int32_t ZEXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int32_t windowBi
  */
 int32_t ZEXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in_desc, out_func out, void *out_desc) {
     struct inflate_state *state;
-    const unsigned char *next;  /* next input */
-    unsigned char *put;         /* next output */
-    unsigned have, left;        /* available input and output */
-    uint32_t hold;              /* bit buffer */
-    unsigned bits;              /* bits in bit buffer */
-    unsigned copy;              /* number of stored or match bytes to copy */
-    unsigned char *from;        /* where to copy match bytes from */
-    code here;                  /* current decoding table entry */
-    code last;                  /* parent table entry */
-    unsigned len;               /* length to copy for repeats, bits to drop */
-    int32_t ret;                /* return code */
+    z_const unsigned char *next; /* next input */
+    unsigned char *put;          /* next output */
+    unsigned have, left;         /* available input and output */
+    uint32_t hold;               /* bit buffer */
+    unsigned bits;               /* bits in bit buffer */
+    unsigned copy;               /* number of stored or match bytes to copy */
+    unsigned char *from;         /* where to copy match bytes from */
+    code here;                   /* current decoding table entry */
+    code last;                   /* parent table entry */
+    unsigned len;                /* length to copy for repeats, bits to drop */
+    int32_t ret;                 /* return code */
     static const uint16_t order[19] = /* permutation of code lengths */
         {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
 
index 2953e09e46845d655ad597eb2815bda352e0cc91..dd904a4870cd0390813c765c2a6e3ae2cfb1fab5 100644 (file)
--- a/inffast.c
+++ b/inffast.c
@@ -65,7 +65,7 @@ static inline uint64_t load_64_bits(const unsigned char *in, unsigned bits) {
 void ZLIB_INTERNAL zng_inflate_fast(PREFIX3(stream) *strm, unsigned long start) {
     /* start: inflate()'s starting value for strm->avail_out */
     struct inflate_state *state;
-    const unsigned char *in;    /* local strm->next_in */
+    z_const unsigned char *in;  /* local strm->next_in */
     const unsigned char *last;  /* have enough input while in < last */
     unsigned char *out;         /* local strm->next_out */
     unsigned char *beg;         /* inflate()'s initial strm->next_out */
index 7225e96de7a7b13c2e0fc836285174cb4cbfd696..13523b3e3681ba6b2ed9e79a34868829a8285089 100644 (file)
@@ -52,7 +52,7 @@
     do { \
         strm->next_out = put; \
         strm->avail_out = left; \
-        strm->next_in = next; \
+        strm->next_in = (z_const unsigned char *)next; \
         strm->avail_in = have; \
         state->hold = hold; \
         state->bits = bits; \
index 70969f46e545c7f516d84c10a4ae88815e908cb0..4010c91dc38c8a6d6f81a2158fea6de3613e6519 100644 (file)
@@ -250,7 +250,7 @@ void test_deflate(unsigned char *compr, size_t comprLen) {
     err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
     CHECK_ERR(err, "deflateInit");
 
-    c_stream.next_in  = (const unsigned char *)hello;
+    c_stream.next_in  = (z_const unsigned char *)hello;
     c_stream.next_out = compr;
 
     while (c_stream.total_in != len && c_stream.total_out < comprLen) {
@@ -283,7 +283,7 @@ void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr,
     d_stream.zfree = zfree;
     d_stream.opaque = (void *)0;
 
-    d_stream.next_in  = (const unsigned char *)compr;
+    d_stream.next_in  = compr;
     d_stream.avail_in = 0;
     d_stream.next_out = uncompr;
     d_stream.total_in = 0;
@@ -345,7 +345,7 @@ void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *un
     /* At this point, uncompr is still mostly zeroes, so it should compress
      * very well:
      */
-    c_stream.next_in = (const unsigned char *)uncompr;
+    c_stream.next_in = uncompr;
     c_stream.avail_in = (unsigned int)uncomprLen;
     err = PREFIX(deflate)(&c_stream, Z_NO_FLUSH);
     CHECK_ERR(err, "deflate");
@@ -376,7 +376,7 @@ void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *un
     } else {
         PREFIX(deflateParams)(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
     }
-    c_stream.next_in = (const unsigned char *)compr;
+    c_stream.next_in = compr;
     diff = (unsigned int)(c_stream.next_out - compr);
     c_stream.avail_in = diff;
     err = PREFIX(deflate)(&c_stream, Z_NO_FLUSH);
@@ -406,7 +406,7 @@ void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *un
     } else {
         PREFIX(deflateParams)(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
     }
-    c_stream.next_in = (const unsigned char *)uncompr;
+    c_stream.next_in = uncompr;
     c_stream.avail_in = (unsigned int)uncomprLen;
     err = PREFIX(deflate)(&c_stream, Z_NO_FLUSH);
     CHECK_ERR(err, "deflate");
@@ -433,7 +433,7 @@ void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *un
     d_stream.zfree = zfree;
     d_stream.opaque = (void *)0;
 
-    d_stream.next_in  = (const unsigned char *)compr;
+    d_stream.next_in  = compr;
     d_stream.avail_in = (unsigned int)comprLen;
     d_stream.total_in = 0;
     d_stream.total_out = 0;
@@ -475,7 +475,7 @@ void test_flush(unsigned char *compr, z_size_t *comprLen) {
     err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
     CHECK_ERR(err, "deflateInit");
 
-    c_stream.next_in  = (const unsigned char *)hello;
+    c_stream.next_in  = (z_const unsigned char *)hello;
     c_stream.next_out = compr;
     c_stream.avail_in = 3;
     c_stream.avail_out = (unsigned int)*comprLen;
@@ -508,7 +508,7 @@ void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, si
     d_stream.zfree = zfree;
     d_stream.opaque = (void *)0;
 
-    d_stream.next_in  = (const unsigned char *)compr;
+    d_stream.next_in  = compr;
     d_stream.avail_in = 2; /* just read the zlib header */
 
     err = PREFIX(inflateInit)(&d_stream);
@@ -558,7 +558,7 @@ void test_dict_deflate(unsigned char *compr, size_t comprLen) {
     c_stream.next_out = compr;
     c_stream.avail_out = (unsigned int)comprLen;
 
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.avail_in = (unsigned int)strlen(hello)+1;
 
     err = PREFIX(deflate)(&c_stream, Z_FINISH);
@@ -583,7 +583,7 @@ void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *unc
     d_stream.zfree = zfree;
     d_stream.opaque = (void *)0;
     d_stream.adler = 0;
-    d_stream.next_in  = (const unsigned char *)compr;
+    d_stream.next_in  = compr;
     d_stream.avail_in = (unsigned int)comprLen;
 
     err = PREFIX(inflateInit)(&d_stream);
@@ -631,7 +631,7 @@ void test_deflate_bound(void) {
     c_stream.zfree = zfree;
     c_stream.opaque = (voidpf)0;
     c_stream.avail_in = len;
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.avail_out = 0;
     c_stream.next_out = outBuf;
 
@@ -679,7 +679,7 @@ void test_deflate_copy(unsigned char *compr, size_t comprLen) {
     err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
     CHECK_ERR(err, "deflateInit");
 
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.next_out = compr;
 
     while (c_stream.total_in != len && c_stream.total_out < comprLen) {
@@ -729,7 +729,7 @@ void test_deflate_get_dict(unsigned char *compr, size_t comprLen) {
     c_stream.next_out = compr;
     c_stream.avail_out = (uInt)comprLen;
 
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.avail_in = (unsigned int)strlen(hello)+1;
 
     err = PREFIX(deflate)(&c_stream, Z_FINISH);
@@ -773,7 +773,7 @@ void test_deflate_pending(unsigned char *compr, size_t comprLen) {
     err = PREFIX(deflateInit)(&c_stream, Z_DEFAULT_COMPRESSION);
     CHECK_ERR(err, "deflateInit");
 
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.next_out = compr;
 
     while (c_stream.total_in != len && c_stream.total_out < comprLen) {
@@ -846,7 +846,7 @@ void test_deflate_prime(unsigned char *compr, size_t comprLen, unsigned char *un
     err = PREFIX(deflatePrime)(&c_stream, 8, 255);
     CHECK_ERR(err, "deflatePrime");
 
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.avail_in = (uint32_t)len;
     c_stream.next_out = compr;
     c_stream.avail_out = (uint32_t)comprLen;
@@ -870,7 +870,7 @@ void test_deflate_prime(unsigned char *compr, size_t comprLen, unsigned char *un
     d_stream.zfree = zfree;
     d_stream.opaque = (void *)0;
 
-    d_stream.next_in  = (const uint8_t *)compr;
+    d_stream.next_in  = compr;
     d_stream.avail_in = (uint32_t)c_stream.total_out;
     d_stream.next_out = uncompr;
     d_stream.avail_out = (uint32_t)uncomprLen;
@@ -973,7 +973,7 @@ void test_deflate_tune(unsigned char *compr, size_t comprLen) {
         printf("deflateTune(): OK\n");
     }
 
-    c_stream.next_in = (const unsigned char *)hello;
+    c_stream.next_in = (z_const unsigned char *)hello;
     c_stream.next_out = compr;
 
     while (c_stream.total_in != len && c_stream.total_out < comprLen) {
index ebba626cf5defde40691f654271d31aae601ab14..3466b202dcbfca806958eb733331ee46edc3c545 100644 (file)
@@ -453,7 +453,7 @@ static void cover_wrap(void) {
 }
 
 /* input and output functions for inflateBack() */
-static unsigned pull(void *desc, const unsigned char **buf) {
+static unsigned pull(void *desc, z_const unsigned char **buf) {
     static unsigned int next = 0;
     static unsigned char dat[] = {0x63, 0, 2, 0};
     struct inflate_state *state;
index 771e7ff91dd31fd31588c888bdef90b638cd931a..392516852d303389ad3932fc252324950996ab73 100644 (file)
@@ -78,7 +78,7 @@ void deflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_
         if (read <= 0)
             break;
 
-        c_stream.next_in  = (const uint8_t *)read_buf;
+        c_stream.next_in  = (z_const uint8_t *)read_buf;
         c_stream.next_out = write_buf;
         c_stream.avail_in = read;
 
@@ -163,7 +163,7 @@ void inflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_
         if (read <= 0)
             break;
 
-        d_stream.next_in  = (const uint8_t *)read_buf;
+        d_stream.next_in  = (z_const uint8_t *)read_buf;
         d_stream.next_out = write_buf;
         d_stream.avail_in = read;
 
index 76844aac757b8a1bf6903a7054b01552c8a4bb3d..1934ba3f5dfb2d901c8646a53e5aca5cd004e9d3 100644 (file)
--- a/uncompr.c
+++ b/uncompr.c
@@ -43,7 +43,7 @@ int ZEXPORT PREFIX(uncompress2)(unsigned char *dest, z_size_t *destLen, const un
         dest = buf;
     }
 
-    stream.next_in = (const unsigned char *)source;
+    stream.next_in = (z_const unsigned char *)source;
     stream.avail_in = 0;
     stream.zalloc = NULL;
     stream.zfree = NULL;
index 8ed84ed3b2fbfebb187b2d37fc3d5287b15f12f3..6f1abdb3f3e236dd7fc630f59ef3701adf5f3006 100644 (file)
@@ -25,6 +25,9 @@
 #  define __has_declspec_attribute(x) 0
 #endif
 
+/* Always define z_const as const */
+#define z_const const
+
 /* Maximum value for memLevel in deflateInit2 */
 #ifndef MAX_MEM_LEVEL
 #  define MAX_MEM_LEVEL 9
index 8b38e89500febcf90eaeed22473b4a245309b873..6ff48c07dc8bcf32e472906441ae986061c681ab 100644 (file)
 #  define __has_declspec_attribute(x) 0
 #endif
 
+#if defined(ZLIB_CONST) && !defined(z_const)
+#  define z_const const
+#else
+#  define z_const
+#endif
+
 /* Maximum value for memLevel in deflateInit2 */
 #ifndef MAX_MEM_LEVEL
 #  define MAX_MEM_LEVEL 9
diff --git a/zlib.h b/zlib.h
index 3465878ded5c5f3b3c14c3e49c1161f41544d9b8..a155b78f46a1dae46c97536f97dbf15c6729357f 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -92,7 +92,7 @@ typedef void  (*free_func)  (void *opaque, void *address);
 struct internal_state;
 
 typedef struct z_stream_s {
-    const unsigned char   *next_in;   /* next input byte */
+    z_const unsigned char *next_in;   /* next input byte */
     uint32_t              avail_in;   /* number of bytes available at next_in */
     unsigned long         total_in;   /* total number of input bytes read so far */
 
@@ -100,7 +100,7 @@ typedef struct z_stream_s {
     uint32_t              avail_out;  /* remaining free space at next_out */
     unsigned long         total_out;  /* total number of bytes output so far */
 
-    const char            *msg;       /* last error message, NULL if no error */
+    z_const char          *msg;       /* last error message, NULL if no error */
     struct internal_state *state;     /* not visible by applications */
 
     alloc_func            zalloc;     /* used to allocate the internal state */
@@ -1063,7 +1063,7 @@ ZEXTERN int ZEXPORT inflateBackInit (z_stream *strm, int windowBits, unsigned ch
    the version of the header file.
 */
 
-typedef uint32_t (*in_func) (void *, const unsigned char * *);
+typedef uint32_t (*in_func) (void *, z_const unsigned char * *);
 typedef int (*out_func) (void *, unsigned char *, uint32_t);
 
 ZEXTERN int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc, out_func out, void *out_desc);
diff --git a/zutil.c b/zutil.c
index 5d03fc5ce14e9d4dc259df4a4dac0c0175bfbedd..fc1b96a552eb8bd8fa25b291bd4cbe4f4e94ae95 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -9,17 +9,17 @@
 #  include "gzguts.h"
 #endif
 
-const char * const PREFIX(z_errmsg)[10] = {
-    (const char *)"need dictionary",     /* Z_NEED_DICT       2  */
-    (const char *)"stream end",          /* Z_STREAM_END      1  */
-    (const char *)"",                    /* Z_OK              0  */
-    (const char *)"file error",          /* Z_ERRNO         (-1) */
-    (const char *)"stream error",        /* Z_STREAM_ERROR  (-2) */
-    (const char *)"data error",          /* Z_DATA_ERROR    (-3) */
-    (const char *)"insufficient memory", /* Z_MEM_ERROR     (-4) */
-    (const char *)"buffer error",        /* Z_BUF_ERROR     (-5) */
-    (const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
-    (const char *)""
+z_const char * const PREFIX(z_errmsg)[10] = {
+    (z_const char *)"need dictionary",     /* Z_NEED_DICT       2  */
+    (z_const char *)"stream end",          /* Z_STREAM_END      1  */
+    (z_const char *)"",                    /* Z_OK              0  */
+    (z_const char *)"file error",          /* Z_ERRNO         (-1) */
+    (z_const char *)"stream error",        /* Z_STREAM_ERROR  (-2) */
+    (z_const char *)"data error",          /* Z_DATA_ERROR    (-3) */
+    (z_const char *)"insufficient memory", /* Z_MEM_ERROR     (-4) */
+    (z_const char *)"buffer error",        /* Z_BUF_ERROR     (-5) */
+    (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
+    (z_const char *)""
 };
 
 const char zlibng_string[] =
diff --git a/zutil.h b/zutil.h
index 1699f4ba0935136dd53b790fdda74ca6eb552150..9ca36ed34f7a8a75024140b830f9dbc4bfe401e7 100644 (file)
--- a/zutil.h
+++ b/zutil.h
@@ -39,7 +39,7 @@ typedef unsigned char uch; /* Included for compatibility with external code only
 typedef uint16_t ush;      /* Included for compatibility with external code only */
 typedef unsigned long ulg;
 
-extern const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
+extern z_const char * const PREFIX(z_errmsg)[10]; /* indexed by 2-zlib_error */
 /* (size given to avoid silly warnings with Visual C++) */
 
 #define ERR_MSG(err) PREFIX(z_errmsg)[Z_NEED_DICT-(err)]