9f9690f1876625853681c0edcfc5086dc85af52c
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.10 / 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,33 +883,11 @@ 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 -{
228 - CLzmaProps propNew;
229 - RINOK(LzmaProps_Decode(&propNew, props, propsSize));
230 - RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
231 - p->prop = propNew;
232 - return SZ_OK;
233 -}
234 -
235 -SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
236 +static SRes LzmaDec_AllocateProbs(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 --- a/include/linux/lzma/LzmaEnc.h
258 +++ b/include/linux/lzma/LzmaEnc.h
259 @@ -31,9 +31,6 @@ typedef struct _CLzmaEncProps
260 } CLzmaEncProps;
261
262 void LzmaEncProps_Init(CLzmaEncProps *p);
263 -void LzmaEncProps_Normalize(CLzmaEncProps *p);
264 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
265 -
266
267 /* ---------- CLzmaEncHandle Interface ---------- */
268
269 @@ -53,26 +50,9 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
270 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
271 SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
272 SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
273 -SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
274 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
275 SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
276 int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
277
278 -/* ---------- One Call Interface ---------- */
279 -
280 -/* LzmaEncode
281 -Return code:
282 - SZ_OK - OK
283 - SZ_ERROR_MEM - Memory allocation error
284 - SZ_ERROR_PARAM - Incorrect paramater
285 - SZ_ERROR_OUTPUT_EOF - output buffer overflow
286 - SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
287 -*/
288 -
289 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
290 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
291 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
292 -
293 #ifdef __cplusplus
294 }
295 #endif
296 --- a/lib/lzma/LzmaEnc.c
297 +++ b/lib/lzma/LzmaEnc.c
298 @@ -53,7 +53,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
299 p->writeEndMark = 0;
300 }
301
302 -void LzmaEncProps_Normalize(CLzmaEncProps *p)
303 +static void LzmaEncProps_Normalize(CLzmaEncProps *p)
304 {
305 int level = p->level;
306 if (level < 0) level = 5;
307 @@ -76,7 +76,7 @@ void LzmaEncProps_Normalize(CLzmaEncProp
308 #endif
309 }
310
311 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
312 +static UInt32 __maybe_unused LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
313 {
314 CLzmaEncProps props = *props2;
315 LzmaEncProps_Normalize(&props);
316 @@ -93,7 +93,7 @@ UInt32 LzmaEncProps_GetDictSize(const CL
317
318 #define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
319
320 -UInt32 GetPosSlot1(UInt32 pos)
321 +static UInt32 GetPosSlot1(UInt32 pos)
322 {
323 UInt32 res;
324 BSR2_RET(pos, res);
325 @@ -107,7 +107,7 @@ UInt32 GetPosSlot1(UInt32 pos)
326 #define kNumLogBits (9 + (int)sizeof(size_t) / 2)
327 #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
328
329 -void LzmaEnc_FastPosInit(Byte *g_FastPos)
330 +static void LzmaEnc_FastPosInit(Byte *g_FastPos)
331 {
332 int c = 2, slotFast;
333 g_FastPos[0] = 0;
334 @@ -339,58 +339,6 @@ typedef struct
335 CSaveState saveState;
336 } CLzmaEnc;
337
338 -void LzmaEnc_SaveState(CLzmaEncHandle pp)
339 -{
340 - CLzmaEnc *p = (CLzmaEnc *)pp;
341 - CSaveState *dest = &p->saveState;
342 - int i;
343 - dest->lenEnc = p->lenEnc;
344 - dest->repLenEnc = p->repLenEnc;
345 - dest->state = p->state;
346 -
347 - for (i = 0; i < kNumStates; i++)
348 - {
349 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
350 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
351 - }
352 - for (i = 0; i < kNumLenToPosStates; i++)
353 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
354 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
355 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
356 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
357 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
358 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
359 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
360 - memcpy(dest->reps, p->reps, sizeof(p->reps));
361 - memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
362 -}
363 -
364 -void LzmaEnc_RestoreState(CLzmaEncHandle pp)
365 -{
366 - CLzmaEnc *dest = (CLzmaEnc *)pp;
367 - const CSaveState *p = &dest->saveState;
368 - int i;
369 - dest->lenEnc = p->lenEnc;
370 - dest->repLenEnc = p->repLenEnc;
371 - dest->state = p->state;
372 -
373 - for (i = 0; i < kNumStates; i++)
374 - {
375 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
376 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
377 - }
378 - for (i = 0; i < kNumLenToPosStates; i++)
379 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
380 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
381 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
382 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
383 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
384 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
385 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
386 - memcpy(dest->reps, p->reps, sizeof(p->reps));
387 - memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
388 -}
389 -
390 SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
391 {
392 CLzmaEnc *p = (CLzmaEnc *)pp;
393 @@ -600,7 +548,7 @@ static void LitEnc_EncodeMatched(CRangeE
394 while (symbol < 0x10000);
395 }
396
397 -void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
398 +static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
399 {
400 UInt32 i;
401 for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
402 @@ -1676,7 +1624,7 @@ static void FillDistancesPrices(CLzmaEnc
403 p->matchPriceCount = 0;
404 }
405
406 -void LzmaEnc_Construct(CLzmaEnc *p)
407 +static void LzmaEnc_Construct(CLzmaEnc *p)
408 {
409 RangeEnc_Construct(&p->rc);
410 MatchFinder_Construct(&p->matchFinderBase);
411 @@ -1709,7 +1657,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
412 return p;
413 }
414
415 -void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
416 +static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
417 {
418 alloc->Free(alloc, p->litProbs);
419 alloc->Free(alloc, p->saveState.litProbs);
420 @@ -1717,7 +1665,7 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAl
421 p->saveState.litProbs = 0;
422 }
423
424 -void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
425 +static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
426 {
427 #ifndef _7ZIP_ST
428 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
429 @@ -1947,7 +1895,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, U
430 return SZ_OK;
431 }
432
433 -void LzmaEnc_Init(CLzmaEnc *p)
434 +static void LzmaEnc_Init(CLzmaEnc *p)
435 {
436 UInt32 i;
437 p->state = 0;
438 @@ -2005,7 +1953,7 @@ void LzmaEnc_Init(CLzmaEnc *p)
439 p->lpMask = (1 << p->lp) - 1;
440 }
441
442 -void LzmaEnc_InitPrices(CLzmaEnc *p)
443 +static void LzmaEnc_InitPrices(CLzmaEnc *p)
444 {
445 if (!p->fastMode)
446 {
447 @@ -2037,26 +1985,6 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEn
448 return SZ_OK;
449 }
450
451 -static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
452 - ISzAlloc *alloc, ISzAlloc *allocBig)
453 -{
454 - CLzmaEnc *p = (CLzmaEnc *)pp;
455 - p->matchFinderBase.stream = inStream;
456 - p->needInit = 1;
457 - p->rc.outStream = outStream;
458 - return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
459 -}
460 -
461 -SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
462 - ISeqInStream *inStream, UInt32 keepWindowSize,
463 - ISzAlloc *alloc, ISzAlloc *allocBig)
464 -{
465 - CLzmaEnc *p = (CLzmaEnc *)pp;
466 - p->matchFinderBase.stream = inStream;
467 - p->needInit = 1;
468 - return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
469 -}
470 -
471 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
472 {
473 p->matchFinderBase.directInput = 1;
474 @@ -2064,7 +1992,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc
475 p->matchFinderBase.directInputRem = srcLen;
476 }
477
478 -SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
479 +static SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
480 UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
481 {
482 CLzmaEnc *p = (CLzmaEnc *)pp;
483 @@ -2074,7 +2002,7 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle p
484 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
485 }
486
487 -void LzmaEnc_Finish(CLzmaEncHandle pp)
488 +static void LzmaEnc_Finish(CLzmaEncHandle pp)
489 {
490 #ifndef _7ZIP_ST
491 CLzmaEnc *p = (CLzmaEnc *)pp;
492 @@ -2107,53 +2035,6 @@ static size_t MyWrite(void *pp, const vo
493 return size;
494 }
495
496 -
497 -UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
498 -{
499 - const CLzmaEnc *p = (CLzmaEnc *)pp;
500 - return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
501 -}
502 -
503 -const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
504 -{
505 - const CLzmaEnc *p = (CLzmaEnc *)pp;
506 - return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
507 -}
508 -
509 -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
510 - Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
511 -{
512 - CLzmaEnc *p = (CLzmaEnc *)pp;
513 - UInt64 nowPos64;
514 - SRes res;
515 - CSeqOutStreamBuf outStream;
516 -
517 - outStream.funcTable.Write = MyWrite;
518 - outStream.data = dest;
519 - outStream.rem = *destLen;
520 - outStream.overflow = False;
521 -
522 - p->writeEndMark = False;
523 - p->finished = False;
524 - p->result = SZ_OK;
525 -
526 - if (reInit)
527 - LzmaEnc_Init(p);
528 - LzmaEnc_InitPrices(p);
529 - nowPos64 = p->nowPos64;
530 - RangeEnc_Init(&p->rc);
531 - p->rc.outStream = &outStream.funcTable;
532 -
533 - res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
534 -
535 - *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
536 - *destLen -= outStream.rem;
537 - if (outStream.overflow)
538 - return SZ_ERROR_OUTPUT_EOF;
539 -
540 - return res;
541 -}
542 -
543 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
544 {
545 SRes res = SZ_OK;
546 @@ -2184,13 +2065,6 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p,
547 return res;
548 }
549
550 -SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
551 - ISzAlloc *alloc, ISzAlloc *allocBig)
552 -{
553 - RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
554 - return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
555 -}
556 -
557 SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
558 {
559 CLzmaEnc *p = (CLzmaEnc *)pp;
560 @@ -2247,25 +2121,3 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp
561 return SZ_ERROR_OUTPUT_EOF;
562 return res;
563 }
564 -
565 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
566 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
567 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
568 -{
569 - CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
570 - SRes res;
571 - if (p == 0)
572 - return SZ_ERROR_MEM;
573 -
574 - res = LzmaEnc_SetProps(p, props);
575 - if (res == SZ_OK)
576 - {
577 - res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
578 - if (res == SZ_OK)
579 - res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
580 - writeEndMark, progress, alloc, allocBig);
581 - }
582 -
583 - LzmaEnc_Destroy(p, alloc, allocBig);
584 - return res;
585 -}
586 --- a/include/linux/lzma/LzFind.h
587 +++ b/include/linux/lzma/LzFind.h
588 @@ -55,11 +55,6 @@ typedef struct _CMatchFinder
589
590 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
591
592 -int MatchFinder_NeedMove(CMatchFinder *p);
593 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
594 -void MatchFinder_MoveBlock(CMatchFinder *p);
595 -void MatchFinder_ReadIfRequired(CMatchFinder *p);
596 -
597 void MatchFinder_Construct(CMatchFinder *p);
598
599 /* Conditions:
600 @@ -70,12 +65,6 @@ int MatchFinder_Create(CMatchFinder *p,
601 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
602 ISzAlloc *alloc);
603 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
604 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
605 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
606 -
607 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
608 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
609 - UInt32 *distances, UInt32 maxLen);
610
611 /*
612 Conditions:
613 @@ -102,12 +91,6 @@ typedef struct _IMatchFinder
614
615 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
616
617 -void MatchFinder_Init(CMatchFinder *p);
618 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
619 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
620 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
621 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
622 -
623 #ifdef __cplusplus
624 }
625 #endif
626 --- a/lib/lzma/LzFind.c
627 +++ b/lib/lzma/LzFind.c
628 @@ -14,9 +14,15 @@
629
630 #define kStartMaxLen 3
631
632 +#if 0
633 +#define DIRECT_INPUT p->directInput
634 +#else
635 +#define DIRECT_INPUT 1
636 +#endif
637 +
638 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
639 {
640 - if (!p->directInput)
641 + if (!DIRECT_INPUT)
642 {
643 alloc->Free(alloc, p->bufferBase);
644 p->bufferBase = 0;
645 @@ -28,7 +34,7 @@ static void LzInWindow_Free(CMatchFinder
646 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
647 {
648 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
649 - if (p->directInput)
650 + if (DIRECT_INPUT)
651 {
652 p->blockSize = blockSize;
653 return 1;
654 @@ -42,12 +48,12 @@ static int LzInWindow_Create(CMatchFinde
655 return (p->bufferBase != 0);
656 }
657
658 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
659 -Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
660 +static Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
661 +static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
662
663 -UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
664 +static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
665
666 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
667 +static void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
668 {
669 p->posLimit -= subValue;
670 p->pos -= subValue;
671 @@ -58,7 +64,7 @@ static void MatchFinder_ReadBlock(CMatch
672 {
673 if (p->streamEndWasReached || p->result != SZ_OK)
674 return;
675 - if (p->directInput)
676 + if (DIRECT_INPUT)
677 {
678 UInt32 curSize = 0xFFFFFFFF - p->streamPos;
679 if (curSize > p->directInputRem)
680 @@ -89,7 +95,7 @@ static void MatchFinder_ReadBlock(CMatch
681 }
682 }
683
684 -void MatchFinder_MoveBlock(CMatchFinder *p)
685 +static void MatchFinder_MoveBlock(CMatchFinder *p)
686 {
687 memmove(p->bufferBase,
688 p->buffer - p->keepSizeBefore,
689 @@ -97,22 +103,14 @@ void MatchFinder_MoveBlock(CMatchFinder
690 p->buffer = p->bufferBase + p->keepSizeBefore;
691 }
692
693 -int MatchFinder_NeedMove(CMatchFinder *p)
694 +static int MatchFinder_NeedMove(CMatchFinder *p)
695 {
696 - if (p->directInput)
697 + if (DIRECT_INPUT)
698 return 0;
699 /* if (p->streamEndWasReached) return 0; */
700 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
701 }
702
703 -void MatchFinder_ReadIfRequired(CMatchFinder *p)
704 -{
705 - if (p->streamEndWasReached)
706 - return;
707 - if (p->keepSizeAfter >= p->streamPos - p->pos)
708 - MatchFinder_ReadBlock(p);
709 -}
710 -
711 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
712 {
713 if (MatchFinder_NeedMove(p))
714 @@ -268,7 +266,7 @@ static void MatchFinder_SetLimits(CMatch
715 p->posLimit = p->pos + limit;
716 }
717
718 -void MatchFinder_Init(CMatchFinder *p)
719 +static void MatchFinder_Init(CMatchFinder *p)
720 {
721 UInt32 i;
722 for (i = 0; i < p->hashSizeSum; i++)
723 @@ -287,7 +285,7 @@ static UInt32 MatchFinder_GetSubValue(CM
724 return (p->pos - p->historySize - 1) & kNormalizeMask;
725 }
726
727 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
728 +static void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
729 {
730 UInt32 i;
731 for (i = 0; i < numItems; i++)
732 @@ -319,38 +317,7 @@ static void MatchFinder_CheckLimits(CMat
733 MatchFinder_SetLimits(p);
734 }
735
736 -static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
737 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
738 - UInt32 *distances, UInt32 maxLen)
739 -{
740 - son[_cyclicBufferPos] = curMatch;
741 - for (;;)
742 - {
743 - UInt32 delta = pos - curMatch;
744 - if (cutValue-- == 0 || delta >= _cyclicBufferSize)
745 - return distances;
746 - {
747 - const Byte *pb = cur - delta;
748 - curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
749 - if (pb[maxLen] == cur[maxLen] && *pb == *cur)
750 - {
751 - UInt32 len = 0;
752 - while (++len != lenLimit)
753 - if (pb[len] != cur[len])
754 - break;
755 - if (maxLen < len)
756 - {
757 - *distances++ = maxLen = len;
758 - *distances++ = delta - 1;
759 - if (len == lenLimit)
760 - return distances;
761 - }
762 - }
763 - }
764 - }
765 -}
766 -
767 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
768 +static UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
769 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
770 UInt32 *distances, UInt32 maxLen)
771 {
772 @@ -460,10 +427,10 @@ static void SkipMatchesSpec(UInt32 lenLi
773 p->buffer++; \
774 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
775
776 -#define MOVE_POS_RET MOVE_POS return offset;
777 -
778 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
779
780 +#define MOVE_POS_RET MatchFinder_MovePos(p); return offset;
781 +
782 #define GET_MATCHES_HEADER2(minLen, ret_op) \
783 UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
784 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
785 @@ -479,62 +446,7 @@ static void MatchFinder_MovePos(CMatchFi
786 distances + offset, maxLen) - distances); MOVE_POS_RET;
787
788 #define SKIP_FOOTER \
789 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
790 -
791 -static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
792 -{
793 - UInt32 offset;
794 - GET_MATCHES_HEADER(2)
795 - HASH2_CALC;
796 - curMatch = p->hash[hashValue];
797 - p->hash[hashValue] = p->pos;
798 - offset = 0;
799 - GET_MATCHES_FOOTER(offset, 1)
800 -}
801 -
802 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
803 -{
804 - UInt32 offset;
805 - GET_MATCHES_HEADER(3)
806 - HASH_ZIP_CALC;
807 - curMatch = p->hash[hashValue];
808 - p->hash[hashValue] = p->pos;
809 - offset = 0;
810 - GET_MATCHES_FOOTER(offset, 2)
811 -}
812 -
813 -static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
814 -{
815 - UInt32 hash2Value, delta2, maxLen, offset;
816 - GET_MATCHES_HEADER(3)
817 -
818 - HASH3_CALC;
819 -
820 - delta2 = p->pos - p->hash[hash2Value];
821 - curMatch = p->hash[kFix3HashSize + hashValue];
822 -
823 - p->hash[hash2Value] =
824 - p->hash[kFix3HashSize + hashValue] = p->pos;
825 -
826 -
827 - maxLen = 2;
828 - offset = 0;
829 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
830 - {
831 - for (; maxLen != lenLimit; maxLen++)
832 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
833 - break;
834 - distances[0] = maxLen;
835 - distances[1] = delta2 - 1;
836 - offset = 2;
837 - if (maxLen == lenLimit)
838 - {
839 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
840 - MOVE_POS_RET;
841 - }
842 - }
843 - GET_MATCHES_FOOTER(offset, maxLen)
844 -}
845 + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MatchFinder_MovePos(p);
846
847 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
848 {
849 @@ -583,108 +495,6 @@ static UInt32 Bt4_MatchFinder_GetMatches
850 GET_MATCHES_FOOTER(offset, maxLen)
851 }
852
853 -static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
854 -{
855 - UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
856 - GET_MATCHES_HEADER(4)
857 -
858 - HASH4_CALC;
859 -
860 - delta2 = p->pos - p->hash[ hash2Value];
861 - delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
862 - curMatch = p->hash[kFix4HashSize + hashValue];
863 -
864 - p->hash[ hash2Value] =
865 - p->hash[kFix3HashSize + hash3Value] =
866 - p->hash[kFix4HashSize + hashValue] = p->pos;
867 -
868 - maxLen = 1;
869 - offset = 0;
870 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
871 - {
872 - distances[0] = maxLen = 2;
873 - distances[1] = delta2 - 1;
874 - offset = 2;
875 - }
876 - if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
877 - {
878 - maxLen = 3;
879 - distances[offset + 1] = delta3 - 1;
880 - offset += 2;
881 - delta2 = delta3;
882 - }
883 - if (offset != 0)
884 - {
885 - for (; maxLen != lenLimit; maxLen++)
886 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
887 - break;
888 - distances[offset - 2] = maxLen;
889 - if (maxLen == lenLimit)
890 - {
891 - p->son[p->cyclicBufferPos] = curMatch;
892 - MOVE_POS_RET;
893 - }
894 - }
895 - if (maxLen < 3)
896 - maxLen = 3;
897 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
898 - distances + offset, maxLen) - (distances));
899 - MOVE_POS_RET
900 -}
901 -
902 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
903 -{
904 - UInt32 offset;
905 - GET_MATCHES_HEADER(3)
906 - HASH_ZIP_CALC;
907 - curMatch = p->hash[hashValue];
908 - p->hash[hashValue] = p->pos;
909 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
910 - distances, 2) - (distances));
911 - MOVE_POS_RET
912 -}
913 -
914 -static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
915 -{
916 - do
917 - {
918 - SKIP_HEADER(2)
919 - HASH2_CALC;
920 - curMatch = p->hash[hashValue];
921 - p->hash[hashValue] = p->pos;
922 - SKIP_FOOTER
923 - }
924 - while (--num != 0);
925 -}
926 -
927 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
928 -{
929 - do
930 - {
931 - SKIP_HEADER(3)
932 - HASH_ZIP_CALC;
933 - curMatch = p->hash[hashValue];
934 - p->hash[hashValue] = p->pos;
935 - SKIP_FOOTER
936 - }
937 - while (--num != 0);
938 -}
939 -
940 -static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
941 -{
942 - do
943 - {
944 - UInt32 hash2Value;
945 - SKIP_HEADER(3)
946 - HASH3_CALC;
947 - curMatch = p->hash[kFix3HashSize + hashValue];
948 - p->hash[hash2Value] =
949 - p->hash[kFix3HashSize + hashValue] = p->pos;
950 - SKIP_FOOTER
951 - }
952 - while (--num != 0);
953 -}
954 -
955 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
956 {
957 do
958 @@ -701,61 +511,12 @@ static void Bt4_MatchFinder_Skip(CMatchF
959 while (--num != 0);
960 }
961
962 -static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
963 -{
964 - do
965 - {
966 - UInt32 hash2Value, hash3Value;
967 - SKIP_HEADER(4)
968 - HASH4_CALC;
969 - curMatch = p->hash[kFix4HashSize + hashValue];
970 - p->hash[ hash2Value] =
971 - p->hash[kFix3HashSize + hash3Value] =
972 - p->hash[kFix4HashSize + hashValue] = p->pos;
973 - p->son[p->cyclicBufferPos] = curMatch;
974 - MOVE_POS
975 - }
976 - while (--num != 0);
977 -}
978 -
979 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
980 -{
981 - do
982 - {
983 - SKIP_HEADER(3)
984 - HASH_ZIP_CALC;
985 - curMatch = p->hash[hashValue];
986 - p->hash[hashValue] = p->pos;
987 - p->son[p->cyclicBufferPos] = curMatch;
988 - MOVE_POS
989 - }
990 - while (--num != 0);
991 -}
992 -
993 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
994 {
995 vTable->Init = (Mf_Init_Func)MatchFinder_Init;
996 vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
997 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
998 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
999 - if (!p->btMode)
1000 - {
1001 - vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
1002 - vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
1003 - }
1004 - else if (p->numHashBytes == 2)
1005 - {
1006 - vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
1007 - vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
1008 - }
1009 - else if (p->numHashBytes == 3)
1010 - {
1011 - vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
1012 - vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
1013 - }
1014 - else
1015 - {
1016 - vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1017 - vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
1018 - }
1019 + vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1020 + vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
1021 }