1 From 3fd297761ac246c54d7723c57fca95c112b99465 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Sat, 15 Jul 2017 21:15:44 +0200
4 Subject: lzma: de-bloat the lzma library used by jffs2
6 lede-commit: 3fd1dd08fbcbb78b34efefd32c3032e5c99108d6
7 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 include/linux/lzma/LzFind.h | 17 ---
10 include/linux/lzma/LzmaDec.h | 101 ---------------
11 include/linux/lzma/LzmaEnc.h | 20 ---
12 lib/lzma/LzFind.c | 287 ++++---------------------------------------
13 lib/lzma/LzmaDec.c | 86 +------------
14 lib/lzma/LzmaEnc.c | 172 ++------------------------
15 6 files changed, 42 insertions(+), 641 deletions(-)
17 diff --git a/include/linux/lzma/LzFind.h b/include/linux/lzma/LzFind.h
18 index 010c4b92ba33..6d4f8e239028 100644
19 --- a/include/linux/lzma/LzFind.h
20 +++ b/include/linux/lzma/LzFind.h
21 @@ -55,11 +55,6 @@ typedef struct _CMatchFinder
23 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
25 -int MatchFinder_NeedMove(CMatchFinder *p);
26 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
27 -void MatchFinder_MoveBlock(CMatchFinder *p);
28 -void MatchFinder_ReadIfRequired(CMatchFinder *p);
30 void MatchFinder_Construct(CMatchFinder *p);
33 @@ -70,12 +65,6 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
34 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
36 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
37 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
38 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
40 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
41 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
42 - UInt32 *distances, UInt32 maxLen);
46 @@ -102,12 +91,6 @@ typedef struct _IMatchFinder
48 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
50 -void MatchFinder_Init(CMatchFinder *p);
51 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
52 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
53 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
54 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
59 diff --git a/include/linux/lzma/LzmaDec.h b/include/linux/lzma/LzmaDec.h
60 index bf7f084ba3dd..c90f95e9fbaf 100644
61 --- a/include/linux/lzma/LzmaDec.h
62 +++ b/include/linux/lzma/LzmaDec.h
63 @@ -31,14 +31,6 @@ typedef struct _CLzmaProps
67 -/* LzmaProps_Decode - decodes properties
70 - SZ_ERROR_UNSUPPORTED - Unsupported properties
73 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
76 /* ---------- LZMA Decoder state ---------- */
78 @@ -70,8 +62,6 @@ typedef struct
80 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
82 -void LzmaDec_Init(CLzmaDec *p);
84 /* There are two types of LZMA streams:
85 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
86 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
87 @@ -108,97 +98,6 @@ typedef enum
89 /* ELzmaStatus is used only as output value for function call */
92 -/* ---------- Interfaces ---------- */
94 -/* There are 3 levels of interfaces:
95 - 1) Dictionary Interface
97 - 3) One Call Interface
98 - You can select any of these interfaces, but don't mix functions from different
99 - groups for same object. */
102 -/* There are two variants to allocate state for Dictionary Interface:
103 - 1) LzmaDec_Allocate / LzmaDec_Free
104 - 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
105 - You can use variant 2, if you set dictionary buffer manually.
106 - For Buffer Interface you must always use variant 1.
108 -LzmaDec_Allocate* can return:
110 - SZ_ERROR_MEM - Memory allocation error
111 - SZ_ERROR_UNSUPPORTED - Unsupported properties
114 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
115 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
117 -SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
118 -void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
120 -/* ---------- Dictionary Interface ---------- */
122 -/* You can use it, if you want to eliminate the overhead for data copying from
123 - dictionary to some other external buffer.
124 - You must work with CLzmaDec variables directly in this interface.
129 - for (each new stream)
132 - while (it needs more decompression)
134 - LzmaDec_DecodeToDic()
135 - use data from CLzmaDec::dic and update CLzmaDec::dicPos
141 -/* LzmaDec_DecodeToDic
143 - The decoding to internal dictionary buffer (CLzmaDec::dic).
144 - You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
147 - It has meaning only if the decoding reaches output limit (dicLimit).
148 - LZMA_FINISH_ANY - Decode just dicLimit bytes.
149 - LZMA_FINISH_END - Stream must be finished after dicLimit.
154 - LZMA_STATUS_FINISHED_WITH_MARK
155 - LZMA_STATUS_NOT_FINISHED
156 - LZMA_STATUS_NEEDS_MORE_INPUT
157 - LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
158 - SZ_ERROR_DATA - Data error
161 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
162 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
165 -/* ---------- Buffer Interface ---------- */
167 -/* It's zlib-like interface.
168 - See LzmaDec_DecodeToDic description for information about STEPS and return results,
169 - but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
170 - to work with CLzmaDec variables manually.
173 - It has meaning only if the decoding reaches output limit (*destLen).
174 - LZMA_FINISH_ANY - Decode just destLen bytes.
175 - LZMA_FINISH_END - Stream must be finished after (*destLen).
178 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
179 - const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
182 /* ---------- One Call Interface ---------- */
185 diff --git a/include/linux/lzma/LzmaEnc.h b/include/linux/lzma/LzmaEnc.h
186 index 200d60eb83cd..2986c0460be4 100644
187 --- a/include/linux/lzma/LzmaEnc.h
188 +++ b/include/linux/lzma/LzmaEnc.h
189 @@ -31,9 +31,6 @@ typedef struct _CLzmaEncProps
192 void LzmaEncProps_Init(CLzmaEncProps *p);
193 -void LzmaEncProps_Normalize(CLzmaEncProps *p);
194 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
197 /* ---------- CLzmaEncHandle Interface ---------- */
199 @@ -53,26 +50,9 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
200 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
201 SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
202 SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
203 -SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
204 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
205 SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
206 int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
208 -/* ---------- One Call Interface ---------- */
213 - SZ_ERROR_MEM - Memory allocation error
214 - SZ_ERROR_PARAM - Incorrect paramater
215 - SZ_ERROR_OUTPUT_EOF - output buffer overflow
216 - SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
219 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
220 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
221 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
226 diff --git a/lib/lzma/LzFind.c b/lib/lzma/LzFind.c
227 index e3ecb05420eb..86251ccedfda 100644
228 --- a/lib/lzma/LzFind.c
229 +++ b/lib/lzma/LzFind.c
232 #define kStartMaxLen 3
235 +#define DIRECT_INPUT p->directInput
237 +#define DIRECT_INPUT 1
240 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
242 - if (!p->directInput)
245 alloc->Free(alloc, p->bufferBase);
247 @@ -28,7 +34,7 @@ static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
248 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
250 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
251 - if (p->directInput)
254 p->blockSize = blockSize;
256 @@ -42,12 +48,12 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
257 return (p->bufferBase != 0);
260 -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
261 -Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
262 +static Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
263 +static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
265 -UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
266 +static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
268 -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
269 +static void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
271 p->posLimit -= subValue;
273 @@ -58,7 +64,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
275 if (p->streamEndWasReached || p->result != SZ_OK)
277 - if (p->directInput)
280 UInt32 curSize = 0xFFFFFFFF - p->streamPos;
281 if (curSize > p->directInputRem)
282 @@ -89,7 +95,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
286 -void MatchFinder_MoveBlock(CMatchFinder *p)
287 +static void MatchFinder_MoveBlock(CMatchFinder *p)
289 memmove(p->bufferBase,
290 p->buffer - p->keepSizeBefore,
291 @@ -97,22 +103,14 @@ void MatchFinder_MoveBlock(CMatchFinder *p)
292 p->buffer = p->bufferBase + p->keepSizeBefore;
295 -int MatchFinder_NeedMove(CMatchFinder *p)
296 +static int MatchFinder_NeedMove(CMatchFinder *p)
298 - if (p->directInput)
301 /* if (p->streamEndWasReached) return 0; */
302 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
305 -void MatchFinder_ReadIfRequired(CMatchFinder *p)
307 - if (p->streamEndWasReached)
309 - if (p->keepSizeAfter >= p->streamPos - p->pos)
310 - MatchFinder_ReadBlock(p);
313 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
315 if (MatchFinder_NeedMove(p))
316 @@ -268,7 +266,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
317 p->posLimit = p->pos + limit;
320 -void MatchFinder_Init(CMatchFinder *p)
321 +static void MatchFinder_Init(CMatchFinder *p)
324 for (i = 0; i < p->hashSizeSum; i++)
325 @@ -287,7 +285,7 @@ static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
326 return (p->pos - p->historySize - 1) & kNormalizeMask;
329 -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
330 +static void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
333 for (i = 0; i < numItems; i++)
334 @@ -319,38 +317,7 @@ static void MatchFinder_CheckLimits(CMatchFinder *p)
335 MatchFinder_SetLimits(p);
338 -static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
339 - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
340 - UInt32 *distances, UInt32 maxLen)
342 - son[_cyclicBufferPos] = curMatch;
345 - UInt32 delta = pos - curMatch;
346 - if (cutValue-- == 0 || delta >= _cyclicBufferSize)
349 - const Byte *pb = cur - delta;
350 - curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
351 - if (pb[maxLen] == cur[maxLen] && *pb == *cur)
354 - while (++len != lenLimit)
355 - if (pb[len] != cur[len])
359 - *distances++ = maxLen = len;
360 - *distances++ = delta - 1;
361 - if (len == lenLimit)
369 -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
370 +static UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
371 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
372 UInt32 *distances, UInt32 maxLen)
374 @@ -460,10 +427,10 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
376 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
378 -#define MOVE_POS_RET MOVE_POS return offset;
380 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
382 +#define MOVE_POS_RET MatchFinder_MovePos(p); return offset;
384 #define GET_MATCHES_HEADER2(minLen, ret_op) \
385 UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
386 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
387 @@ -479,62 +446,7 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
388 distances + offset, maxLen) - distances); MOVE_POS_RET;
390 #define SKIP_FOOTER \
391 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
393 -static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
396 - GET_MATCHES_HEADER(2)
398 - curMatch = p->hash[hashValue];
399 - p->hash[hashValue] = p->pos;
401 - GET_MATCHES_FOOTER(offset, 1)
404 -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
407 - GET_MATCHES_HEADER(3)
409 - curMatch = p->hash[hashValue];
410 - p->hash[hashValue] = p->pos;
412 - GET_MATCHES_FOOTER(offset, 2)
415 -static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
417 - UInt32 hash2Value, delta2, maxLen, offset;
418 - GET_MATCHES_HEADER(3)
422 - delta2 = p->pos - p->hash[hash2Value];
423 - curMatch = p->hash[kFix3HashSize + hashValue];
425 - p->hash[hash2Value] =
426 - p->hash[kFix3HashSize + hashValue] = p->pos;
431 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
433 - for (; maxLen != lenLimit; maxLen++)
434 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
436 - distances[0] = maxLen;
437 - distances[1] = delta2 - 1;
439 - if (maxLen == lenLimit)
441 - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
445 - GET_MATCHES_FOOTER(offset, maxLen)
447 + SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MatchFinder_MovePos(p);
449 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
451 @@ -583,108 +495,6 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
452 GET_MATCHES_FOOTER(offset, maxLen)
455 -static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
457 - UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
458 - GET_MATCHES_HEADER(4)
462 - delta2 = p->pos - p->hash[ hash2Value];
463 - delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
464 - curMatch = p->hash[kFix4HashSize + hashValue];
466 - p->hash[ hash2Value] =
467 - p->hash[kFix3HashSize + hash3Value] =
468 - p->hash[kFix4HashSize + hashValue] = p->pos;
472 - if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
474 - distances[0] = maxLen = 2;
475 - distances[1] = delta2 - 1;
478 - if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
481 - distances[offset + 1] = delta3 - 1;
487 - for (; maxLen != lenLimit; maxLen++)
488 - if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
490 - distances[offset - 2] = maxLen;
491 - if (maxLen == lenLimit)
493 - p->son[p->cyclicBufferPos] = curMatch;
499 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
500 - distances + offset, maxLen) - (distances));
504 -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
507 - GET_MATCHES_HEADER(3)
509 - curMatch = p->hash[hashValue];
510 - p->hash[hashValue] = p->pos;
511 - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
512 - distances, 2) - (distances));
516 -static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
522 - curMatch = p->hash[hashValue];
523 - p->hash[hashValue] = p->pos;
526 - while (--num != 0);
529 -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
535 - curMatch = p->hash[hashValue];
536 - p->hash[hashValue] = p->pos;
539 - while (--num != 0);
542 -static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
549 - curMatch = p->hash[kFix3HashSize + hashValue];
550 - p->hash[hash2Value] =
551 - p->hash[kFix3HashSize + hashValue] = p->pos;
554 - while (--num != 0);
557 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
560 @@ -701,61 +511,12 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
564 -static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
568 - UInt32 hash2Value, hash3Value;
571 - curMatch = p->hash[kFix4HashSize + hashValue];
572 - p->hash[ hash2Value] =
573 - p->hash[kFix3HashSize + hash3Value] =
574 - p->hash[kFix4HashSize + hashValue] = p->pos;
575 - p->son[p->cyclicBufferPos] = curMatch;
578 - while (--num != 0);
581 -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
587 - curMatch = p->hash[hashValue];
588 - p->hash[hashValue] = p->pos;
589 - p->son[p->cyclicBufferPos] = curMatch;
592 - while (--num != 0);
595 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
597 vTable->Init = (Mf_Init_Func)MatchFinder_Init;
598 vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
599 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
600 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
603 - vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
604 - vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
606 - else if (p->numHashBytes == 2)
608 - vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
609 - vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
611 - else if (p->numHashBytes == 3)
613 - vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
614 - vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
618 - vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
619 - vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
621 + vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
622 + vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
624 diff --git a/lib/lzma/LzmaDec.c b/lib/lzma/LzmaDec.c
625 index 2036761bf146..7666e3f82067 100644
626 --- a/lib/lzma/LzmaDec.c
627 +++ b/lib/lzma/LzmaDec.c
628 @@ -682,7 +682,7 @@ static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
632 -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
633 +static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
637 @@ -698,7 +698,7 @@ void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
638 p->needInitState = 1;
641 -void LzmaDec_Init(CLzmaDec *p)
642 +static void LzmaDec_Init(CLzmaDec *p)
645 LzmaDec_InitDicAndState(p, True, True);
646 @@ -716,7 +716,7 @@ static void LzmaDec_InitStateReal(CLzmaDec *p)
647 p->needInitState = 0;
650 -SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
651 +static SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
652 ELzmaFinishMode finishMode, ELzmaStatus *status)
654 SizeT inSize = *srcLen;
655 @@ -837,65 +837,13 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
656 return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
659 -SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
661 - SizeT outSize = *destLen;
662 - SizeT inSize = *srcLen;
663 - *srcLen = *destLen = 0;
666 - SizeT inSizeCur = inSize, outSizeCur, dicPos;
667 - ELzmaFinishMode curFinishMode;
669 - if (p->dicPos == p->dicBufSize)
671 - dicPos = p->dicPos;
672 - if (outSize > p->dicBufSize - dicPos)
674 - outSizeCur = p->dicBufSize;
675 - curFinishMode = LZMA_FINISH_ANY;
679 - outSizeCur = dicPos + outSize;
680 - curFinishMode = finishMode;
683 - res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
685 - inSize -= inSizeCur;
686 - *srcLen += inSizeCur;
687 - outSizeCur = p->dicPos - dicPos;
688 - memcpy(dest, p->dic + dicPos, outSizeCur);
689 - dest += outSizeCur;
690 - outSize -= outSizeCur;
691 - *destLen += outSizeCur;
694 - if (outSizeCur == 0 || outSize == 0)
699 -void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
700 +static void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
702 alloc->Free(alloc, p->probs);
706 -static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
708 - alloc->Free(alloc, p->dic);
712 -void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
714 - LzmaDec_FreeProbs(p, alloc);
715 - LzmaDec_FreeDict(p, alloc);
718 -SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
719 +static SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
723 @@ -935,33 +883,11 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
727 -SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
729 - CLzmaProps propNew;
730 - RINOK(LzmaProps_Decode(&propNew, props, propsSize));
731 - RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
736 -SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
737 +static SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
741 RINOK(LzmaProps_Decode(&propNew, props, propsSize));
742 RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
743 - dicBufSize = propNew.dicSize;
744 - if (p->dic == 0 || dicBufSize != p->dicBufSize)
746 - LzmaDec_FreeDict(p, alloc);
747 - p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
750 - LzmaDec_FreeProbs(p, alloc);
751 - return SZ_ERROR_MEM;
754 - p->dicBufSize = dicBufSize;
758 diff --git a/lib/lzma/LzmaEnc.c b/lib/lzma/LzmaEnc.c
759 index 6dadf00dfab2..943965647bad 100644
760 --- a/lib/lzma/LzmaEnc.c
761 +++ b/lib/lzma/LzmaEnc.c
762 @@ -53,7 +53,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
766 -void LzmaEncProps_Normalize(CLzmaEncProps *p)
767 +static void LzmaEncProps_Normalize(CLzmaEncProps *p)
769 int level = p->level;
770 if (level < 0) level = 5;
771 @@ -76,7 +76,7 @@ void LzmaEncProps_Normalize(CLzmaEncProps *p)
775 -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
776 +static UInt32 __maybe_unused LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
778 CLzmaEncProps props = *props2;
779 LzmaEncProps_Normalize(&props);
780 @@ -93,7 +93,7 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
782 #define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
784 -UInt32 GetPosSlot1(UInt32 pos)
785 +static UInt32 GetPosSlot1(UInt32 pos)
789 @@ -107,7 +107,7 @@ UInt32 GetPosSlot1(UInt32 pos)
790 #define kNumLogBits (9 + (int)sizeof(size_t) / 2)
791 #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7)
793 -void LzmaEnc_FastPosInit(Byte *g_FastPos)
794 +static void LzmaEnc_FastPosInit(Byte *g_FastPos)
798 @@ -339,58 +339,6 @@ typedef struct
799 CSaveState saveState;
802 -void LzmaEnc_SaveState(CLzmaEncHandle pp)
804 - CLzmaEnc *p = (CLzmaEnc *)pp;
805 - CSaveState *dest = &p->saveState;
807 - dest->lenEnc = p->lenEnc;
808 - dest->repLenEnc = p->repLenEnc;
809 - dest->state = p->state;
811 - for (i = 0; i < kNumStates; i++)
813 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
814 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
816 - for (i = 0; i < kNumLenToPosStates; i++)
817 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
818 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
819 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
820 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
821 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
822 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
823 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
824 - memcpy(dest->reps, p->reps, sizeof(p->reps));
825 - memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb));
828 -void LzmaEnc_RestoreState(CLzmaEncHandle pp)
830 - CLzmaEnc *dest = (CLzmaEnc *)pp;
831 - const CSaveState *p = &dest->saveState;
833 - dest->lenEnc = p->lenEnc;
834 - dest->repLenEnc = p->repLenEnc;
835 - dest->state = p->state;
837 - for (i = 0; i < kNumStates; i++)
839 - memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i]));
840 - memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i]));
842 - for (i = 0; i < kNumLenToPosStates; i++)
843 - memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i]));
844 - memcpy(dest->isRep, p->isRep, sizeof(p->isRep));
845 - memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0));
846 - memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1));
847 - memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2));
848 - memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders));
849 - memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder));
850 - memcpy(dest->reps, p->reps, sizeof(p->reps));
851 - memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb));
854 SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
856 CLzmaEnc *p = (CLzmaEnc *)pp;
857 @@ -600,7 +548,7 @@ static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol,
858 while (symbol < 0x10000);
861 -void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
862 +static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices)
865 for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
866 @@ -1676,7 +1624,7 @@ static void FillDistancesPrices(CLzmaEnc *p)
867 p->matchPriceCount = 0;
870 -void LzmaEnc_Construct(CLzmaEnc *p)
871 +static void LzmaEnc_Construct(CLzmaEnc *p)
873 RangeEnc_Construct(&p->rc);
874 MatchFinder_Construct(&p->matchFinderBase);
875 @@ -1709,7 +1657,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc)
879 -void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
880 +static void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
882 alloc->Free(alloc, p->litProbs);
883 alloc->Free(alloc, p->saveState.litProbs);
884 @@ -1717,7 +1665,7 @@ void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc)
885 p->saveState.litProbs = 0;
888 -void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
889 +static void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig)
892 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig);
893 @@ -1947,7 +1895,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I
897 -void LzmaEnc_Init(CLzmaEnc *p)
898 +static void LzmaEnc_Init(CLzmaEnc *p)
902 @@ -2005,7 +1953,7 @@ void LzmaEnc_Init(CLzmaEnc *p)
903 p->lpMask = (1 << p->lp) - 1;
906 -void LzmaEnc_InitPrices(CLzmaEnc *p)
907 +static void LzmaEnc_InitPrices(CLzmaEnc *p)
911 @@ -2037,26 +1985,6 @@ static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *a
915 -static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream,
916 - ISzAlloc *alloc, ISzAlloc *allocBig)
918 - CLzmaEnc *p = (CLzmaEnc *)pp;
919 - p->matchFinderBase.stream = inStream;
921 - p->rc.outStream = outStream;
922 - return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
925 -SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
926 - ISeqInStream *inStream, UInt32 keepWindowSize,
927 - ISzAlloc *alloc, ISzAlloc *allocBig)
929 - CLzmaEnc *p = (CLzmaEnc *)pp;
930 - p->matchFinderBase.stream = inStream;
932 - return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
935 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
937 p->matchFinderBase.directInput = 1;
938 @@ -2064,7 +1992,7 @@ static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen)
939 p->matchFinderBase.directInputRem = srcLen;
942 -SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
943 +static SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
944 UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
946 CLzmaEnc *p = (CLzmaEnc *)pp;
947 @@ -2074,7 +2002,7 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
948 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig);
951 -void LzmaEnc_Finish(CLzmaEncHandle pp)
952 +static void LzmaEnc_Finish(CLzmaEncHandle pp)
955 CLzmaEnc *p = (CLzmaEnc *)pp;
956 @@ -2107,53 +2035,6 @@ static size_t MyWrite(void *pp, const void *data, size_t size)
961 -UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp)
963 - const CLzmaEnc *p = (CLzmaEnc *)pp;
964 - return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
967 -const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
969 - const CLzmaEnc *p = (CLzmaEnc *)pp;
970 - return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
973 -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
974 - Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
976 - CLzmaEnc *p = (CLzmaEnc *)pp;
979 - CSeqOutStreamBuf outStream;
981 - outStream.funcTable.Write = MyWrite;
982 - outStream.data = dest;
983 - outStream.rem = *destLen;
984 - outStream.overflow = False;
986 - p->writeEndMark = False;
987 - p->finished = False;
992 - LzmaEnc_InitPrices(p);
993 - nowPos64 = p->nowPos64;
994 - RangeEnc_Init(&p->rc);
995 - p->rc.outStream = &outStream.funcTable;
997 - res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize);
999 - *unpackSize = (UInt32)(p->nowPos64 - nowPos64);
1000 - *destLen -= outStream.rem;
1001 - if (outStream.overflow)
1002 - return SZ_ERROR_OUTPUT_EOF;
1007 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
1010 @@ -2184,13 +2065,6 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress)
1014 -SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress,
1015 - ISzAlloc *alloc, ISzAlloc *allocBig)
1017 - RINOK(LzmaEnc_Prepare(pp, outStream, inStream, alloc, allocBig));
1018 - return LzmaEnc_Encode2((CLzmaEnc *)pp, progress);
1021 SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size)
1023 CLzmaEnc *p = (CLzmaEnc *)pp;
1024 @@ -2247,25 +2121,3 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
1025 return SZ_ERROR_OUTPUT_EOF;
1029 -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
1030 - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
1031 - ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
1033 - CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
1036 - return SZ_ERROR_MEM;
1038 - res = LzmaEnc_SetProps(p, props);
1041 - res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize);
1043 - res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen,
1044 - writeEndMark, progress, alloc, allocBig);
1047 - LzmaEnc_Destroy(p, alloc, allocBig);