]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Remove BUILDFIXED and MAKEFIXED. (#375)
authorHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 8 Aug 2019 08:38:06 +0000 (10:38 +0200)
committerGitHub <noreply@github.com>
Thu, 8 Aug 2019 08:38:06 +0000 (10:38 +0200)
Remove BUILDFIXED support.
Split out MAKEFIXED into a separate 'makefixed' util that is easy
to use if we want to regenerate/verify inffixed.h.

.gitignore
CMakeLists.txt
Makefile.in
configure
inflate.c
tools/makefixed.c [new file with mode: 0644]
zlib-ng.h
zlib.h
zutil.c

index 50e5ee6fab566972c5f9551108b37d0624f01946..da5bec5bd60a460fc2ce142d18e80d9d2ed3bdad 100644 (file)
@@ -18,6 +18,7 @@
 /examplesh
 /libz.so*
 /libz-ng.so*
+/makefixed
 /minigzip
 /minigzip64
 /minigzipsh
index f1bcb11674a0980888297532f230530161f5ca34..420fc1c6800b937f819686c2d8b4782c96c47e63 100644 (file)
@@ -825,6 +825,9 @@ if (ZLIB_ENABLE_TESTS)
     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)
index 69fe011658b60a07c7b518bd7168589d25352336..cf107b97ee53d175d43072aed728c48f01818061 100644 (file)
@@ -85,7 +85,7 @@ PIC_OBJS = $(PIC_OBJC)
 
 all: static shared
 
-static: example$(EXE) minigzip$(EXE) fuzzers
+static: example$(EXE) minigzip$(EXE) fuzzers makefixed$(EXE)
 
 shared: examplesh$(EXE) minigzipsh$(EXE)
 
@@ -193,6 +193,9 @@ example64.o:
 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
 
@@ -256,6 +259,12 @@ ifneq ($(STRIP),)
        $(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
@@ -330,7 +339,7 @@ clean:
           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
index 66dfefd3485b4fc3548d8d614e46b441dc634471..5a95d59c0cb5a9b651dda07f76eea0c4d98b6db9 100755 (executable)
--- a/configure
+++ b/configure
@@ -1347,7 +1347,7 @@ sed < $SRCDIR/Makefile.in "
 " > 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
index 7d166567845a5f6194deb3bb6181d8e039c60732..ed544ba95858248b1727f67a6e1d51dd2472fccc 100644 (file)
--- 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"
 
 #  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 */
diff --git a/tools/makefixed.c b/tools/makefixed.c
new file mode 100644 (file)
index 0000000..0f983bd
--- /dev/null
@@ -0,0 +1,89 @@
+#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;
+}
+
index a66b2af14ed3b299ef915888c569e9f9a7d681df..55fc12fa4010c8f1e6a38f75c83723f8eaca8576 100644 (file)
--- a/zlib-ng.h
+++ b/zlib-ng.h
@@ -1147,7 +1147,7 @@ ZEXTERN unsigned long ZEXPORT zng_zlibCompileFlags(void);
      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)
 
diff --git a/zlib.h b/zlib.h
index 891350013992a1bbc17606a957f87c338bd65a7e..bd8c9733e2b4b7aac04f76f608504d2ef98c3141 100644 (file)
--- a/zlib.h
+++ b/zlib.h
@@ -1158,7 +1158,7 @@ ZEXTERN unsigned long ZEXPORT zlibCompileFlags(void);
      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)
 
diff --git a/zutil.c b/zutil.c
index 7553db82bc8d492b2d6b92b4c31b5879e034ca38..223d0fcc6c1431001805caed0cae0d1cdf68e7ac 100644 (file)
--- a/zutil.c
+++ b/zutil.c
@@ -77,9 +77,6 @@ unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void)
 #ifdef ZLIB_WINAPI
     flags += 1 << 10;
 #endif
-#ifdef BUILDFIXED
-    flags += 1 << 12;
-#endif
 #ifdef DYNAMIC_CRC_TABLE
     flags += 1 << 13;
 #endif