]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Introduce inflate_ensure_window, make bi_reverse and flush_pending ZLIB_INTERNAL
authorIlya Leoshkevich <iii@linux.ibm.com>
Wed, 10 Apr 2019 11:41:58 +0000 (13:41 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 23 May 2019 10:44:59 +0000 (12:44 +0200)
deflate.c
deflate.h
inflate.c
inflate.h
trees.c

index 3280a11f600bffe5013653f0792c0f61342aaf44..82d99a1037e8819897dcdcb70d2985606ae7a2a3 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -83,7 +83,6 @@ static block_state deflate_rle   (deflate_state *s, int flush);
 static block_state deflate_huff  (deflate_state *s, int flush);
 static void lm_init              (deflate_state *s);
 static void putShortMSB          (deflate_state *s, uint16_t b);
-ZLIB_INTERNAL void flush_pending (PREFIX3(stream) *strm);
 ZLIB_INTERNAL unsigned read_buf  (PREFIX3(stream) *strm, unsigned char *buf, unsigned size);
 
 extern void crc_reset(deflate_state *const s);
index 1360a3d17698f76341281757609908018ba1e235..76b7f3bcf4217daff6ec0d8ac7311d27dd21e9d5 100644 (file)
--- a/deflate.h
+++ b/deflate.h
@@ -336,6 +336,8 @@ void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s);
 void ZLIB_INTERNAL _tr_align(deflate_state *s);
 void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, char *buf, unsigned long stored_len, int last);
 void ZLIB_INTERNAL bi_windup(deflate_state *s);
+unsigned ZLIB_INTERNAL bi_reverse(unsigned code, int len);
+void ZLIB_INTERNAL flush_pending(PREFIX3(streamp) strm);
 
 #define d_code(dist) ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
 /* Mapping from a distance to a distance code. dist is the distance - 1 and
index 6ba76274bdb5f3f5657069855161af527bf4aa78..002dca88134b5a19a151072fd6704e8e4e46d221 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -359,6 +359,33 @@ void makefixed(void) {
 }
 #endif /* MAKEFIXED */
 
+int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state)
+{
+    /* if it hasn't been done already, allocate space for the window */
+    if (state->window == NULL) {
+#ifdef INFFAST_CHUNKSIZE
+        unsigned wsize = 1U << state->wbits;
+        state->window = (unsigned char *) ZALLOC(state->strm, wsize + INFFAST_CHUNKSIZE, sizeof(unsigned char));
+        if (state->window == Z_NULL)
+            return 1;
+        memset(state->window + wsize, 0, INFFAST_CHUNKSIZE);
+#else
+        state->window = (unsigned char *) ZALLOC(state->strm, 1U << state->wbits, sizeof(unsigned char));
+        if (state->window == NULL)
+            return 1;
+#endif
+    }
+
+    /* if window not in use yet, initialize */
+    if (state->wsize == 0) {
+        state->wsize = 1U << state->wbits;
+        state->wnext = 0;
+        state->whave = 0;
+    }
+
+    return 0;
+}
+
 /*
    Update the window with the last wsize (normally 32K) bytes written before
    returning.  If window does not exist yet, create it.  This is only called
@@ -379,27 +406,7 @@ static int updatewindow(PREFIX3(stream) *strm, const unsigned char *end, uint32_
 
     state = (struct inflate_state *)strm->state;
 
-    /* if it hasn't been done already, allocate space for the window */
-    if (state->window == NULL) {
-#ifdef INFFAST_CHUNKSIZE
-        unsigned wsize = 1U << state->wbits;
-        state->window = (unsigned char *) ZALLOC(strm, wsize + INFFAST_CHUNKSIZE, sizeof(unsigned char));
-        if (state->window == Z_NULL)
-            return 1;
-        memset(state->window + wsize, 0, INFFAST_CHUNKSIZE);
-#else
-        state->window = (unsigned char *) ZALLOC(strm, 1U << state->wbits, sizeof(unsigned char));
-        if (state->window == NULL)
-            return 1;
-#endif
-    }
-
-    /* if window not in use yet, initialize */
-    if (state->wsize == 0) {
-        state->wsize = 1U << state->wbits;
-        state->wnext = 0;
-        state->whave = 0;
-    }
+    if (inflate_ensure_window(state)) return 1;
 
     /* copy state->wsize or less output bytes into the circular window */
     if (copy >= state->wsize) {
index 8c142a97716672838e5306fc7241d58a406b38bc..01fb1f9b02a2e407fd7089bc6b4ffd697e82a98e 100644 (file)
--- a/inflate.h
+++ b/inflate.h
@@ -127,4 +127,6 @@ struct inflate_state {
     unsigned was;               /* initial length of match */
 };
 
+int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state);
+
 #endif /* INFLATE_H_ */
diff --git a/trees.c b/trees.c
index ef47abdc6dc2e1268368e5095ff787482e73279a..53c73bde179e0570c174a0c8bb9c19073514c76e 100644 (file)
--- a/trees.c
+++ b/trees.c
@@ -145,7 +145,6 @@ static int  build_bl_tree    (deflate_state *s);
 static void send_all_trees   (deflate_state *s, int lcodes, int dcodes, int blcodes);
 static void compress_block   (deflate_state *s, const ct_data *ltree, const ct_data *dtree);
 static int  detect_data_type (deflate_state *s);
-static unsigned bi_reverse   (unsigned code, int len);
 static void bi_flush         (deflate_state *s);
 
 #ifdef GEN_TREES_H
@@ -1044,7 +1043,7 @@ static int detect_data_type(deflate_state *s) {
  * method would use a table)
  * IN assertion: 1 <= len <= 15
  */
-static unsigned bi_reverse(unsigned code, int len) {
+ZLIB_INTERNAL unsigned bi_reverse(unsigned code, int len) {
     /* code: the value to invert */
     /* len: its bit length */
     register unsigned res = 0;