aboutsummaryrefslogtreecommitdiff
path: root/archival/bz/bzlib_private.h
diff options
context:
space:
mode:
Diffstat (limited to 'archival/bz/bzlib_private.h')
-rw-r--r--archival/bz/bzlib_private.h84
1 files changed, 30 insertions, 54 deletions
diff --git a/archival/bz/bzlib_private.h b/archival/bz/bzlib_private.h
index 24ffbee9c..02f177eb2 100644
--- a/archival/bz/bzlib_private.h
+++ b/archival/bz/bzlib_private.h
@@ -25,31 +25,30 @@ in the file LICENSE.
25 25
26/* #include "bzlib.h" */ 26/* #include "bzlib.h" */
27 27
28#define BZ_DEBUG 0
29//#define BZ_NO_STDIO 1 - does not work
30
31
32/*-- General stuff. --*/ 28/*-- General stuff. --*/
33 29
34typedef unsigned char Bool; 30typedef unsigned char Bool;
35typedef unsigned char UChar;
36 31
37#define True ((Bool)1) 32#define True ((Bool)1)
38#define False ((Bool)0) 33#define False ((Bool)0)
39 34
35#if BZ_LIGHT_DEBUG
40static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN; 36static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
41#define AssertH(cond, errcode) \ 37#define AssertH(cond, errcode) \
42{ \ 38do { \
43 if (!(cond)) \ 39 if (!(cond)) \
44 bz_assert_fail(errcode); \ 40 bz_assert_fail(errcode); \
45} 41} while (0)
42#else
43#define AssertH(cond, msg) do { } while (0)
44#endif
46 45
47#if BZ_DEBUG 46#if BZ_DEBUG
48#define AssertD(cond, msg) \ 47#define AssertD(cond, msg) \
49{ \ 48do { \
50 if (!(cond)) \ 49 if (!(cond)) \
51 bb_error_msg_and_die("(debug build): internal error %s", msg); \ 50 bb_error_msg_and_die("(debug build): internal error %s", msg); \
52} 51} while (0)
53#else 52#else
54#define AssertD(cond, msg) do { } while (0) 53#define AssertD(cond, msg) do { } while (0)
55#endif 54#endif
@@ -79,35 +78,8 @@ static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
79#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE)) 78#define BZ_MAX_SELECTORS (2 + (900000 / BZ_G_SIZE))
80 79
81 80
82/*-- Stuff for randomising repetitive blocks. --*/
83
84static const int32_t BZ2_rNums[512];
85
86#define BZ_RAND_DECLS \
87 int32_t rNToGo; \
88 int32_t rTPos \
89
90#define BZ_RAND_INIT_MASK \
91 s->rNToGo = 0; \
92 s->rTPos = 0 \
93
94#define BZ_RAND_MASK ((s->rNToGo == 1) ? 1 : 0)
95
96#define BZ_RAND_UPD_MASK \
97{ \
98 if (s->rNToGo == 0) { \
99 s->rNToGo = BZ2_rNums[s->rTPos]; \
100 s->rTPos++; \
101 if (s->rTPos == 512) s->rTPos = 0; \
102 } \
103 s->rNToGo--; \
104}
105
106
107/*-- Stuff for doing CRCs. --*/ 81/*-- Stuff for doing CRCs. --*/
108 82
109static const uint32_t BZ2_crc32Table[256];
110
111#define BZ_INITIALISE_CRC(crcVar) \ 83#define BZ_INITIALISE_CRC(crcVar) \
112{ \ 84{ \
113 crcVar = 0xffffffffL; \ 85 crcVar = 0xffffffffL; \
@@ -118,9 +90,9 @@ static const uint32_t BZ2_crc32Table[256];
118 crcVar = ~(crcVar); \ 90 crcVar = ~(crcVar); \
119} 91}
120 92
121#define BZ_UPDATE_CRC(crcVar,cha) \ 93#define BZ_UPDATE_CRC(s, crcVar, cha) \
122{ \ 94{ \
123 crcVar = (crcVar << 8) ^ BZ2_crc32Table[(crcVar >> 24) ^ ((UChar)cha)]; \ 95 crcVar = (crcVar << 8) ^ s->crc32table[(crcVar >> 24) ^ ((uint8_t)cha)]; \
124} 96}
125 97
126 98
@@ -152,24 +124,28 @@ typedef struct EState {
152 int32_t state; 124 int32_t state;
153 125
154 /* remembers avail_in when flush/finish requested */ 126 /* remembers avail_in when flush/finish requested */
155 uint32_t avail_in_expect; //vda: do we need this? 127/* bbox: not needed, strm->avail_in always has the same value */
128/* commented out with '//#' throughout the code */
129 /* uint32_t avail_in_expect; */
156 130
157 /* for doing the block sorting */ 131 /* for doing the block sorting */
132 int32_t origPtr;
158 uint32_t *arr1; 133 uint32_t *arr1;
159 uint32_t *arr2; 134 uint32_t *arr2;
160 uint32_t *ftab; 135 uint32_t *ftab;
161 int32_t origPtr;
162 136
163 /* aliases for arr1 and arr2 */ 137 /* aliases for arr1 and arr2 */
164 uint32_t *ptr; 138 uint32_t *ptr;
165 UChar *block; 139 uint8_t *block;
166 uint16_t *mtfv; 140 uint16_t *mtfv;
167 UChar *zbits; 141 uint8_t *zbits;
142
143 /* guess what */
144 uint32_t *crc32table;
168 145
169 /* run-length-encoding of the input */ 146 /* run-length-encoding of the input */
170 uint32_t state_in_ch; 147 uint32_t state_in_ch;
171 int32_t state_in_len; 148 int32_t state_in_len;
172 BZ_RAND_DECLS;
173 149
174 /* input and output limits and current posns */ 150 /* input and output limits and current posns */
175 int32_t nblock; 151 int32_t nblock;
@@ -194,18 +170,18 @@ typedef struct EState {
194 170
195 /* map of bytes used in block */ 171 /* map of bytes used in block */
196 int32_t nInUse; 172 int32_t nInUse;
197 Bool inUse[256]; 173 Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
198 UChar unseqToSeq[256]; 174 uint8_t unseqToSeq[256];
199 175
200 /* stuff for coding the MTF values */ 176 /* stuff for coding the MTF values */
201 int32_t mtfFreq [BZ_MAX_ALPHA_SIZE]; 177 int32_t mtfFreq [BZ_MAX_ALPHA_SIZE];
202 UChar selector [BZ_MAX_SELECTORS]; 178 uint8_t selector [BZ_MAX_SELECTORS];
203 UChar selectorMtf[BZ_MAX_SELECTORS]; 179 uint8_t selectorMtf[BZ_MAX_SELECTORS];
204 180
205 UChar len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 181 uint8_t len [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
206 int32_t code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 182 int32_t code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
207 int32_t rfreq [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE]; 183 int32_t rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
208#ifdef FAST_GROUP6 184#if CONFIG_BZIP2_FEATURE_SPEED >= 5
209 /* second dimension: only 3 needed; 4 makes index calculations faster */ 185 /* second dimension: only 3 needed; 4 makes index calculations faster */
210 uint32_t len_pack[BZ_MAX_ALPHA_SIZE][4]; 186 uint32_t len_pack[BZ_MAX_ALPHA_SIZE][4];
211#endif 187#endif
@@ -218,16 +194,16 @@ static void
218BZ2_blockSort(EState*); 194BZ2_blockSort(EState*);
219 195
220static void 196static void
221BZ2_compressBlock(EState*, Bool); 197BZ2_compressBlock(EState*, int);
222 198
223static void 199static void
224BZ2_bsInitWrite(EState*); 200BZ2_bsInitWrite(EState*);
225 201
226static void 202static void
227BZ2_hbAssignCodes(int32_t*, UChar*, int32_t, int32_t, int32_t); 203BZ2_hbAssignCodes(int32_t*, uint8_t*, int32_t, int32_t, int32_t);
228 204
229static void 205static void
230BZ2_hbMakeCodeLengths(UChar*, int32_t*, int32_t, int32_t); 206BZ2_hbMakeCodeLengths(uint8_t*, int32_t*, int32_t, int32_t);
231 207
232/*-------------------------------------------------------------*/ 208/*-------------------------------------------------------------*/
233/*--- end bzlib_private.h ---*/ 209/*--- end bzlib_private.h ---*/