Explicitly indicate functions are conditionally dispatched

Signed-off-by: Vladislav Shchapov <vladislav@shchapov.ru>
This commit is contained in:
Vladislav Shchapov 2024-02-28 10:12:53 +05:00 committed by Hans Kristian Rosbach
parent af494fc34f
commit fe0a6407da
13 changed files with 45 additions and 38 deletions

View File

@ -9,22 +9,22 @@
#ifdef ZLIB_COMPAT #ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32_z)(unsigned long adler, const unsigned char *buf, size_t len) { 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 #else
uint32_t Z_EXPORT PREFIX(adler32_z)(uint32_t adler, const unsigned char *buf, size_t len) { 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 #endif
/* ========================================================================= */ /* ========================================================================= */
#ifdef ZLIB_COMPAT #ifdef ZLIB_COMPAT
unsigned long Z_EXPORT PREFIX(adler32)(unsigned long adler, const unsigned char *buf, unsigned int len) { 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 #else
uint32_t Z_EXPORT PREFIX(adler32)(uint32_t adler, const unsigned char *buf, uint32_t len) { 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 #endif

View File

@ -9,7 +9,7 @@
#include <limits.h> #include <limits.h>
Z_INTERNAL uint32_t adler32_fold_copy_c(uint32_t adler, uint8_t *dst, const uint8_t *src, size_t len) { 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); memcpy(dst, src, len);
return adler; return adler;
} }

View File

@ -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) { 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); 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 * 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 */ * init_crc is an unused argument in this context */
Z_UNUSED(init_crc); 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) { Z_INTERNAL uint32_t crc32_fold_final_c(crc32_fold *crc) {

View File

@ -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) { unsigned long Z_EXPORT PREFIX(crc32_z)(unsigned long crc, const unsigned char *buf, size_t len) {
if (buf == NULL) return 0; 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 #else
uint32_t Z_EXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t len) { uint32_t Z_EXPORT PREFIX(crc32_z)(uint32_t crc, const unsigned char *buf, size_t len) {
if (buf == NULL) return 0; if (buf == NULL) return 0;
return functable.crc32(crc, buf, len); return FUNCTABLE_CALL(crc32)(crc, buf, len);
} }
#endif #endif

View File

@ -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 */ /* when using zlib wrappers, compute Adler-32 for provided dictionary */
if (wrap == 1) 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 */ DEFLATE_SET_DICTIONARY_HOOK(strm, dictionary, dictLength); /* hook for IBM Z DFLTCC */
s->wrap = 0; /* avoid computing Adler-32 in read_buf */ 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 #ifdef GZIP
if (s->wrap == 2) { if (s->wrap == 2) {
strm->adler = functable.crc32_fold_reset(&s->crc_fold); strm->adler = FUNCTABLE_CALL(crc32_fold_reset)(&s->crc_fold);
} else } else
#endif #endif
strm->adler = ADLER32_INITIAL_VALUE; 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 != level) {
if (s->level == 0 && s->matches != 0) { if (s->level == 0 && s->matches != 0) {
if (s->matches == 1) { if (s->matches == 1) {
functable.slide_hash(s); FUNCTABLE_CALL(slide_hash)(s);
} else { } else {
CLEAR_HASH(s); CLEAR_HASH(s);
} }
@ -804,7 +804,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) {
#ifdef GZIP #ifdef GZIP
if (s->status == GZIP_STATE) { if (s->status == GZIP_STATE) {
/* gzip header */ /* gzip header */
functable.crc32_fold_reset(&s->crc_fold); FUNCTABLE_CALL(crc32_fold_reset)(&s->crc_fold);
put_byte(s, 31); put_byte(s, 31);
put_byte(s, 139); put_byte(s, 139);
put_byte(s, 8); 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); 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; s->status = BUSY_STATE;
@ -992,7 +992,7 @@ int32_t Z_EXPORT PREFIX(deflate)(PREFIX3(stream) *strm, int32_t flush) {
/* Write the trailer */ /* Write the trailer */
#ifdef GZIP #ifdef GZIP
if (s->wrap == 2) { 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, strm->adler);
put_uint32(s, (uint32_t)strm->total_in); 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); memcpy(buf, strm->next_in, len);
#ifdef GZIP #ifdef GZIP
} else if (strm->state->wrap == 2) { } 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 #endif
} else if (strm->state->wrap == 1) { } 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 { } else {
memcpy(buf, strm->next_in, len); memcpy(buf, strm->next_in, len);
} }
@ -1206,7 +1206,7 @@ void Z_INTERNAL PREFIX(fill_window)(deflate_state *s) {
s->block_start -= (int)wsize; s->block_start -= (int)wsize;
if (s->insert > s->strstart) if (s->insert > s->strstart)
s->insert = s->strstart; s->insert = s->strstart;
functable.slide_hash(s); FUNCTABLE_CALL(slide_hash)(s);
more += wsize; more += wsize;
} }
if (s->strm->avail_in == 0) if (s->strm->avail_in == 0)

View File

@ -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 window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file). * 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 */ /* longest_match() sets match_start */
} }
} }

View File

