Remove BUILDFIXED support.
Split out MAKEFIXED into a separate 'makefixed' util that is easy
to use if we want to regenerate/verify inffixed.h.
/examplesh
/libz.so*
/libz-ng.so*
+/makefixed
/minigzip
/minigzip64
/minigzipsh
add_executable(switchlevels test/switchlevels.c)
configure_test_executable(switchlevels)
+ add_executable(makefixed tools/makefixed.c inftrees.c)
+ configure_test_executable(makefixed)
+
if(HAVE_OFF64_T)
add_executable(example64 test/example.c)
configure_test_executable(example64)
all: static shared
-static: example$(EXE) minigzip$(EXE) fuzzers
+static: example$(EXE) minigzip$(EXE) fuzzers makefixed$(EXE)
shared: examplesh$(EXE) minigzipsh$(EXE)
minigzip64.o:
$(CC) $(CFLAGS) -DWITH_GZFILEOP -D_FILE_OFFSET_BITS=64 $(INCLUDES) -c -o $@ $(SRCDIR)/test/minigzip.c
+makefixed.o:
+ $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/tools/makefixed.c
+
zlibrc.o: win32/zlib$(SUFFIX)1.rc
$(RC) $(RCFLAGS) -o $@ win32/zlib$(SUFFIX)1.rc
$(STRIP) $@
endif
+makefixed$(EXE): makefixed.o $(OBJG) $(STATICLIB)
+ $(CC) $(LDFLAGS) -o $@ makefixed.o $(OBJG) $(TEST_LIBS) $(LDSHAREDLIBC)
+ifneq ($(STRIP),)
+ $(STRIP) $@
+endif
+
install-shared: $(SHAREDTARGET)
ifneq ($(SHAREDTARGET),)
-@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
example64$(EXE) minigzip64$(EXE) \
checksum_fuzzer$(EXE) compress_fuzzer$(EXE) example_small_fuzzer$(EXE) example_large_fuzzer$(EXE) \
example_flush_fuzzer$(EXE) example_dict_fuzzer$(EXE) minigzip_fuzzer$(EXE) \
- infcover \
+ infcover makefixed$(EXE) \
$(STATICLIB) $(IMPORTLIB) $(SHAREDLIB) $(SHAREDLIBV) $(SHAREDLIBM) \
foo.gz so_locations \
_match.s maketree
" > Makefile
# Append header files dependences.
-for file in $(ls -1 $SRCDIR/*.c $SRCDIR/test/*.c $SRCDIR/test/fuzz/*.c $SRCDIR/$ARCHDIR/*.c); do
+for file in $(ls -1 $SRCDIR/*.c $SRCDIR/test/*.c $SRCDIR/test/fuzz/*.c $SRCDIR/$ARCHDIR/*.c $SRCDIR/tools/*.c); do
short_name=$(echo $file | sed -e "s#$SRCDIR/##g")
incs=$(grep -h include $file | sed -n 's/# *\include *"\(.*\.h\)".*/\1/p' | sort | uniq)
includes=$(for i in $incs; do
#include "inflate.h"
#include "inffast.h"
#include "inflate_p.h"
+#include "inffixed.h"
#include "memcopy.h"
#include "functable.h"
# 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;
/*
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 */
--- /dev/null
+#include <stdio.h>
+#include "zbuild.h"
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+
+// Build and return state with length and distance decoding tables and index sizes set to fixed code decoding.
+void ZLIB_INTERNAL buildfixedtables(struct inflate_state *state) {
+ static code *lenfix, *distfix;
+ static code fixed[544];
+
+ // build fixed huffman tables
+ 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);
+
+ state->lencode = lenfix;
+ state->lenbits = 9;
+ state->distcode = distfix;
+ state->distbits = 5;
+}
+
+
+// Create fixed tables on the fly and write out a inffixed.h file that is #include'd above.
+// makefixed() writes those tables to stdout, which would be piped to inffixed.h.
+void makefixed(void) {
+ unsigned low, size;
+ struct inflate_state state;
+
+ buildfixedtables(&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 };");
+}
+
+// The output of this application can be piped out to recreate inffixed.h
+int main(void) {
+ makefixed();
+ return 0;
+}
+
11: 0 (reserved)
One-time table building (smaller code, but not thread-safe if true):
- 12: BUILDFIXED -- build static block decoding tables when needed
+ 12: BUILDFIXED -- build static block decoding tables when needed (not supported by zlib-ng)
13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
14,15: 0 (reserved)
11: 0 (reserved)
One-time table building (smaller code, but not thread-safe if true):
- 12: BUILDFIXED -- build static block decoding tables when needed
+ 12: BUILDFIXED -- build static block decoding tables when needed (not supported by zlib-ng)
13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
14,15: 0 (reserved)
#ifdef ZLIB_WINAPI
flags += 1 << 10;
#endif
-#ifdef BUILDFIXED
- flags += 1 << 12;
-#endif
#ifdef DYNAMIC_CRC_TABLE
flags += 1 << 13;
#endif