1 --- a/include/linux/lzma/LzmaDec.h
2 +++ b/include/linux/lzma/LzmaDec.h
3 @@ -31,14 +31,6 @@ typedef struct _CLzmaProps
7 -/* LzmaProps_Decode - decodes properties
10 - SZ_ERROR_UNSUPPORTED - Unsupported properties
13 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
16 /* ---------- LZMA Decoder state ---------- */
18 @@ -70,8 +62,6 @@ typedef struct
20 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
22 -void LzmaDec_Init(CLzmaDec *p);
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
29 /* ELzmaStatus is used only as output value for function call */
32 -/* ---------- Interfaces ---------- */
34 -/* There are 3 levels of interfaces:
35 - 1) Dictionary 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. */
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.
48 -LzmaDec_Allocate* can return:
50 - SZ_ERROR_MEM - Memory allocation error
51 - SZ_ERROR_UNSUPPORTED - Unsupported properties
54 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
55 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
57 -SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
58 -void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
60 -/* ---------- Dictionary Interface ---------- */
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.
69 - for (each new stream)
72 - while (it needs more decompression)
74 - LzmaDec_DecodeToDic()
75 - use data from CLzmaDec::dic and update CLzmaDec::dicPos
81 -/* LzmaDec_DecodeToDic
83 - The decoding to internal dictionary buffer (CLzmaDec::dic).
84 - You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
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.
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
101 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
102 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
105 -/* ---------- Buffer Interface ---------- */
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.
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).
118 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
119 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
122 /* ---------- One Call Interface ---------- */
125 --- a/lib/lzma/LzmaDec.c
126 +++ b/lib/lzma/LzmaDec.c
127 @@ -682,7 +682,7 @@ static void LzmaDec_InitRc(CLzmaDec *p,
131 -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
132 +static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
136 @@ -698,7 +698,7 @@ void LzmaDec_InitDicAndState(CLzmaDec *p
137 p->needInitState = 1;
140 -void LzmaDec_Init(CLzmaDec *p)
141 +static void LzmaDec_Init(CLzmaDec *p)
144 LzmaDec_InitDicAndState(p, True, True);
145 @@ -716,7 +716,7 @@ static void LzmaDec_InitStateReal(CLzmaD
146 p->needInitState = 0;
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)
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;
158 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
160 - SizeT outSize = *destLen;
161 - SizeT inSize = *srcLen;
162 - *srcLen = *destLen = 0;
165 - SizeT inSizeCur = inSize, outSizeCur, dicPos;
166 - ELzmaFinishMode curFinishMode;
168 - if (p->dicPos == p->dicBufSize)
170 - dicPos = p->dicPos;
171 - if (outSize > p->dicBufSize - dicPos)
173 - outSizeCur = p->dicBufSize;
174 - curFinishMode = LZMA_FINISH_ANY;
178 - outSizeCur = dicPos + outSize;
179 - curFinishMode = finishMode;
182 - res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
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;
193 - if (outSizeCur == 0 || outSize == 0)
198 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
199 +static void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
201 alloc->Free(alloc, p->probs);
205 -static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
207 - alloc->Free(alloc, p->dic);
211 -void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
213 - LzmaDec_FreeProbs(p, alloc);
214 - LzmaDec_FreeDict(p, alloc);
217 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
218 +static SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
222 @@ -935,7 +883,7 @@ static SRes LzmaDec_AllocateProbs2(CLzma
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)
230 RINOK(LzmaProps_Decode(&propNew, props, propsSize));
231 @@ -943,28 +891,6 @@ SRes LzmaDec_AllocateProbs(CLzmaDec *p,
236 -SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
238 - CLzmaProps propNew;
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)
245 - LzmaDec_FreeDict(p, alloc);
246 - p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
249 - LzmaDec_FreeProbs(p, alloc);
250 - return SZ_ERROR_MEM;
253 - p->dicBufSize = dicBufSize;
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
265 void LzmaEncProps_Init(CLzmaEncProps *p);
266 -void LzmaEncProps_Normalize(CLzmaEncProps *p);
267 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
270 /* ---------- CLzmaEncHandle Interface ---------- */
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);
281 -/* ---------- One Call Interface ---------- */
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)
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);
299 --- a/lib/lzma/LzmaEnc.c
300 +++ b/lib/lzma/LzmaEnc.c
301 @@ -53,7 +53,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
305 -void LzmaEncProps_Normalize(CLzmaEncProps *p)
306 +static void LzmaEncProps_Normalize(CLzmaEncProps *p)
308 int level = p->level;
309 if (level < 0) level = 5;
310 @@ -76,7 +76,7 @@ void LzmaEncProps_Normalize(CLzmaEncProp
314 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
315 +static UInt32 __maybe_unused LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
317 CLzmaEncProps props = *props2;
318 LzmaEncProps_Normalize(&props);
319 @@ -93,7 +93,7 @@ UInt32 LzmaEncProps_GetDictSize(const CL
321 #define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
323 -UInt32 GetPosSlot1(UInt32 pos)
324 +static UInt32 GetPosSlot1(UInt32 pos)
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)
332 -void LzmaEnc_FastPosInit(Byte *g_FastPos)
333 +static void LzmaEnc_FastPosInit(Byte *g_FastPos)
337 @@ -339,58 +339,6 @@ typedef struct
338 CSaveState saveState;
341 -void LzmaEnc_SaveState(CLzmaEncHandle pp)
343 - CLzmaEnc *p = (CLzmaEnc *)pp;
344 - CSaveState *dest = &p->saveState;
346 - dest->lenEnc = p->lenEnc;
347 - dest->repLenEnc = p->repLenEnc;
348 - dest->state = p->state;
350 - for (i = 0; i < kNumStates; i++)
352 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
353 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
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));
367 -void LzmaEnc_RestoreState(CLzmaEncHandle pp)
369 - CLzmaEnc *dest = (CLzmaEnc *)pp;
370 - const CSaveState *p = &dest->saveState;
372 - dest->lenEnc = p->lenEnc;
373 - dest->repLenEnc = p->repLenEnc;
374 - dest->state = p->state;
376 - for (i = 0; i < kNumStates; i++)
378 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
379 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
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));
393 SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
395 CLzmaEnc *p = (CLzmaEnc *)pp;
396 @@ -600,7 +548,7 @@ static void LitEnc_EncodeMatched(CRangeE
397 while (symbol < 0x10000);
400 -void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
401 +static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
404 for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
405 @@ -1676,7 +1624,7 @@ static void FillDistancesPrices(CLzmaEnc
406 p->matchPriceCount = 0;
409 -void LzmaEnc_Construct(CLzmaEnc *p)
410 +static void LzmaEnc_Construct(CLzmaEnc *p)
412 RangeEnc_Construct(&p->rc);
413 MatchFinder_Construct(&p->matchFinderBase);
414 @@ -1709,7 +1657,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *
418 -void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
419 +static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
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;
427 -void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
428 +static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
431 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
432 @@ -1947,7 +1895,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, U
436 -void LzmaEnc_Init(CLzmaEnc *p)
437 +static void LzmaEnc_Init(CLzmaEnc *p)
441 @@ -2005,7 +1953,7 @@ void LzmaEnc_Init(CLzmaEnc *p)
442 p->lpMask = (1 << p->lp) - 1;
445 -void LzmaEnc_InitPrices(CLzmaEnc *p)
446 +static void LzmaEnc_InitPrices(CLzmaEnc *p)
450 @@ -2037,26 +1985,6 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEn
454 -static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
455 - ISzAlloc *alloc, ISzAlloc *allocBig)
457 - CLzmaEnc *p = (CLzmaEnc *)pp;
458 - p->matchFinderBase.stream = inStream;
460 - p->rc.outStream = outStream;
461 - return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
464 -SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
465 - ISeqInStream *inStream, UInt32 keepWindowSize,
466 - ISzAlloc *alloc, ISzAlloc *allocBig)
468 - CLzmaEnc *p = (CLzmaEnc *)pp;
469 - p->matchFinderBase.stream = inStream;
471 - return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
474 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
476 p->matchFinderBase.directInput = 1;
477 @@ -2064,7 +1992,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc
478 p->matchFinderBase.directInputRem = srcLen;
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)
485 CLzmaEnc *p = (CLzmaEnc *)pp;
486 @@ -2074,7 +2002,7 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle p
487 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
490 -void LzmaEnc_Finish(CLzmaEncHandle pp)
491 +static void LzmaEnc_Finish(CLzmaEncHandle pp)
494 CLzmaEnc *p = (CLzmaEnc *)pp;
495 @@ -2107,53 +2035,6 @@ static size_t MyWrite(void *pp, const vo
500 -UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
502 - const CLzmaEnc *p = (CLzmaEnc *)pp;
503 - return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
506 -const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
508 - const CLzmaEnc *p = (CLzmaEnc *)pp;
509 - return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
512 -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
513 - Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
515 - CLzmaEnc *p = (CLzmaEnc *)pp;
518 - CSeqOutStreamBuf outStream;
520 - outStream.funcTable.Write = MyWrite;
521 - outStream.data = dest;
522 - outStream.rem = *destLen;
523 - outStream.overflow = False;
525 - p->writeEndMark = False;
526 - p->finished = False;
531 - LzmaEnc_InitPrices(p);
532 - nowPos64 = p->nowPos64;
533 - RangeEnc_Init(&p->rc);
534 - p->rc.outStream = &outStream.funcTable;
536 - res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
538 - *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
539 - *destLen -= outStream.rem;
540 - if (outStream.overflow)
541 - return SZ_ERROR_OUTPUT_EOF;
546 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
549 @@ -2184,13 +2065,6 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p,
553 -SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
554 - ISzAlloc *alloc, ISzAlloc *allocBig)
556 - RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
557 - return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
560 SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
562 CLzmaEnc *p = (CLzmaEnc *)pp;
563 @@ -2247,25 +2121,3 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp
564 return SZ_ERROR_OUTPUT_EOF;
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)
572 - CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
575 - return SZ_ERROR_MEM;
577 - res = LzmaEnc_SetProps(p, props);
580 - res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
582 - res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
583 - writeEndMark, progress, alloc, allocBig);
586 - LzmaEnc_Destroy(p, alloc, allocBig);
589 --- a/include/linux/lzma/LzFind.h
590 +++ b/include/linux/lzma/LzFind.h
591 @@ -55,11 +55,6 @@ typedef struct _CMatchFinder
593 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
595 -int MatchFinder_NeedMove(CMatchFinder *p);
596 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
597 -void MatchFinder_MoveBlock(CMatchFinder *p);
598 -void MatchFinder_ReadIfRequired(CMatchFinder *p);
600 void MatchFinder_Construct(CMatchFinder *p);
603 @@ -70,12 +65,6 @@ int MatchFinder_Create(CMatchFinder *p,
604 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
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);
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);
616 @@ -102,12 +91,6 @@ typedef struct _IMatchFinder
618 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
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);
629 --- a/lib/lzma/LzFind.c
630 +++ b/lib/lzma/LzFind.c
633 #define kStartMaxLen 3
636 +#define DIRECT_INPUT p->directInput
638 +#define DIRECT_INPUT 1
641 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
643 - if (!p->directInput)
646 alloc->Free(alloc, p->bufferBase);
648 @@ -28,7 +34,7 @@ static void LzInWindow_Free(CMatchFinder
649 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
651 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
652 - if (p->directInput)
655 p->blockSize = blockSize;
657 @@ -42,12 +48,12 @@ static int LzInWindow_Create(CMatchFinde
658 return (p->bufferBase != 0);
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]; }
666 -UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
667 +static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
669 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
670 +static void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
672 p->posLimit -= subValue;
674 @@ -58,7 +64,7 @@ static void MatchFinder_ReadBlock(CMatch
676 if (p->streamEndWasReached || p->result != SZ_OK)
678 - if (p->directInput)
681 UInt32 curSize = 0xFFFFFFFF - p->streamPos;
682 if (curSize > p->directInputRem)
683 @@ -89,7 +95,7 @@ static void MatchFinder_ReadBlock(CMatch
687 -void MatchFinder_MoveBlock(CMatchFinder *p)
688 +static void MatchFinder_MoveBlock(CMatchFinder *p)
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;
696 -int MatchFinder_NeedMove(CMatchFinder *p)
697 +static int MatchFinder_NeedMove(CMatchFinder *p)
699 - if (p->directInput)
702 /* if (p->streamEndWasReached) return 0; */
703 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
706 -void MatchFinder_ReadIfRequired(CMatchFinder *p)
708 - if (p->streamEndWasReached)
710 - if (p->keepSizeAfter >= p->streamPos - p->pos)
711 - MatchFinder_ReadBlock(p);
714 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
716 if (MatchFinder_NeedMove(p))
717 @@ -268,7 +266,7 @@ static void MatchFinder_SetLimits(CMatch
718 p->posLimit = p->pos + limit;
721 -void MatchFinder_Init(CMatchFinder *p)
722 +static void MatchFinder_Init(CMatchFinder *p)
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;
730 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
731 +static void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
734 for (i = 0; i < numItems; i++)
735 @@ -319,38 +317,7 @@ static void MatchFinder_CheckLimits(CMat
736 MatchFinder_SetLimits(p);
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)
743 - son[_cyclicBufferPos] = curMatch;
746 - UInt32 delta = pos - curMatch;
747 - if (cutValue-- == 0 || delta >= _cyclicBufferSize)
750 - const Byte *pb = cur - delta;
751 - curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
752 - if (pb[maxLen] == cur[maxLen] && *pb == *cur)
755 - while (++len != lenLimit)
756 - if (pb[len] != cur[len])
760 - *distances++ = maxLen = len;
761 - *distances++ = delta - 1;
762 - if (len == lenLimit)
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)
775 @@ -460,10 +427,10 @@ static void SkipMatchesSpec(UInt32 lenLi
777 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
779 -#define MOVE_POS_RET MOVE_POS return offset;
781 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
783 +#define MOVE_POS_RET MatchFinder_MovePos(p); return offset;
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;
791 #define SKIP_FOOTER \
792 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
794 -static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
797 - GET_MATCHES_HEADER(2)
799 - curMatch = p->hash[hashValue];
800 - p->hash[hashValue] = p->pos;
802 - GET_MATCHES_FOOTER(offset, 1)
805 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
808 - GET_MATCHES_HEADER(3)
810 - curMatch = p->hash[hashValue];
811 - p->hash[hashValue] = p->pos;
813 - GET_MATCHES_FOOTER(offset, 2)
816 -static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
818 - UInt32 hash2Value, delta2, maxLen, offset;
819 - GET_MATCHES_HEADER(3)
823 - delta2 = p->pos - p->hash[hash2Value];
824 - curMatch = p->hash[kFix3HashSize + hashValue];
826 - p->hash[hash2Value] =
827 - p->hash[kFix3HashSize + hashValue] = p->pos;
832 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
834 - for (; maxLen != lenLimit; maxLen++)
835 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
837 - distances[0] = maxLen;
838 - distances[1] = delta2 - 1;
840 - if (maxLen == lenLimit)
842 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
846 - GET_MATCHES_FOOTER(offset, maxLen)
848 + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MatchFinder_MovePos(p);
850 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
852 @@ -583,108 +495,6 @@ static UInt32 Bt4_MatchFinder_GetMatches
853 GET_MATCHES_FOOTER(offset, maxLen)
856 -static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
858 - UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
859 - GET_MATCHES_HEADER(4)
863 - delta2 = p->pos - p->hash[ hash2Value];
864 - delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
865 - curMatch = p->hash[kFix4HashSize + hashValue];
867 - p->hash[ hash2Value] =
868 - p->hash[kFix3HashSize + hash3Value] =
869 - p->hash[kFix4HashSize + hashValue] = p->pos;
873 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
875 - distances[0] = maxLen = 2;
876 - distances[1] = delta2 - 1;
879 - if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
882 - distances[offset + 1] = delta3 - 1;
888 - for (; maxLen != lenLimit; maxLen++)
889 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
891 - distances[offset - 2] = maxLen;
892 - if (maxLen == lenLimit)
894 - p->son[p->cyclicBufferPos] = curMatch;
900 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
901 - distances + offset, maxLen) - (distances));
905 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
908 - GET_MATCHES_HEADER(3)
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));
917 -static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
923 - curMatch = p->hash[hashValue];
924 - p->hash[hashValue] = p->pos;
927 - while (--num != 0);
930 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
936 - curMatch = p->hash[hashValue];
937 - p->hash[hashValue] = p->pos;
940 - while (--num != 0);
943 -static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
950 - curMatch = p->hash[kFix3HashSize + hashValue];
951 - p->hash[hash2Value] =
952 - p->hash[kFix3HashSize + hashValue] = p->pos;
955 - while (--num != 0);
958 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
961 @@ -701,61 +511,12 @@ static void Bt4_MatchFinder_Skip(CMatchF
965 -static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
969 - UInt32 hash2Value, hash3Value;
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;
979 - while (--num != 0);
982 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
988 - curMatch = p->hash[hashValue];
989 - p->hash[hashValue] = p->pos;
990 - p->son[p->cyclicBufferPos] = curMatch;
993 - while (--num != 0);
996 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
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;
1004 - vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
1005 - vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
1007 - else if (p->numHashBytes == 2)
1009 - vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
1010 - vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
1012 - else if (p->numHashBytes == 3)
1014 - vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
1015 - vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
1019 - vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1020 - vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
1022 + vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
1023 + vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;