Skip to content

Commit

Permalink
Explicitly indicate functions are conditionally dispatched
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <[email protected]>
  • Loading branch information
phprus authored and Dead2 committed Mar 6, 2024
1 parent af494fc commit fe0a640
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 38 deletions.
8 changes: 4 additions & 4 deletions adler32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion arch/generic/adler32_fold_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions arch/generic/crc32_fold_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 9 additions & 9 deletions deflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion deflate_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}
}
Expand Down
4 changes: 2 additions & 2 deletions deflate_medium.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion deflate_quick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions deflate_slow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
Expand Down
7 changes: 7 additions & 0 deletions functable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions infback.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 10 additions & 10 deletions inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ 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);
}
}

static inline void inf_chksum(PREFIX3(stream) *strm, const uint8_t *src, uint32_t len) {
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);
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions inflate_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit fe0a640

Please sign in to comment.