From: Hans Kristian Rosbach Date: Sat, 16 May 2015 19:15:51 +0000 (+0200) Subject: Replace ush with uint16_t X-Git-Tag: 1.9.9-b1~815^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80d5ed789c3d4c6bbb53c0c5239ba0cb39316d4d;p=thirdparty%2Fzlib-ng.git Replace ush with uint16_t Conflicts: deflate.c deflate.h trees.c zutil.h --- diff --git a/deflate.c b/deflate.c index 9861a7fa8..ef8a0c3b0 100644 --- a/deflate.c +++ b/deflate.c @@ -113,10 +113,10 @@ extern void copy_with_crc(z_stream *strm, unsigned char *dst, long size); * found for specific files. */ typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; + uint16_t good_length; /* reduce lazy search above this match length */ + uint16_t max_lazy; /* do not perform lazy search above this match length */ + uint16_t nice_length; /* quit search above this match length */ + uint16_t max_chain; compress_func func; } config; @@ -249,7 +249,7 @@ int ZEXPORT deflateInit2_(z_stream *strm, int level, int method, int windowBits, int wrap = 1; static const char my_version[] = ZLIB_VERSION; - ush *overlay; + uint16_t *overlay; /* We overlay pending_buf and d_buf+l_buf. This works since the average * output size for (length,distance) codes is <= 24 bits. */ @@ -330,9 +330,9 @@ int ZEXPORT deflateInit2_(z_stream *strm, int level, int method, int windowBits, s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - overlay = (ush *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); + overlay = (uint16_t *) ZALLOC(strm, s->lit_bufsize, sizeof(uint16_t)+2); s->pending_buf = (uch *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); + s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(uint16_t)+2L); if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || s->pending_buf == Z_NULL) { @@ -341,8 +341,8 @@ int ZEXPORT deflateInit2_(z_stream *strm, int level, int method, int windowBits, deflateEnd (strm); return Z_MEM_ERROR; } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; + s->d_buf = overlay + s->lit_bufsize/sizeof(uint16_t); + s->l_buf = s->pending_buf + (1+sizeof(uint16_t))*s->lit_bufsize; s->level = level; s->strategy = strategy; @@ -494,7 +494,7 @@ int ZEXPORT deflatePrime (z_stream *strm, int bits, int value) put = Buf_size - s->bi_valid; if (put > bits) put = bits; - s->bi_buf |= (ush)((value & ((1 << put) - 1)) << s->bi_valid); + s->bi_buf |= (uint16_t)((value & ((1 << put) - 1)) << s->bi_valid); s->bi_valid += put; _tr_flush_bits(s); value >>= put; @@ -1020,7 +1020,7 @@ int ZEXPORT deflateCopy (z_stream *dest, z_stream *source) { deflate_state *ds; deflate_state *ss; - ush *overlay; + uint16_t *overlay; if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { @@ -1040,7 +1040,7 @@ int ZEXPORT deflateCopy (z_stream *dest, z_stream *source) ds->window = (unsigned char *) ZALLOC(dest, ds->w_size, 2*sizeof(unsigned char)); ds->prev = (Pos *) ZALLOC(dest, ds->w_size, sizeof(Pos)); ds->head = (Pos *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ush *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); + overlay = (uint16_t *) ZALLOC(dest, ds->lit_bufsize, sizeof(uint16_t)+2); ds->pending_buf = (uch *) overlay; if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || @@ -1055,8 +1055,8 @@ int ZEXPORT deflateCopy (z_stream *dest, z_stream *source) memcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; + ds->d_buf = overlay + ds->lit_bufsize/sizeof(uint16_t); + ds->l_buf = ds->pending_buf + (1+sizeof(uint16_t))*ds->lit_bufsize; ds->l_desc.dyn_tree = ds->dyn_ltree; ds->d_desc.dyn_tree = ds->dyn_dtree; diff --git a/deflate.h b/deflate.h index ef974c373..ce09d087e 100644 --- a/deflate.h +++ b/deflate.h @@ -71,12 +71,12 @@ /* Data structure describing a single value and its code string. */ typedef struct ct_data_s { union { - ush freq; /* frequency count */ - ush code; /* bit string */ + uint16_t freq; /* frequency count */ + uint16_t code; /* bit string */ } fc; union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ + uint16_t dad; /* father node in Huffman tree */ + uint16_t len; /* length of bit string */ } dl; } ct_data; @@ -93,7 +93,7 @@ typedef struct tree_desc_s { static_tree_desc *stat_desc; /* the corresponding static tree */ } tree_desc; -typedef ush Pos; +typedef uint16_t Pos; typedef unsigned IPos; /* A Pos is an index in the character window. We use short instead of int to @@ -210,7 +210,7 @@ typedef struct internal_state { struct tree_desc_s d_desc; /* desc. for distance tree */ struct tree_desc_s bl_desc; /* desc. for bit length tree */ - ush bl_count[MAX_BITS+1]; + uint16_t bl_count[MAX_BITS+1]; /* number of codes at each bit length for an optimal tree */ int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ @@ -248,7 +248,7 @@ typedef struct internal_state { uInt last_lit; /* running index in l_buf */ - ush *d_buf; + uint16_t *d_buf; /* Buffer for distances. To simplify the code, d_buf and l_buf have * the same number of elements. To use different lengths, an extra flag * array would be necessary. @@ -264,7 +264,7 @@ typedef struct internal_state { ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ #endif - ush bi_buf; + uint16_t bi_buf; /* Output buffer. bits are inserted starting at the bottom (least * significant bits). */ @@ -310,12 +310,12 @@ typedef enum { */ #define put_short(s, w) { \ s->pending += 2; \ - *(ush*)(&s->pending_buf[s->pending - 2]) = (w) ; \ + *(uint16_t*)(&s->pending_buf[s->pending - 2]) = (w) ; \ } #else #define put_short(s, w) { \ put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ + put_byte(s, (uch)((uint16_t)(w) >> 8)); \ } #endif @@ -369,7 +369,7 @@ void ZLIB_INTERNAL bi_windup (deflate_state *s); } # define _tr_tally_dist(s, distance, length, flush) \ { uch len = (length); \ - ush dist = (distance); \ + uint16_t dist = (distance); \ s->d_buf[s->last_lit] = dist; \ s->l_buf[s->last_lit++] = len; \ dist--; \ @@ -434,12 +434,12 @@ local void send_bits(deflate_state *s, * unused bits in value. */ if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; + s->bi_buf |= (uint16_t)value << s->bi_valid; put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); + s->bi_buf = (uint16_t)value >> (Buf_size - s->bi_valid); s->bi_valid += length - Buf_size; } else { - s->bi_buf |= (ush)value << s->bi_valid; + s->bi_buf |= (uint16_t)value << s->bi_valid; s->bi_valid += length; } } @@ -448,12 +448,12 @@ local void send_bits(deflate_state *s, { int len = length;\ if (s->bi_valid > (int)Buf_size - len) {\ int val = value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ + s->bi_buf |= (uint16_t)val << s->bi_valid;\ put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ + s->bi_buf = (uint16_t)val >> (Buf_size - s->bi_valid);\ s->bi_valid += len - Buf_size;\ } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ + s->bi_buf |= (uint16_t)(value) << s->bi_valid;\ s->bi_valid += len;\ }\ } diff --git a/trees.c b/trees.c index a02bab7d1..0349f5c27 100644 --- a/trees.c +++ b/trees.c @@ -136,7 +136,7 @@ local void tr_static_init (void); local void init_block (deflate_state *s); local void pqdownheap (deflate_state *s, ct_data *tree, int k); local void gen_bitlen (deflate_state *s, tree_desc *desc); -local void gen_codes (ct_data *tree, int max_code, ush *bl_count); +local void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count); local void build_tree (deflate_state *s, tree_desc *desc); local void scan_tree (deflate_state *s, ct_data *tree, int max_code); local void send_tree (deflate_state *s, ct_data *tree, int max_code); @@ -164,7 +164,7 @@ local void tr_static_init() int length; /* length value */ int code; /* code value */ int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; + uint16_t bl_count[MAX_BITS+1]; /* number of codes at each bit length for an optimal tree */ if (static_init_done) return; @@ -419,7 +419,7 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc) int n, m; /* iterate over the tree elements */ int bits; /* bit length */ int xbits; /* extra bits */ - ush f; /* frequency */ + uint16_t f; /* frequency */ int overflow = 0; /* number of elements with bit length too large */ for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; @@ -433,7 +433,7 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc) n = s->heap[h]; bits = tree[tree[n].Dad].Len + 1; if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; + tree[n].Len = (uint16_t)bits; /* We overwrite tree[n].Dad which is no longer needed */ if (n > max_code) continue; /* not a leaf node */ @@ -477,7 +477,7 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc) Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); s->opt_len += ((long)bits - (long)tree[m].Len) *(long)tree[m].Freq; - tree[m].Len = (ush)bits; + tree[m].Len = (uint16_t)bits; } n--; } @@ -492,15 +492,15 @@ local void gen_bitlen(deflate_state *s, tree_desc *desc) * OUT assertion: the field code is set for all tree elements of non * zero code length. */ -local void gen_codes (ct_data *tree, int max_code, ush *bl_count) +local void gen_codes (ct_data *tree, int max_code, uint16_t *bl_count) { /* tree: the tree to decorate */ /* max_code: largest code with non zero frequency */ /* bl_count: number of codes at each bit length */ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - ush code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ + uint16_t next_code[MAX_BITS+1]; /* next code value for each bit length */ + uint16_t code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ /* The distribution counts are first used to generate the code values * without bit reversal. @@ -593,7 +593,7 @@ local void build_tree(deflate_state *s, tree_desc *desc) tree[node].Freq = tree[n].Freq + tree[m].Freq; s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; + tree[n].Dad = tree[m].Dad = (uint16_t)node; #ifdef DUMP_BL_TREE if (tree == s->bl_tree) { fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", @@ -634,7 +634,7 @@ local void scan_tree (deflate_state *s, ct_data *tree, int max_code) int min_count = 4; /* min repeat count */ if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code+1].Len = (ush)0xffff; /* guard */ + tree[max_code+1].Len = (uint16_t)0xffff; /* guard */ for (n = 0; n <= max_code; n++) { curlen = nextlen; nextlen = tree[n+1].Len; @@ -921,7 +921,7 @@ int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, unsigned lc) { /* dist: distance of matched string */ /* lc: match length-MIN_MATCH or unmatched char (if dist==0) */ - s->d_buf[s->last_lit] = (ush)dist; + s->d_buf[s->last_lit] = (uint16_t)dist; s->l_buf[s->last_lit++] = (uch)lc; if (dist == 0) { /* lc is the unmatched char */ @@ -930,9 +930,9 @@ int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, unsigned lc) s->matches++; /* Here, lc is the match length - MIN_MATCH */ dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); + Assert((uint16_t)dist < (uint16_t)MAX_DIST(s) && + (uint16_t)lc <= (uint16_t)(MAX_MATCH-MIN_MATCH) && + (uint16_t)d_code(dist) < (uint16_t)D_CODES, "_tr_tally: bad match"); s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; s->dyn_dtree[d_code(dist)].Freq++; @@ -1115,8 +1115,8 @@ local void copy_block(deflate_state *s, char *buf, unsigned len, int header) bi_windup(s); /* align on byte boundary */ if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); + put_short(s, (uint16_t)len); + put_short(s, (uint16_t)~len); #ifdef DEBUG s->bits_sent += 2*16; #endif diff --git a/zutil.h b/zutil.h index de1aa95ea..50565cacc 100644 --- a/zutil.h +++ b/zutil.h @@ -30,8 +30,8 @@ #endif /* compile with -Dlocal if your debugger can't find static symbols */ -typedef unsigned char uch; -typedef unsigned short ush; +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 z_errmsg[10]; /* indexed by 2-zlib_error */