@ -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 window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file). * 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; current_match.match_start = (uint16_t)s->match_start;
if (UNLIKELY(current_match.match_length < WANT_MIN_MATCH)) if (UNLIKELY(current_match.match_length < WANT_MIN_MATCH))
current_match.match_length = 1; 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 window index 0 (in particular we have to avoid a match
* of the string with itself at the start of the input file). * 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; next_match.match_start = (uint16_t)s->match_start;
if (UNLIKELY(next_match.match_start >= next_match.strstart)) { if (UNLIKELY(next_match.match_start >= next_match.strstart)) {
/* this can happen due to some restarts */ /* this can happen due to some restarts */

View File

@ -94,7 +94,7 @@ Z_INTERNAL block_state deflate_quick(deflate_state *s, int flush) {
const uint8_t *match_start = s->window + hash_head; const uint8_t *match_start = s->window + hash_head;
if (zng_memcmp_2(str_start, match_start) == 0) { 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 (match_len >= WANT_MIN_MATCH) {
if (UNLIKELY(match_len > s->lookahead)) if (UNLIKELY(match_len > s->lookahead))

View File

@ -22,9 +22,9 @@ Z_INTERNAL block_state deflate_slow(deflate_state *s, int flush) {
match_func longest_match; match_func longest_match;
if (s->max_chain_length <= 1024) if (s->max_chain_length <= 1024)
longest_match = functable.longest_match; longest_match = FUNCTABLE_FPTR(longest_match);
else else
longest_match = functable.longest_match_slow; longest_match = FUNCTABLE_FPTR(longest_match_slow);
/* Process the input block. */ /* Process the input block. */
for (;;) { for (;;) {

View File

@ -29,4 +29,11 @@ struct functable_s {
Z_INTERNAL extern struct functable_s functable; 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 #endif

View File

@ -55,7 +55,7 @@ int32_t ZNG_CONDEXPORT PREFIX(inflateBackInit)(PREFIX3(stream) *strm, int32_t wi
state->wnext = 0; state->wnext = 0;
state->whave = 0; state->whave = 0;
state->sane = 1; state->sane = 1;
state->chunksize = functable.chunksize(); state->chunksize = FUNCTABLE_CALL(chunksize)();
return Z_OK; return Z_OK;
} }
@ -357,7 +357,7 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in
RESTORE(); RESTORE();
if (state->whave < state->wsize) if (state->whave < state->wsize)
state->whave = state->wsize - left; state->whave = state->wsize - left;
functable.inflate_fast(strm, state->wsize); FUNCTABLE_CALL(inflate_fast)(strm, state->wsize);
LOAD(); LOAD();
break; break;
} }

View File

@ -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; struct inflate_state *state = (struct inflate_state*)strm->state;
#ifdef GUNZIP #ifdef GUNZIP
if (state->flags) { 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 } else
#endif #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; struct inflate_state *state = (struct inflate_state*)strm->state;
#ifdef GUNZIP #ifdef GUNZIP
if (state->flags) { if (state->flags) {
functable.crc32_fold(&state->crc_fold, src, len, 0); FUNCTABLE_CALL(crc32_fold)(&state->crc_fold, src, len, 0);
} else } else
#endif #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->strm = strm;
state->window = NULL; state->window = NULL;
state->mode = HEAD; /* to pass state test in inflateReset2() */ state->mode = HEAD; /* to pass state test in inflateReset2() */
state->chunksize = functable.chunksize(); state->chunksize = FUNCTABLE_CALL(chunksize)();
ret = PREFIX(inflateReset2)(strm, windowBits); ret = PREFIX(inflateReset2)(strm, windowBits);
if (ret != Z_OK) { if (ret != Z_OK) {
ZFREE_STATE(strm, state); 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 */ /* compute crc32 checksum if not in raw mode */
if ((state->wrap & 4) && state->flags) 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; state->mode = TYPE;
break; break;
#endif #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 */ /* use inflate_fast() if we have enough input and output */
if (have >= INFLATE_FAST_MIN_HAVE && left >= INFLATE_FAST_MIN_LEFT) { if (have >= INFLATE_FAST_MIN_HAVE && left >= INFLATE_FAST_MIN_LEFT) {
RESTORE(); RESTORE();
functable.inflate_fast(strm, out); FUNCTABLE_CALL(inflate_fast)(strm, out);
LOAD(); LOAD();
if (state->mode == TYPE) if (state->mode == TYPE)
state->back = -1; state->back = -1;
@ -1024,7 +1024,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
} else { } else {
copy = MIN(state->length, left); 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; left -= copy;
state->length -= copy; state->length -= copy;
@ -1054,7 +1054,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
} }
#ifdef GUNZIP #ifdef GUNZIP
if (state->flags) 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 #endif
} }
out = left; out = left;
@ -1188,7 +1188,7 @@ int32_t Z_EXPORT PREFIX(inflateSetDictionary)(PREFIX3(stream) *strm, const uint8
/* check for correct dictionary identifier */ /* check for correct dictionary identifier */
if (state->mode == DICT) { 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) if (dictid != state->check)
return Z_DATA_ERROR; return Z_DATA_ERROR;
} }

View File

@ -46,9 +46,9 @@
/* check function to use adler32() for zlib or crc32() for gzip */ /* check function to use adler32() for zlib or crc32() for gzip */
#ifdef GUNZIP #ifdef GUNZIP
# define UPDATE(check, buf, len) \ # 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 #else
# define UPDATE(check, buf, len) functable.adler32(check, buf, len) # define UPDATE(check, buf, len) FUNCTABLE_CALL(adler32)(check, buf, len)
#endif #endif
/* check macros for header crc */ /* check macros for header crc */