summaryrefslogtreecommitdiff
path: root/inflate.c
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-github@circlestorm.org>2019-08-08 10:38:06 +0200
committerGitHub <noreply@github.com>2019-08-08 10:38:06 +0200
commit74a3e05bfa71e17f5b28d5f64d35e1cbe1b71a6a (patch)
treef544b536b2bb85755a8e71c3f64bc4d0b4320c68 /inflate.c
parent340f2f6ef64ba91c5e9576a2a097657e28186ec7 (diff)
Remove BUILDFIXED and MAKEFIXED. (#375)
Remove BUILDFIXED support. Split out MAKEFIXED into a separate 'makefixed' util that is easy to use if we want to regenerate/verify inffixed.h.
Diffstat (limited to 'inflate.c')
-rw-r--r--inflate.c115
1 files changed, 2 insertions, 113 deletions
diff --git a/inflate.c b/inflate.c
index 7d16656..ed544ba 100644
--- a/inflate.c
+++ b/inflate.c
@@ -9,6 +9,7 @@
#include "inflate.h"
#include "inffast.h"
#include "inflate_p.h"
+#include "inffixed.h"
#include "memcopy.h"
#include "functable.h"
@@ -37,21 +38,10 @@
# define INFLATE_MARK_HOOK(strm) do {} while (0)
#endif
-#ifdef MAKEFIXED
-# ifndef BUILDFIXED
-# define BUILDFIXED
-# endif
-#endif
-
/* function prototypes */
static int inflateStateCheck(PREFIX3(stream) *strm);
static int updatewindow(PREFIX3(stream) *strm, const unsigned char *end, uint32_t copy);
static uint32_t syncsearch(uint32_t *have, const unsigned char *buf, uint32_t len);
-#ifdef BUILDFIXED
- void makefixed(void);
-#else
-# include "inffixed.h"
-#endif
static int inflateStateCheck(PREFIX3(stream) *strm) {
struct inflate_state *state;
@@ -199,117 +189,16 @@ int ZEXPORT PREFIX(inflatePrime)(PREFIX3(stream) *strm, int bits, int value) {
/*
Return state with length and distance decoding tables and index sizes set to
- fixed code decoding. Normally this returns fixed tables from inffixed.h.
- If BUILDFIXED is defined, then instead this routine builds the tables the
- first time it's called, and returns those tables the first time and
- thereafter. This reduces the size of the code by about 2K bytes, in
- exchange for a little execution time. However, BUILDFIXED should not be
- used for threaded applications, since the rewriting of the tables and virgin
- may not be thread-safe.
+ fixed code decoding. This returns fixed tables from inffixed.h.
*/
void ZLIB_INTERNAL fixedtables(struct inflate_state *state) {
-#ifdef BUILDFIXED
- static int virgin = 1;
- static code *lenfix, *distfix;
- static code fixed[544];
-
- /* build fixed huffman tables if first call (may not be thread safe) */
- if (virgin) {
- unsigned sym, bits;
- static code *next;
-
- /* literal/length table */
- sym = 0;
- while (sym < 144) state->lens[sym++] = 8;
- while (sym < 256) state->lens[sym++] = 9;
- while (sym < 280) state->lens[sym++] = 7;
- while (sym < 288) state->lens[sym++] = 8;
- next = fixed;
- lenfix = next;
- bits = 9;
- zng_inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
-
- /* distance table */
- sym = 0;
- while (sym < 32) state->lens[sym++] = 5;
- distfix = next;
- bits = 5;
- zng_inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
-
- /* do this just once */
- virgin = 0;
- }
-#endif /* BUILDFIXED */
state->lencode = lenfix;
state->lenbits = 9;
state->distcode = distfix;
state->distbits = 5;
}
-#ifdef MAKEFIXED
-#include <stdio.h>
-
-/*
- Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
- defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
- those tables to stdout, which would be piped to inffixed.h. A small program
- can simply call makefixed to do this:
-
- void makefixed(void);
-
- int main(void)
- {
- makefixed();
- return 0;
- }
-
- Then that can be linked with zlib built with MAKEFIXED defined and run:
-
- a.out > inffixed.h
- */
-void makefixed(void) {
- unsigned low, size;
- struct inflate_state state;
-
- fixedtables(&state);
- puts(" /* inffixed.h -- table for decoding fixed codes");
- puts(" * Generated automatically by makefixed().");
- puts(" */");
- puts("");
- puts(" /* WARNING: this file should *not* be used by applications.");
- puts(" It is part of the implementation of this library and is");
- puts(" subject to change. Applications should only use zlib.h.");
- puts(" */");
- puts("");
- size = 1U << 9;
- printf(" static const code lenfix[%u] = {", size);
- low = 0;
- for (;;) {
- if ((low % 7) == 0)
- printf("\n ");
- printf("{%u,%u,%d}", (low & 127) == 99 ? 64 : state.lencode[low].op,
- state.lencode[low].bits, state.lencode[low].val);
- if (++low == size)
- break;
- putchar(',');
- }
- puts("\n };");
- size = 1U << 5;
- printf("\n static const code distfix[%u] = {", size);
- low = 0;
- for (;;) {
- if ((low % 6) == 0)
- printf("\n ");
- printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, state.distcode[low].val);
- if (++low == size)
- break;
- putchar(',');
- }
- puts("\n };");
-}
-#endif /* MAKEFIXED */
-
int ZLIB_INTERNAL inflate_ensure_window(struct inflate_state *state)
{
/* if it hasn't been done already, allocate space for the window */