From: Ilya Leoshkevich Date: Wed, 10 Apr 2019 11:41:58 +0000 (+0200) Subject: Introduce inflate_ensure_window, make bi_reverse and flush_pending ZLIB_INTERNAL X-Git-Tag: 1.9.9-b1~487 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7f659f2faa899a73f3456c29554769261c1721f;p=thirdparty%2Fzlib-ng.git Introduce inflate_ensure_window, make bi_reverse and flush_pending ZLIB_INTERNAL --- diff --git a/deflate.c b/deflate.c index 3280a11f..82d99a10 100644 --- 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); diff --git a/deflate.h b/deflate.h index 1360a3d1..76b7f3bc 100644 --- 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 diff --git a/inflate.c b/inflate.c index 6ba76274..002dca88 100644 --- 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) { diff --git a/inflate.h b/inflate.h index 8c142a97..01fb1f9b 100644 --- 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 ef47abdc..53c73bde 100644 --- 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;