mirror of
https://github.com/GerbilSoft/zlib-ng.git
synced 2025-06-18 11:35:35 -04:00
Explicitly indicate functions are conditionally dispatched
Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
parent
af494fc34f
commit
fe0a6407da
@ -9,22 +9,22 @@
|
||||
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned long Z_EXPORT PREFIX(adler32_z)(unsigned long adler, const unsigned char *buf, size_t len) {
|
||||
return (unsigned long)functable.adler32((uint32_t)adler, buf, len);
|
||||
return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
|
||||
}
|
||||
#else
|
||||
uint32_t Z_EXPORT PREFIX(adler32_z)(uint32_t adler, const unsigned char *buf, size_t len) {
|
||||
return functable.adler32(adler, buf, len);
|
||||
return FUNCTABLE_CALL(adler32)(adler, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ========================================================================= */
|
||||
#ifdef ZLIB_COMPAT
|
||||
unsigned long Z_EXPORT PREFIX(adler32)(unsigned long adler, const unsigned char *buf, unsigned int len) {
|
||||
return (unsigned long)functable.adler32((uint32_t)adler, buf, len);
|
||||
return (unsigned long)FUNCTABLE_CALL(adler32)((uint32_t)adler, buf, len);
|
||||
}
|
||||
#else
|
||||
uint32_t Z_EXPORT PREFIX(adler32)(uint32_t adler, const unsigned char *buf, uint32_t len) {
|
||||
return functable.adler32(adler, buf, len);
|
||||
return FUNCTABLE_CALL(adler32)(adler, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <limits.h>
|
||||
|
||||
Z_INTERNAL uint32_t adler32_fold_copy_c(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len) {
|
||||
adler = functable.adler32(adler, src, len);
|
||||
adler = FUNCTABLE_CALL(adler32)(adler, src, len);
|
||||
memcpy(dst, src, len);
|
||||
return adler;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ Z_INTERNAL uint32_t crc32_fold_reset_c(crc32_fold *crc) {
|
||||
}
|
||||
|
||||
Z_INTERNAL void crc32_fold_copy_c(crc32_fold *crc, uint8_t *dst, const uint8_t *src, size_t len) {
|
||||
crc->value = functable.crc32(crc->value, src, len);
|
||||
crc->value = FUNCTABLE_CALL(crc32)(crc->value, src, len);
|
||||
memcpy(dst, src, len);
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ Z_INTERNAL void crc32_fold_c(crc32_fold *crc, const uint8_t *src, size_t len, ui
|
||||
* same arguments for the versions that _do_ do a folding CRC but we don't want a copy. The
|
||||
* init_crc is an unused argument in this context */
|
||||
Z_UNUSED(init_crc);
|
||||
crc->value = functable.crc32(crc->value, src, len);
|
||||
crc->value = FUNCTABLE_CALL(crc32)(crc->value, src, len);
|
||||
}
|
||||
|
||||
Z_INTERNAL uint32_t crc32_fold_final_c(crc32_fold *crc) {
|
||||
|
4
crc32.c
4
crc32.c
@ -21,13 +21,13 @@ const uint32_t * Z_EXPORT PREFIX(get_crc_table)(void) {
|
||||
unsigned long Z_EXPORT PREFIX(crc32_z)(unsigned long crc, const unsigned char *buf, size_t len) {
|
||||
if (buf == NULL) return 0;
|
||||
|
||||
return (unsigned long)functable.crc32((uint32_t)crc, buf, len);
|
||||
return (unsigned long)FUNCTABLE_CALL(crc32)((uint32_t)crc, buf, len);
|
||||
}
|
||||
#else
|
||||
uint32_t Z_EXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t len) {
|
||||
if (buf == NULL) return 0;
|
||||
|
||||
return functable.crc32(crc, buf, len);
|
||||
return FUNCTABLE_CALL(crc32)(crc, buf, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
18
deflate.c
18
deflate.c
@ -372,7 +372,7 @@ int32_t Z_EXPORT PREFIX(deflateSetDictionary)(PREFIX3(stream) *strm, const uint8
|
||||
|
||||
/* when using zlib wrappers, compute Adler-32 for provided dictionary */
|
||||
if (wrap == 1)
|
||||
strm->adler = functable.adler32(strm->adler, dictionary, dictLength);
|
||||
strm->adler = FUNCTABLE_CALL(adler32)(strm->adler, dictionary, dictLength);
|
||||
DEFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength); /* hook for IBM Z DFLTCC */
|
||||
s->wrap = 0; /* avoid computing Adler-32 in read_buf */
|
||||
|
||||
@ -459,7 +459,7 @@ int32_t Z_EXPORT PREFIX(deflateResetKeep)(PREFIX3(stream) *strm) {
|
||||
|
||||
#ifdef GZIP
|
||||
if (s->wrap == 2) {
|
||||
strm->adler = functable.crc32_fold_reset(&s->crc_fold);
|
||||
strm->adler = FUNCTABLE_CALL(crc32_fold_reset)(&s->crc_fold);
|
||||
} else
|
||||
#endif
|
||||
strm->adler = ADLER32_INITIAL_VALUE;
|
||||
@ -565,7 +565,7 @@ int32_t Z_EXPORT PREFIX(deflateParams)(PREFIX3(stream) *strm, int32_t level, int
|
||||
if (s->level != level) {
|
||||
if (s->level == 0 && s->matches != 0) {
|
||||
if (s->matches == 1) {
|
||||
functable.slide_hash(s);
|
||||
FUNCTABLE_CALL(slide_hash)(s);
|
||||
} else {
|
||||
CLEAR_HASH(s);
|
||||
}
|
||||
@ -804,7 +804,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
#ifdef GZIP
|
||||
if (s->status == GZIP_STATE) {
|
||||
/* gzip header */
|
||||
functable.crc32_fold_reset(&s->crc_fold);
|
||||
FUNCTABLE_CALL(crc32_fold_reset)(&s->crc_fold);
|
||||
put_byte(s, 31);
|
||||
put_byte(s, 139);
|
||||
put_byte(s, 8);
|
||||
@ -921,7 +921,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
}
|
||||
}
|
||||
put_short(s, (uint16_t)strm->adler);
|
||||
functable.crc32_fold_reset(&s->crc_fold);
|
||||
FUNCTABLE_CALL(crc32_fold_reset)(&s->crc_fold);
|
||||
}
|
||||
s->status = BUSY_STATE;
|
||||
|
||||
@ -992,7 +992,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
/* Write the trailer */
|
||||
#ifdef GZIP
|
||||
if (s->wrap == 2) {
|
||||
strm->adler = functable.crc32_fold_final(&s->crc_fold);
|
||||
strm->adler = FUNCTABLE_CALL(crc32_fold_final)(&s->crc_fold);
|
||||
|
||||
put_uint32(s, strm->adler);
|
||||
put_uint32(s, (uint32_t)strm->total_in);
|
||||
@ -1110,10 +1110,10 @@ Z_INTERNAL unsigned PREFIX(read_buf)(PREFIX3(stream) *strm, unsigned char *buf,
|
||||
memcpy(buf, strm->next_in, len);
|
||||
#ifdef GZIP
|
||||
} else if (strm->state->wrap == 2) {
|
||||
functable.crc32_fold_copy(&strm->state->crc_fold, buf, strm->next_in, len);
|
||||
FUNCTABLE_CALL(crc32_fold_copy)(&strm->state->crc_fold, buf, strm->next_in, len);
|
||||
#endif
|
||||
} else if (strm->state->wrap == 1) {
|
||||
strm->adler = functable.adler32_fold_copy(strm->adler, buf, strm->next_in, len);
|
||||
strm->adler = FUNCTABLE_CALL(adler32_fold_copy)(strm->adler, buf, strm->next_in, len);
|
||||
} else {
|
||||
memcpy(buf, strm->next_in, len);
|
||||
}
|
||||
@ -1206,7 +1206,7 @@ void Z_INTERNAL PREFIX(fill_window)(deflate_state *s) {
|
||||
s->block_start -= (int)wsize;
|
||||
if (s->insert > s->strstart)
|
||||
s->insert = s->strstart;
|
||||
functable.slide_hash(s);
|
||||
FUNCTABLE_CALL(slide_hash)(s);
|
||||
more += wsize;
|
||||
}
|
||||
if (s->strm->avail_in == 0)
|
||||
|
@ -52,7 +52,7 @@ Z_INTERNAL block_state deflate_fast(deflate_state *s, int flush) {
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
match_len = functable.longest_match(s, hash_head);
|
||||
match_len = FUNCTABLE_CALL(longest_match)(s, hash_head);
|
||||
/* longest_match() sets match_start */
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
current_match.match_length = (uint16_t)functable.longest_match(s, hash_head);
|
||||
current_match.match_length = (uint16_t)FUNCTABLE_CALL(longest_match)(s, hash_head);
|
||||
current_match.match_start = (uint16_t)s->match_start;
|
||||
if (UNLIKELY(current_match.match_length < WANT_MIN_MATCH))
|
||||
current_match.match_length = 1;
|
||||
@ -250,7 +250,7 @@ Z_INTERNAL block_state deflate_medium(deflate_state *s, int flush) {
|
||||
* of window index 0 (in particular we have to avoid a match
|
||||
* of the string with itself at the start of the input file).
|
||||
*/
|
||||
next_match.match_length = (uint16_t)functable.longest_match(s, hash_head);
|
||||
next_match.match_length = (uint16_t)FUNCTABLE_CALL(longest_match)(s, hash_head);
|
||||
next_match.match_start = (uint16_t)s->match_start;
|
||||
if (UNLIKELY(next_match.match_start >= next_match.strstart)) {
|
||||
/* this can happen due to some restarts */
|
||||
|
@ -94,7 +94,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
|
||||
const uint8_t *match_start = s->window + hash_head;
|
||||
|
||||
if (zng_memcmp_2(str_start, match_start) == 0) {
|
||||
match_len = functable.compare256(str_start+2, match_start+2) + 2;
|
||||
match_len = FUNCTABLE_CALL(compare256)(str_start+2, match_start+2) + 2;
|
||||
|
||||
if (match_len >= WANT_MIN_MATCH) {
|
||||
if (UNLIKELY(match_len > s->lookahead))
|
||||
|
@ -22,9 +22,9 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
|
||||
match_func longest_match;
|
||||
|
||||
if (s->max_chain_length <= 1024)
|
||||
longest_match = functable.longest_match;
|
||||
longest_match = FUNCTABLE_FPTR(longest_match);
|
||||
else
|
||||
longest_match = functable.longest_match_slow;
|
||||
longest_match = FUNCTABLE_FPTR(longest_match_slow);
|
||||
|
||||
/* Process the input block. */
|
||||
for (;;) {
|
||||
|
@ -29,4 +29,11 @@ struct functable_s {
|
||||
|
||||
Z_INTERNAL extern struct functable_s functable;
|
||||
|
||||
|
||||
/* Explicitly indicate functions are conditionally dispatched.
|
||||
*/
|
||||
#define FUNCTABLE_CALL(name) functable.name
|
||||
#define FUNCTABLE_FPTR(name) functable.name
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -55,7 +55,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t wi
|
||||
state->wnext = 0;
|
||||
state->whave = 0;
|
||||
state->sane = 1;
|
||||
state->chunksize = functable.chunksize();
|
||||
state->chunksize = FUNCTABLE_CALL(chunksize)();
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
@ -357,7 +357,7 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in
|
||||
RESTORE();
|
||||
if (state->whave < state->wsize)
|
||||
state->whave = state->wsize - left;
|
||||
functable.inflate_fast(strm, state->wsize);
|
||||
FUNCTABLE_CALL(inflate_fast)(strm, state->wsize);
|
||||
LOAD();
|
||||
break;
|
||||
}
|
||||
|
20
inflate.c
20
inflate.c
@ -28,11 +28,11 @@ static inline void inf_chksum_cpy(PREFIX3(stream) *strm, uint8_t *dst,
|
||||
struct inflate_state *state = (struct inflate_state*)strm->state;
|
||||
#ifdef GUNZIP
|
||||
if (state->flags) {
|
||||
functable.crc32_fold_copy(&state->crc_fold, dst, src, copy);
|
||||
FUNCTABLE_CALL(crc32_fold_copy)(&state->crc_fold, dst, src, copy);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
strm->adler = state->check = functable.adler32_fold_copy(state->check, dst, src, copy);
|
||||
strm->adler = state->check = FUNCTABLE_CALL(adler32_fold_copy)(state->check, dst, src, copy);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,11 +40,11 @@ static inline void inf_chksum(PREFIX3(stream) *strm, const uint8_t *src, uint32_
|
||||
struct inflate_state *state = (struct inflate_state*)strm->state;
|
||||
#ifdef GUNZIP
|
||||
if (state->flags) {
|
||||
functable.crc32_fold(&state->crc_fold, src, len, 0);
|
||||
FUNCTABLE_CALL(crc32_fold)(&state->crc_fold, src, len, 0);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
strm->adler = state->check = functable.adler32(state->check, src, len);
|
||||
strm->adler = state->check = FUNCTABLE_CALL(adler32)(state->check, src, len);
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +159,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateInit2)(PREFIX3(stream) *strm, int32_t windo
|
||||
state->strm = strm;
|
||||
state->window = NULL;
|
||||
state->mode = HEAD; /* to pass state test in inflateReset2() */
|
||||
state->chunksize = functable.chunksize();
|
||||
state->chunksize = FUNCTABLE_CALL(chunksize)();
|
||||
ret = PREFIX(inflateReset2)(strm, windowBits);
|
||||
if (ret != Z_OK) {
|
||||
ZFREE_STATE(strm, state);
|
||||
@ -634,7 +634,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
}
|
||||
/* compute crc32 checksum if not in raw mode */
|
||||
if ((state->wrap & 4) && state->flags)
|
||||
strm->adler = state->check = functable.crc32_fold_reset(&state->crc_fold);
|
||||
strm->adler = state->check = FUNCTABLE_CALL(crc32_fold_reset)(&state->crc_fold);
|
||||
state->mode = TYPE;
|
||||
break;
|
||||
#endif
|
||||
@ -865,7 +865,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
/* use inflate_fast() if we have enough input and output */
|
||||
if (have >= INFLATE_FAST_MIN_HAVE && left >= INFLATE_FAST_MIN_LEFT) {
|
||||
RESTORE();
|
||||
functable.inflate_fast(strm, out);
|
||||
FUNCTABLE_CALL(inflate_fast)(strm, out);
|
||||
LOAD();
|
||||
if (state->mode == TYPE)
|
||||
state->back = -1;
|
||||
@ -1024,7 +1024,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
} else {
|
||||
copy = MIN(state->length, left);
|
||||
|
||||
put = functable.chunkmemset_safe(put, state->offset, copy, left);
|
||||
put = FUNCTABLE_CALL(chunkmemset_safe)(put, state->offset, copy, left);
|
||||
}
|
||||
left -= copy;
|
||||
state->length -= copy;
|
||||
@ -1054,7 +1054,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
|
||||
}
|
||||
#ifdef GUNZIP
|
||||
if (state->flags)
|
||||
strm->adler = state->check = functable.crc32_fold_final(&state->crc_fold);
|
||||
strm->adler = state->check = FUNCTABLE_CALL(crc32_fold_final)(&state->crc_fold);
|
||||
#endif
|
||||
}
|
||||
out = left;
|
||||
@ -1188,7 +1188,7 @@ int32_t Z_EXPORT PREFIX(inflateSetDictionary)(PREFIX3(stream) *strm, const uint8
|
||||
|
||||
/* check for correct dictionary identifier */
|
||||
if (state->mode == DICT) {
|
||||
dictid = functable.adler32(ADLER32_INITIAL_VALUE, dictionary, dictLength);
|
||||
dictid = FUNCTABLE_CALL(adler32)(ADLER32_INITIAL_VALUE, dictionary, dictLength);
|
||||
if (dictid != state->check)
|
||||
return Z_DATA_ERROR;
|
||||
}
|
||||
|
@ -46,9 +46,9 @@
|
||||
/* check function to use adler32() for zlib or crc32() for gzip */
|
||||
#ifdef GUNZIP
|
||||
# define UPDATE(check, buf, len) \
|
||||
(state->flags ? PREFIX(crc32)(check, buf, len) : functable.adler32(check, buf, len))
|
||||
(state->flags ? PREFIX(crc32)(check, buf, len) : FUNCTABLE_CALL(adler32)(check, buf, len))
|
||||
#else
|
||||
# define UPDATE(check, buf, len) functable.adler32(check, buf, len)
|
||||
# define UPDATE(check, buf, len) FUNCTABLE_CALL(adler32)(check, buf, len)
|
||||
#endif
|
||||
|
||||
/* check macros for header crc */
|
||||
|
Loading…
Reference in New Issue
Block a user