generic: bump 4.4 to rc4
[openwrt/openwrt.git] / target / linux / generic / patches-4.4 / 531-debloat_lzma.patch
1 --- a/include/linux/lzma/LzmaDec.h
2 +++ b/include/linux/lzma/LzmaDec.h
3 @@ -31,14 +31,6 @@ typedef struct _CLzmaProps
4 UInt32 dicSize;
5 } CLzmaProps;
6
7 -/* LzmaProps_Decode - decodes properties
8 -Returns:
9 - SZ_OK
10 - SZ_ERROR_UNSUPPORTED - Unsupported properties
11 -*/
12 -
13 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
14 -
15
16 /* ---------- LZMA Decoder state ---------- */
17
18 @@ -70,8 +62,6 @@ typedef struct
19
20 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
21
22 -void LzmaDec_Init(CLzmaDec *p);
23 -
24 /* There are two types of LZMA streams:
25 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
26 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
27 @@ -108,97 +98,6 @@ typedef enum
28
29 /* ELzmaStatus is used only as output value for function call */
30
31 -
32 -/* ---------- Interfaces ---------- */
33 -
34 -/* There are 3 levels of interfaces:
35 - 1) Dictionary Interface
36 - 2) Buffer Interface
37 - 3) One Call Interface
38 - You can select any of these interfaces, but don't mix functions from different
39 - groups for same object. */
40 -
41 -
42 -/* There are two variants to allocate state for Dictionary Interface:
43 - 1) LzmaDec_Allocate / LzmaDec_Free
44 - 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
45 - You can use variant 2, if you set dictionary buffer manually.
46 - For Buffer Interface you must always use variant 1.
47 -
48 -LzmaDec_Allocate* can return:
49 - SZ_OK
50 - SZ_ERROR_MEM - Memory allocation error
51 - SZ_ERROR_UNSUPPORTED - Unsupported properties
52 -*/
53 -
54 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
55 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
56 -
57 -SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
58 -void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
59 -
60 -/* ---------- Dictionary Interface ---------- */
61 -
62 -/* You can use it, if you want to eliminate the overhead for data copying from
63 - dictionary to some other external buffer.
64 - You must work with CLzmaDec variables directly in this interface.
65 -
66 - STEPS:
67 - LzmaDec_Constr()
68 - LzmaDec_Allocate()
69 - for (each new stream)
70 - {
71 - LzmaDec_Init()
72 - while (it needs more decompression)
73 - {
74 - LzmaDec_DecodeToDic()
75 - use data from CLzmaDec::dic and update CLzmaDec::dicPos
76 - }
77 - }
78 - LzmaDec_Free()
79 -*/
80 -
81 -/* LzmaDec_DecodeToDic
82 -
83 - The decoding to internal dictionary buffer (CLzmaDec::dic).
84 - You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
85 -
86 -finishMode:
87 - It has meaning only if the decoding reaches output limit (dicLimit).
88 - LZMA_FINISH_ANY - Decode just dicLimit bytes.
89 - LZMA_FINISH_END - Stream must be finished after dicLimit.
90 -
91 -Returns:
92 - SZ_OK
93 - status:
94 - LZMA_STATUS_FINISHED_WITH_MARK
95 - LZMA_STATUS_NOT_FINISHED
96 - LZMA_STATUS_NEEDS_MORE_INPUT
97 - LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
98 - SZ_ERROR_DATA - Data error
99 -*/
100 -
101 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
102 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
103 -
104 -
105 -/* ---------- Buffer Interface ---------- */
106 -
107 -/* It's zlib-like interface.
108 - See LzmaDec_DecodeToDic description for information about STEPS and return results,
109 - but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
110 - to work with CLzmaDec variables manually.
111 -
112 -finishMode:
113 - It has meaning only if the decoding reaches output limit (*destLen).
114 - LZMA_FINISH_ANY - Decode just destLen bytes.
115 - LZMA_FINISH_END - Stream must be finished after (*destLen).
116 -*/
117 -
118 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
119 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
120 -
121 -
122 /* ---------- One Call Interface ---------- */
123
124 /* LzmaDecode
125 --- a/lib/lzma/LzmaDec.c
126 +++ b/lib/lzma/LzmaDec.c
127 @@ -682,7 +682,7 @@ static void LzmaDec_InitRc(CLzmaDec *p,
128 p->needFlush = 0;
129 }
130
131 -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
132 +static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
133 {
134 p->needFlush = 1;
135 p->remainLen = 0;
136 @@ -698,7 +698,7 @@ void LzmaDec_InitDicAndState(CLzmaDec *p
137 p->needInitState = 1;
138 }
139
140 -void LzmaDec_Init(CLzmaDec *p)
141 +static void LzmaDec_Init(CLzmaDec *p)
142 {
143 p->dicPos = 0;
144 LzmaDec_InitDicAndState(p, True, True);
145 @@ -716,7 +716,7 @@ static void LzmaDec_InitStateReal(CLzmaD
146 p->needInitState = 0;
147 }
148
149 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
150 +static SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
151 ELzmaFinishMode finishMode, ELzmaStatus *status)
152 {
153 SizeT inSize = *srcLen;
154 @@ -837,65 +837,13 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, Si
155 return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
156 }
157
158 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
159 -{
160 - SizeT outSize = *destLen;
161 - SizeT inSize = *srcLen;
162 - *srcLen = *destLen = 0;
163 - for (;;)
164 - {
165 - SizeT inSizeCur = inSize, outSizeCur, dicPos;
166 - ELzmaFinishMode curFinishMode;
167 - SRes res;
168 - if (p->dicPos == p->dicBufSize)
169 - p->dicPos = 0;
170 - dicPos = p->dicPos;
171 - if (outSize > p->dicBufSize - dicPos)
172 - {
173 - outSizeCur = p->dicBufSize;
174 - curFinishMode = LZMA_FINISH_ANY;
175 - }
176 - else
177 - {
178 - outSizeCur = dicPos + outSize;
179 - curFinishMode = finishMode;
180 - }
181 -
182 - res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
183 - src += inSizeCur;
184 - inSize -= inSizeCur;
185 - *srcLen += inSizeCur;
186 - outSizeCur = p->dicPos - dicPos;
187 - memcpy(dest, p->dic + dicPos, outSizeCur);
188 - dest += outSizeCur;
189 - outSize -= outSizeCur;
190 - *destLen += outSizeCur;
191 - if (res != 0)
192 - return res;
193 - if (outSizeCur == 0 || outSize == 0)
194 - return SZ_OK;
195 - }
196 -}
197 -
198 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
199 +static void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
200 {
201 alloc->Free(alloc, p->probs);
202 p->probs = 0;
203 }
204
205 -static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
206 -{
207 - alloc->Free(alloc, p->dic);
208 - p->dic = 0;
209 -}
210 -
211 -void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
212 -{
213 - LzmaDec_FreeProbs(p, alloc);
214 - LzmaDec_FreeDict(p, alloc);
215 -}
216 -
217 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
218 +static SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
219 {
220 UInt32 dicSize;
221 Byte d;
222 @@ -935,7 +883,7 @@ static SRes LzmaDec_AllocateProbs2(CLzma
223 return SZ_OK;
224 }
225
226 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
227 +static SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
228 {
229 CLzmaProps propNew;
230 RINOK(LzmaProps_Decode(&propNew, props, propsSize));
231 @@ -943,28 +891,6 @@ SRes LzmaDec_AllocateProbs(CLzmaDec *p,
232 p->prop = propNew;
233 return SZ_OK;
234 }
235 -
236 -SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
237 -{
238 - CLzmaProps propNew;
239 - SizeT dicBufSize;
240 - RINOK(LzmaProps_Decode(&propNew, props, propsSize));
241 - RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
242 - dicBufSize = propNew.dicSize;
243 - if (p->dic == 0 || dicBufSize != p->dicBufSize)
244 - {
245 - LzmaDec_FreeDict(p, alloc);
246 - p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
247 - if (p->dic == 0)
248 - {
249 - LzmaDec_FreeProbs(p, alloc);
250 - return SZ_ERROR_MEM;
251 - }
252 - }
253 - p->dicBufSize = dicBufSize;
254 - p->prop = propNew;
255 - return SZ_OK;
256 -}
257
258 SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
259 const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
260 --- a/include/linux/lzma/LzmaEnc.h
261 +++ b/include/linux/lzma/LzmaEnc.h
262 @@ -31,9 +31,6 @@ typedef struct _CLzmaEncProps
263 } CLzmaEncProps;
264
265 void LzmaEncProps_Init(CLzmaEncProps *p);
266 -void LzmaEncProps_Normalize(CLzmaEncProps *p);
267 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
268 -
269
270 /* ---------- CLzmaEncHandle Interface ---------- */
271
272 @@ -53,26 +50,9 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
273 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
274 SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
275 SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
276 -SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
277 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
278 SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
279 int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
280
281 -/* ---------- One Call Interface ---------- */
282 -
283 -/* LzmaEncode
284 -Return code:
285 - SZ_OK - OK
286 - SZ_ERROR_MEM - Memory allocation error
287 - SZ_ERROR_PARAM - Incorrect paramater
288 - SZ_ERROR_OUTPUT_EOF - output buffer overflow
289 - SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
290 -*/
291 -
292 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
293 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
294 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
295 -
296 #ifdef __cplusplus
297 }
298 #endif
299 --- a/lib/lzma/LzmaEnc.c
300 +++ b/lib/lzma/LzmaEnc.c
301 @@ -53,7 +53,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
302 p->writeEndMark = 0;
303 }
304
305 -void LzmaEncProps_Normalize(CLzmaEncProps *p)
306 +static void LzmaEncProps_Normalize(CLzmaEncProps *p)
307 {
308 int level = p->level;
309 if (level < 0) level = 5;
310 @@ -76,7 +76,7 @@ void LzmaEncProps_Normalize(CLzmaEncProp
311 #endif
312 }
313
314 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
315 +static UInt32 __maybe_unused LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
316 {
317 CLzmaEncProps props = *props2;
318 LzmaEncProps_Normalize(&props);
319 @@ -93,7 +93,7 @@ UInt32 LzmaEncProps_GetDictSize(const CL
320
321 #define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
322
323 -UInt32 GetPosSlot1(UInt32 pos)
324 +static UInt32 GetPosSlot1(UInt32 pos)
325 {
326 UInt32 res;
327 BSR2_RET(pos, res);
328 @@ -107,7 +107,7 @@ UInt32 GetPosSlot1(UInt32 pos)
329 #define kNumLogBits (9 + (int)sizeof(size_t) / 2)
330 #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
331
332 -void LzmaEnc_FastPosInit(Byte *g_FastPos)
333 +static void LzmaEnc_FastPosInit(Byte *g_FastPos)
334 {
335 int c = 2, slotFast;
336 g_FastPos[0] = 0;
337 @@ -339,58 +339,6 @@ typedef struct
338 CSaveState saveState;
339 } CLzmaEnc;
340
341 -void LzmaEnc_SaveState(CLzmaEncHandle pp)
342 -{
343 - CLzmaEnc *p = (CLzmaEnc *)pp;
344 - CSaveState *dest = &p->saveState;
345 - int i;
346 - dest->lenEnc = p->lenEnc;
347 - dest->repLenEnc = p->repLenEnc;
348 - dest->state = p->state;
349 -
350 - for (i = 0; i < kNumStates; i++)
351 - {
352 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
353 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
354 - }
355 - for (i = 0; i < kNumLenToPosStates; i++)
356 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
357 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
358 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
359 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
360 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
361 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
362 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
363 - memcpy(dest->reps, p->reps, sizeof(p->reps));
364 - memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
365 -}
366 -
367 -void LzmaEnc_RestoreState(CLzmaEncHandle pp)
368 -{
369 - CLzmaEnc *dest = (CLzmaEnc *)pp;
370 - const CSaveState *p = &dest->saveState;
371 - int i;
372 - dest->lenEnc = p->lenEnc;
373 - dest->repLenEnc = p->repLenEnc;
374 - dest->state = p->state;
375 -
376 - for (i = 0; i < kNumStates; i++)
377 - {
378 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
379 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
380 - }
381 - for (i = 0; i < kNumLenToPosStates; i++)
382 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
383 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
384 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
385 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
386 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
387 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
388 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
389 - memcpy(dest->reps, p->reps, sizeof(p->reps));
390 - memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
391 -}
392 -
393 SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
394 {
395 CLzmaEnc *p = (CLzmaEnc *)pp;
396 @@ -600,7 +548,7 @@ static void LitEnc_EncodeMatched(CRangeE
397 while (symbol < 0x10000);
398 }
399
400 -void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
401 +static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
402 {
403 UInt32 i;
404 for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
405 @@ -1676,7 +1624,7 @@ static void FillDistancesPrices(CLzmaEnc
406 p->matchPriceCount = 0;
407 }
408
409 -void LzmaEnc_Construct(CLzmaEnc *p)
410 +static void LzmaEnc_Construct(CLzmaEnc *p)
411 {
412 RangeEnc_Construct(&p->rc);
413 MatchFinder_Construct(&p->matchFinderBase);
414 @@ -1709,7 +1657,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
415 return p;
416 }
417
418 -void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
419 +static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
420 {
421 alloc->Free(alloc, p->litProbs);
422 alloc->Free(alloc, p->saveState.litProbs);
423 @@ -1717,7 +1665,7 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAl
424 p->saveState.litProbs = 0;
425 }
426
427 -void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
428 +static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
429 {
430 #ifndef _7ZIP_ST
431 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
432 @@ -1947,7 +1895,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, U
433 return SZ_OK;
434 }
435
436 -void LzmaEnc_Init(CLzmaEnc *p)
437 +static void LzmaEnc_Init(CLzmaEnc *p)
438 {
439 UInt32 i;
440 p->state = 0;
441 @@ -2005,7 +1953,7 @@ void LzmaEnc_Init(CLzmaEnc *p)
442 p->lpMask = (1 << p->lp) - 1;
443 }
444
445 -void LzmaEnc_InitPrices(CLzmaEnc *p)
446 +static void LzmaEnc_InitPrices(CLzmaEnc *p)
447 {
448 if (!p->fastMode)
449 {
450 @@ -2037,26 +1985,6 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEn
451 return SZ_OK;
452 }
453
454 -static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
455 - ISzAlloc *alloc, ISzAlloc *allocBig)
456 -{
457 - CLzmaEnc *p = (CLzmaEnc *)pp;
458 - p->matchFinderBase.stream = inStream;
459 - p->needInit = 1;
460 - p->rc.outStream = outStream;
461 - return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
462 -}
463 -
464 -SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
465 - ISeqInStream *inStream, UInt32 keepWindowSize,
466 - ISzAlloc *alloc, ISzAlloc *allocBig)
467 -{
468 - CLzmaEnc *p = (CLzmaEnc *)pp;
469 - p->matchFinderBase.stream = inStream;
470 - p->needInit = 1;
471 - return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
472 -}
473 -
474 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
475 {
476 p->matchFinderBase.directInput = 1;
477 @@ -2064,7 +1992,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc
478 p->matchFinderBase.directInputRem = srcLen;
479 }
480
481 -SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
482 +static SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
483 UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
484 {
485 CLzmaEnc *p = (CLzmaEnc *)pp;
486 @@ -2074,7 +2002,7 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle p
487 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
488 }
489
490 -void LzmaEnc_Finish(CLzmaEncHandle pp)
491 +static void LzmaEnc_Finish(CLzmaEncHandle pp)
492 {
493 #ifndef _7ZIP_ST
494 CLzmaEnc *p = (CLzmaEnc *)pp;
495 @@ -2107,53 +2035,6 @@ static size_t MyWrite(void *pp, const vo
496 return size;
497 }
498
499 -
500 -UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
501 -{
502 - const CLzmaEnc *p = (CLzmaEnc *)pp;
503 - return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
504 -}
505 -
506 -const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
507 -{
508 - const CLzmaEnc *p = (CLzmaEnc *)pp;
509 - return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
510 -}
511 -
512 -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
513 - Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
514 -{
515 - CLzmaEnc *p = (CLzmaEnc *)pp;
516 - UInt64 nowPos64;
517 - SRes res;
518 - CSeqOutStreamBuf outStream;
519 -
520 - outStream.funcTable.Write = MyWrite;
521 - outStream.data = dest;
522 - outStream.rem = *destLen;
523 - outStream.overflow = False;
524 -
525 - p->writeEndMark = False;
526 - p->finished = False;
527 - p->result = SZ_OK;
528 -
529 - if (reInit)
530 - LzmaEnc_Init(p);
531 - LzmaEnc_InitPrices(p);
532 - nowPos64 = p->nowPos64;
533 - RangeEnc_Init(&p->rc);
534 - p->rc.outStream = &outStream.funcTable;
535 -
536 - res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
537 -
538 - *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
539 - *destLen -= outStream.rem;
540 - if (outStream.overflow)
541 - return SZ_ERROR_OUTPUT_EOF;
542 -
543 - return res;
544 -}
545 -
546 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
547 {
548 SRes res = SZ_OK;
549 @@ -2184,13 +2065,6 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p,
550 return res;
551 }
552
553 -SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
554 - ISzAlloc *alloc, ISzAlloc *allocBig)
555 -{
556 - RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
557 - return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
558 -}
559 -
560 SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
561 {
562 CLzmaEnc *p = (CLzmaEnc *)pp;
563 @@ -2247,25 +2121,3 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp
564 return SZ_ERROR_OUTPUT_EOF;
565 return res;
566 }
567 -
568 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
569 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
570 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
571 -{
572 - CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
573 - SRes res;
574 - if (p == 0)
575 - return SZ_ERROR_MEM;
576 -
577 - res = LzmaEnc_SetProps(p, props);
578 - if (res == SZ_OK)
579 - {
580 - res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
581 - if (res == SZ_OK)
582 - res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
583 - writeEndMark, progress, alloc, allocBig);
584 - }
585 -
586 - LzmaEnc_Destroy(p, alloc, allocBig);
587 - return res;
588 -}
589 --- a/include/linux/lzma/LzFind.h
590 +++ b/include/linux/lzma/LzFind.h
591 @@ -55,11 +55,6 @@ typedef struct _CMatchFinder
592
593 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
594
595 -int MatchFinder_NeedMove(CMatchFinder *p);
596 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
597 -void MatchFinder_MoveBlock(CMatchFinder *p);
598 -void MatchFinder_ReadIfRequired(CMatchFinder *p);
599 -
600 void MatchFinder_Construct(CMatchFinder *p);
601
602 /* Conditions:
603 @@ -70,12 +65,6 @@ int MatchFinder_Create(CMatchFinder *p,
604 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
605 ISzAlloc *alloc);
606 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
607 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
608 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
609 -
610 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
611 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
612 - UInt32 *distances, UInt32 maxLen);
613
614 /*
615 Conditions:
616 @@ -102,12 +91,6 @@ typedef struct _IMatchFinder
617
618 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
619
620 -void MatchFinder_Init(CMatchFinder *p);
621 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
622 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
623 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
624 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
625 -
626 #ifdef __cplusplus
627 }
628 #endif
629 --- a/lib/lzma/LzFind.c
630 +++ b/lib/lzma/LzFind.c
631 @@ -14,9 +14,15 @@
632
633 #define kStartMaxLen 3
634
635 +#if 0
636 +#define DIRECT_INPUT p->directInput
637 +#else
638 +#define DIRECT_INPUT 1
639 +#endif
640 +
641 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
642 {
643 - if (!p->directInput)
644 + if (!DIRECT_INPUT)
645 {
646 alloc->Free(alloc, p->bufferBase);
647 p->bufferBase = 0;
648 @@ -28,7 +34,7 @@ static void LzInWindow_Free(CMatchFinder
649 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
650 {
651 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
652 - if (p->directInput)
653 + if (DIRECT_INPUT)
654 {
655 p->blockSize = blockSize;
656 return 1;
657 @@ -42,12 +48,12 @@ static int LzInWindow_Create(CMatchFinde
658 return (p->bufferBase != 0);
659 }
660
661 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
662 -Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
663 +static Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
664 +static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
665
666 -UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
667 +static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
668
669 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
670 +static void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
671 {
672 p->posLimit -= subValue;
673 p->pos -= subValue;
674 @@ -58,7 +64,7 @@ static void MatchFinder_ReadBlock(CMatch
675 {
676 if (p->streamEndWasReached || p->result != SZ_OK)
677 return;
678 - if (p->directInput)
679 + if (DIRECT_INPUT)
680 {
681 UInt32 curSize = 0xFFFFFFFF - p->streamPos;
682 if (curSize > p->directInputRem)
683 @@ -89,7 +95,7 @@ static void MatchFinder_ReadBlock(CMatch
684 }
685 }
686
687 -void MatchFinder_MoveBlock(CMatchFinder *p)
688 +static void MatchFinder_MoveBlock(CMatchFinder *p)
689 {
690 memmove(p->bufferBase,
691 p->buffer - p->keepSizeBefore,
692 @@ -97,22 +103,14 @@ void MatchFinder_MoveBlock(CMatchFinder
693 p->buffer = p->bufferBase + p->keepSizeBefore;
694 }
695
696 -int MatchFinder_NeedMove(CMatchFinder *p)
697 +static int MatchFinder_NeedMove(CMatchFinder *p)
698 {
699 - if (p->directInput)
700 + if (DIRECT_INPUT)
701 return 0;
702 /* if (p->streamEndWasReached) return 0; */
703 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
704 }
705
706 -void MatchFinder_ReadIfRequired(CMatchFinder *p)
707 -{
708 - if (p->streamEndWasReached)
709 - return;
710 - if (p->keepSizeAfter >= p->streamPos - p->pos)
711 - MatchFinder_ReadBlock(p);
712 -}
713 -
714 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
715 {
716 if (MatchFinder_NeedMove(p))
717 @@ -268,7 +266,7 @@ static void MatchFinder_SetLimits(CMatch
718 p->posLimit = p->pos + limit;
719 }
720
721 -void MatchFinder_Init(CMatchFinder *p)
722 +static void MatchFinder_Init(CMatchFinder *p)
723 {
724 UInt32 i;
725 for (i = 0; i < p->hashSizeSum; i++)
726 @@ -287,7 +285,7 @@ static UInt32 MatchFinder_GetSubValue(CM
727 return (p->pos - p->historySize - 1) & kNormalizeMask;
728 }
729
730 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
731 +static void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
732 {
733 UInt32 i;
734 for (i = 0; i < numItems; i++)
735 @@ -319,38 +317,7 @@ static void MatchFinder_CheckLimits(CMat
736 MatchFinder_SetLimits(p);
737 }
738
739 -static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
740 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
741 - UInt32 *distances, UInt32 maxLen)
742 -{
743 - son[_cyclicBufferPos] = curMatch;
744 - for (;;)
745 - {
746 - UInt32 delta = pos - curMatch;
747 - if (cutValue-- == 0 || delta >= _cyclicBufferSize)
748 - return distances;
749 - {
750 - const Byte *pb = cur - delta;
751 - curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
752 - if (pb[maxLen] == cur[maxLen] && *pb == *cur)
753 - {
754 - UInt32 len = 0;
755 - while (++len != lenLimit)
756 - if (pb[len] != cur[len])
757 - break;
758 - if (maxLen < len)
759 - {
760 - *distances++ = maxLen = len;
761 - *distances++ = delta - 1;
762 - if (len == lenLimit)
763 - return distances;
764 - }
765 - }
766 - }
767 - }
768 -}
769 -
770 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
771 +static UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
772 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
773 UInt32 *distances, UInt32 maxLen)
774 {
775 @@ -460,10 +427,10 @@ static void SkipMatchesSpec(UInt32 lenLi
776 p->buffer++; \
777 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
778
779 -#define MOVE_POS_RET MOVE_POS return offset;
780 -
781 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
782
783 +#define MOVE_POS_RET MatchFinder_MovePos(p); return offset;
784 +
785 #define GET_MATCHES_HEADER2(minLen, ret_op) \
786 UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
787 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
788 @@ -479,62 +446,7 @@ static void MatchFinder_MovePos(CMatchFi
789 distances + offset, maxLen) - distances); MOVE_POS_RET;
790
791 #define SKIP_FOOTER \
792 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
793 -
794 -static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
795 -{
796 - UInt32 offset;
797 - GET_MATCHES_HEADER(2)
798 - HASH2_CALC;
799 - curMatch = p->hash[hashValue];
800 - p->hash[hashValue] = p->pos;
801 - offset = 0;
802 - GET_MATCHES_FOOTER(offset, 1)
803 -}
804 -
805 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
806 -{
807 - UInt32 offset;
808 - GET_MATCHES_HEADER(3)
809 - HASH_ZIP_CALC;
810 - curMatch = p->hash[hashValue];
811 - p->hash[hashValue] = p->pos;
812 - offset = 0;
813 - GET_MATCHES_FOOTER(offset, 2)
814 -}
815 -
816 -static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
817 -{
818 - UInt32 hash2Value, delta2, maxLen, offset;
819 - GET_MATCHES_HEADER(3)
820 -
821 - HASH3_CALC;
822 -
823 - delta2 = p->pos - p->hash[hash2Value];
824 - curMatch = p->hash[kFix3HashSize + hashValue];
825 -
826 - p->hash[hash2Value] =
827 - p->hash[kFix3HashSize + hashValue] = p->pos;
828 -
829 -
830 - maxLen = 2;
831 - offset = 0;
832 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
833 - {
834 - for (; maxLen != lenLimit; maxLen++)
835 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
836 - break;
837 - distances[0] = maxLen;
838 - distances[1] = delta2 - 1;
839 - offset = 2;
840 - if (maxLen == lenLimit)
841 - {
842 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
843 - MOVE_POS_RET;
844 - }
845 - }
846 - GET_MATCHES_FOOTER(offset, maxLen)
847 -}
848 + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MatchFinder_MovePos(p);
849
850 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
851 {
852 @@ -583,108 +495,6 @@ static UInt32 Bt4_MatchFinder_GetMatches
853 GET_MATCHES_FOOTER(offset, maxLen)
854 }
855
856 -static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
857 -{
858 - UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
859 - GET_MATCHES_HEADER(4)
860 -
861 - HASH4_CALC;
862 -
863 - delta2 = p->pos - p->hash[ hash2Value];
864 - delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
865 - curMatch = p->hash[kFix4HashSize + hashValue];
866 -
867 - p->hash[ hash2Value] =
868 - p->hash[kFix3HashSize + hash3Value] =
869 - p->hash[kFix4HashSize + hashValue] = p->pos;
870 -
871 - maxLen = 1;
872 - offset = 0;
873 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
874 - {
875 - distances[0] = maxLen = 2;
876 - distances[1] = delta2 - 1;
877 - offset = 2;
878 - }
879 - if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
880 - {
881 - maxLen = 3;
882 - distances[offset + 1] = delta3 - 1;
883 - offset += 2;
884 - delta2 = delta3;
885 - }
886 - if (offset != 0)
887 - {
888 - for (; maxLen != lenLimit; maxLen++)
889 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
890 - break;
891 - distances[offset - 2] = maxLen;
892 - if (maxLen == lenLimit)
893 - {
894 - p->son[p->cyclicBufferPos] = curMatch;
895 - MOVE_POS_RET;
896 - }
897 - }
898 - if (maxLen < 3)
899 - maxLen = 3;
900 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
901 - distances + offset, maxLen) - (distances));
902 - MOVE_POS_RET
903 -}
904 -
905 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
906 -{
907 - UInt32 offset;
908 - GET_MATCHES_HEADER(3)
909 - HASH_ZIP_CALC;
910 - curMatch = p->hash[hashValue];
911 - p->hash[hashValue] = p->pos;
912 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
913 - distances, 2) - (distances));
914 - MOVE_POS_RET
915 -}
916 -
917 -static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
918 -{
919 - do
920 - {
921 - SKIP_HEADER(2)
922 - HASH2_CALC;
923 - curMatch = p->hash[hashValue];
924 - p->hash[hashValue] = p->pos;
925 - SKIP_FOOTER
926 - }
927 - while (--num != 0);
928 -}
929 -
930 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
931 -{
932 - do
933 - {
934 - SKIP_HEADER(3)
935 - HASH_ZIP_CALC;
936 - curMatch = p->hash[hashValue];
937 - p->hash[hashValue] = p->pos;
938 - SKIP_FOOTER
939 - }
940 - while (--num != 0);
941 -}
942 -
943 -static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
944 -{
945 - do
946 - {
947 - UInt32 hash2Value;
948 - SKIP_HEADER(3)
949 - HASH3_CALC;
950 - curMatch = p->hash[kFix3HashSize + hashValue];
951 - p->hash[hash2Value] =
952 - p->hash[kFix3HashSize + hashValue] = p->pos;
953 - SKIP_FOOTER
954 - }
955 - while (--num != 0);
956 -}
957 -
958 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
959 {
960 do
961 @@ -701,61 +511,12 @@ static void Bt4_MatchFinder_Skip(CMatchF
962 while (--num != 0);
963 }
964
965 -static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
966 -{
967 - do
968 - {
969 - UInt32 hash2Value, hash3Value;
970 - SKIP_HEADER(4)
971 - HASH4_CALC;
972 - curMatch = p->hash[kFix4HashSize + hashValue];
973 - p->hash[ hash2Value] =
974 - p->hash[kFix3HashSize + hash3Value] =
975 - p->hash[kFix4HashSize + hashValue] = p->pos;
976 - p->son[p->cyclicBufferPos] = curMatch;
977 - MOVE_POS
978 - }
979 - while (--num != 0);
980 -}
981 -
982 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
983 -{
984 - do
985 - {
986 - SKIP_HEADER(3)
987 - HASH_ZIP_CALC;
988 - curMatch = p->hash[hashValue];
989 - p->hash[hashValue] = p->pos;
990 - p->son[p->cyclicBufferPos] = curMatch;
991 - MOVE_POS
992 - }
993 - while (--num != 0);
994 -}
995 -
996 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
997 {
998 vTable->Init = (Mf_Init_Func)MatchFinder_Init;
999 vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
1000 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
1001 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
1002 - if (!p->btMode)
1003 - {
1004 - vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
1005 - vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
1006 - }
1007 - else if (p->numHashBytes == 2)
1008 - {
1009 - vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
1010 - vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
1011 - }
1012 - else if (p->numHashBytes == 3)
1013 - {
1014 - vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
1015 - vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
1016 - }
1017 - else
1018 - {
1019 - vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1020 - vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
1021 - }
1022 + vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1023 + vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
1024 }