diff options
| author | Mark Adler <git@madler.net> | 2026-01-05 01:15:38 -0600 |
|---|---|---|
| committer | Mark Adler <git@madler.net> | 2026-01-05 15:03:04 -0600 |
| commit | c267ef7306fe9fc1399833e3556cd9798dec2eb0 (patch) | |
| tree | bc18574b8ea4fc37befdf0174fb5f04472911f6f /infback.c | |
| parent | 916dc1ac351795c9bf86a3d19c3667b014b9d28e (diff) | |
| download | zlib-c267ef7306fe9fc1399833e3556cd9798dec2eb0.tar.gz zlib-c267ef7306fe9fc1399833e3556cd9798dec2eb0.tar.bz2 zlib-c267ef7306fe9fc1399833e3556cd9798dec2eb0.zip | |
Use atomics to build inflate fixed tables once.
This moves the once code from crc32.c to zutil.c, and uses it also
for building the inflate fixed tables when BUILDFIXED is defined.
The fixed tables are now housed in inftrees.c, shared by inflate.c
and infback.c. The once() function is now external, and so is
renamed to z_once() to avoid name collisions.
If either BUILDFIXED or DYNAMIC_CRC_TABLE is defined, and atomics
are not available, then a warning is issued noting that zlib is not
thread-safe.
Diffstat (limited to 'infback.c')
| -rw-r--r-- | infback.c | 53 |
1 files changed, 1 insertions, 52 deletions
| @@ -63,57 +63,6 @@ int ZEXPORT inflateBackInit_(z_streamp strm, int windowBits, | |||
| 63 | return Z_OK; | 63 | return Z_OK; |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | /* | ||
| 67 | Return state with length and distance decoding tables and index sizes set to | ||
| 68 | fixed code decoding. Normally this returns fixed tables from inffixed.h. | ||
| 69 | If BUILDFIXED is defined, then instead this routine builds the tables the | ||
| 70 | first time it's called, and returns those tables the first time and | ||
| 71 | thereafter. This reduces the size of the code by about 2K bytes, in | ||
| 72 | exchange for a little execution time. However, BUILDFIXED should not be | ||
| 73 | used for threaded applications, since the rewriting of the tables and virgin | ||
| 74 | may not be thread-safe. | ||
| 75 | */ | ||
| 76 | local void fixedtables(struct inflate_state FAR *state) { | ||
| 77 | #ifdef BUILDFIXED | ||
| 78 | static int virgin = 1; | ||
| 79 | static code *lenfix, *distfix; | ||
| 80 | static code fixed[544]; | ||
| 81 | |||
| 82 | /* build fixed huffman tables if first call (may not be thread safe) */ | ||
| 83 | if (virgin) { | ||
| 84 | unsigned sym, bits; | ||
| 85 | static code *next; | ||
| 86 | |||
| 87 | /* literal/length table */ | ||
| 88 | sym = 0; | ||
| 89 | while (sym < 144) state->lens[sym++] = 8; | ||
| 90 | while (sym < 256) state->lens[sym++] = 9; | ||
| 91 | while (sym < 280) state->lens[sym++] = 7; | ||
| 92 | while (sym < 288) state->lens[sym++] = 8; | ||
| 93 | next = fixed; | ||
| 94 | lenfix = next; | ||
| 95 | bits = 9; | ||
| 96 | inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); | ||
| 97 | |||
| 98 | /* distance table */ | ||
| 99 | sym = 0; | ||
| 100 | while (sym < 32) state->lens[sym++] = 5; | ||
| 101 | distfix = next; | ||
| 102 | bits = 5; | ||
| 103 | inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); | ||
| 104 | |||
| 105 | /* do this just once */ | ||
| 106 | virgin = 0; | ||
| 107 | } | ||
| 108 | #else /* !BUILDFIXED */ | ||
| 109 | # include "inffixed.h" | ||
| 110 | #endif /* BUILDFIXED */ | ||
| 111 | state->lencode = lenfix; | ||
| 112 | state->lenbits = 9; | ||
| 113 | state->distcode = distfix; | ||
| 114 | state->distbits = 5; | ||
| 115 | } | ||
| 116 | |||
| 117 | /* Macros for inflateBack(): */ | 66 | /* Macros for inflateBack(): */ |
| 118 | 67 | ||
| 119 | /* Load returned state from inflate_fast() */ | 68 | /* Load returned state from inflate_fast() */ |
| @@ -293,7 +242,7 @@ int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, | |||
| 293 | state->mode = STORED; | 242 | state->mode = STORED; |
| 294 | break; | 243 | break; |
| 295 | case 1: /* fixed block */ | 244 | case 1: /* fixed block */ |
| 296 | fixedtables(state); | 245 | inflate_fixed(state); |
| 297 | Tracev((stderr, "inflate: fixed codes block%s\n", | 246 | Tracev((stderr, "inflate: fixed codes block%s\n", |
| 298 | state->last ? " (last)" : "")); | 247 | state->last ? " (last)" : "")); |
| 299 | state->mode = LEN; /* decode codes */ | 248 | state->mode = LEN; /* decode codes */ |
