Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2018-12-30 17:01:47 +0300
committerKornel <kornel@geekhood.net>2018-12-30 17:01:47 +0300
commit5b2a99c548a6c9c90d4cc63cddca29af009c2479 (patch)
treefb4af843548b762bdb6cc8dc2ec65457a9fdf7da
parent18dc2b41613055f0daf7f6a1d4311368798ea12a (diff)
18.0618.06
-rw-r--r--C/7zArcIn.c4
-rw-r--r--C/7zDec.c8
-rw-r--r--C/7zTypes.h5
-rw-r--r--C/7zVersion.h6
-rw-r--r--C/Bcj2Enc.c6
-rw-r--r--C/BwtSort.c4
-rw-r--r--C/CpuArch.c10
-rw-r--r--C/CpuArch.h8
-rw-r--r--C/LzFind.c164
-rw-r--r--C/LzFindMt.c117
-rw-r--r--C/LzFindMt.h14
-rw-r--r--C/Lzma2Dec.c10
-rw-r--r--C/Lzma2DecMt.c30
-rw-r--r--C/Lzma2Enc.c8
-rw-r--r--C/Lzma86Enc.c8
-rw-r--r--C/LzmaDec.c32
-rw-r--r--C/LzmaEnc.c733
-rw-r--r--C/MtCoder.c8
-rw-r--r--C/MtCoder.h6
-rw-r--r--C/MtDec.c20
-rw-r--r--C/MtDec.h24
-rw-r--r--C/Ppmd7.c6
-rw-r--r--C/Ppmd7.h6
-rw-r--r--C/Ppmd7Dec.c4
-rw-r--r--C/Ppmd8.c6
-rw-r--r--C/Ppmd8.h6
-rw-r--r--C/Ppmd8Dec.c4
-rw-r--r--C/Util/7z/7zMain.c4
-rw-r--r--C/Util/7zipInstall/7zipInstall.c24
-rw-r--r--C/Util/7zipUninstall/7zipUninstall.c38
-rw-r--r--C/Util/Lzma/LzmaUtil.c4
-rw-r--r--C/Util/SfxSetup/SfxSetup.c10
-rw-r--r--C/Xz.h20
-rw-r--r--C/XzDec.c85
-rw-r--r--C/XzEnc.c6
-rw-r--r--C/XzIn.c4
-rw-r--r--CPP/7zip/Aes.mak2
-rw-r--r--CPP/7zip/Archive/7z/7zHandler.cpp7
-rw-r--r--CPP/7zip/Archive/7z/7zHandlerOut.cpp3
-rw-r--r--CPP/7zip/Archive/7z/7zIn.cpp17
-rw-r--r--CPP/7zip/Archive/7z/7zIn.h10
-rw-r--r--CPP/7zip/Archive/7z/7zUpdate.cpp19
-rw-r--r--CPP/7zip/Archive/ArHandler.cpp8
-rw-r--r--CPP/7zip/Archive/Bz2Handler.cpp8
-rw-r--r--CPP/7zip/Archive/Common/CoderMixer2.cpp1
-rw-r--r--CPP/7zip/Archive/DmgHandler.cpp14
-rw-r--r--CPP/7zip/Archive/ExtHandler.cpp13
-rw-r--r--CPP/7zip/Archive/FatHandler.cpp3
-rw-r--r--CPP/7zip/Archive/HfsHandler.cpp8
-rw-r--r--CPP/7zip/Archive/LzmaHandler.cpp52
-rw-r--r--CPP/7zip/Archive/Nsis/NsisIn.cpp13
-rw-r--r--CPP/7zip/Archive/NtfsHandler.cpp23
-rw-r--r--CPP/7zip/Archive/Rar/Rar5Handler.cpp144
-rw-r--r--CPP/7zip/Archive/Rar/RarHandler.cpp5
-rw-r--r--CPP/7zip/Archive/SquashfsHandler.cpp50
-rw-r--r--CPP/7zip/Archive/SwfHandler.cpp2
-rw-r--r--CPP/7zip/Archive/Tar/TarIn.cpp10
-rw-r--r--CPP/7zip/Archive/Wim/WimIn.cpp18
-rw-r--r--CPP/7zip/Archive/Wim/WimIn.h7
-rw-r--r--CPP/7zip/Archive/XzHandler.cpp4
-rw-r--r--CPP/7zip/Archive/Zip/ZipHandler.cpp8
-rw-r--r--CPP/7zip/Archive/Zip/ZipIn.cpp21
-rw-r--r--CPP/7zip/Archive/Zip/ZipIn.h6
-rw-r--r--CPP/7zip/Archive/Zip/ZipItem.h14
-rw-r--r--CPP/7zip/Archive/Zip/ZipUpdate.cpp5
-rw-r--r--CPP/7zip/Bundles/LzmaCon/makefile1
-rw-r--r--CPP/7zip/Compress/DeflateDecoder.cpp8
-rw-r--r--CPP/7zip/Compress/LzmsDecoder.cpp4
-rw-r--r--CPP/7zip/Compress/Rar3Decoder.cpp33
-rw-r--r--CPP/7zip/Compress/Rar3Decoder.h1
-rw-r--r--CPP/7zip/Compress/XpressDecoder.cpp19
-rw-r--r--CPP/7zip/Crc.mak2
-rw-r--r--CPP/7zip/Crc64.mak2
-rw-r--r--CPP/7zip/LzmaDec.mak2
-rw-r--r--CPP/7zip/UI/Common/ArchiveCommandLine.cpp16
-rw-r--r--CPP/7zip/UI/Common/ArchiveExtractCallback.cpp26
-rw-r--r--CPP/7zip/UI/Common/ArchiveName.cpp76
-rw-r--r--CPP/7zip/UI/Common/ArchiveName.h5
-rw-r--r--CPP/7zip/UI/Common/Bench.cpp96
-rw-r--r--CPP/7zip/UI/Common/Bench.h5
-rw-r--r--CPP/7zip/UI/Common/EnumDirItems.cpp10
-rw-r--r--CPP/7zip/UI/Common/EnumDirItems.h1
-rw-r--r--CPP/7zip/UI/Common/HashCalc.cpp2
-rw-r--r--CPP/7zip/UI/Common/HashCalc.h8
-rw-r--r--CPP/7zip/UI/Common/OpenArchive.cpp5
-rw-r--r--CPP/7zip/UI/Common/Update.cpp95
-rw-r--r--CPP/7zip/UI/Console/HashCon.cpp2
-rw-r--r--CPP/7zip/UI/Console/List.cpp50
-rw-r--r--CPP/7zip/UI/Console/Main.cpp16
-rw-r--r--CPP/7zip/UI/Explorer/ContextMenu.cpp10
-rw-r--r--CPP/7zip/UI/Far/Far.cpp19
-rw-r--r--CPP/7zip/UI/FileManager/AltStreamsFolder.cpp2
-rw-r--r--CPP/7zip/UI/FileManager/ExtractCallback.cpp4
-rw-r--r--CPP/7zip/UI/FileManager/ListViewDialog.cpp6
-rw-r--r--CPP/7zip/UI/FileManager/Panel.cpp5
-rw-r--r--CPP/7zip/UI/FileManager/PanelCopy.cpp13
-rw-r--r--CPP/7zip/UI/FileManager/PanelCrc.cpp12
-rw-r--r--CPP/7zip/UI/FileManager/PanelDrag.cpp6
-rw-r--r--CPP/7zip/UI/GUI/BenchmarkDialog.cpp11
-rw-r--r--CPP/7zip/UI/GUI/ExtractGUI.cpp4
-rw-r--r--CPP/7zip/UI/GUI/HashGUI.cpp35
-rw-r--r--CPP/7zip/UI/GUI/HashGUI.h6
-rw-r--r--CPP/Build.mak49
-rw-r--r--CPP/Common/ListFileUtils.cpp15
-rw-r--r--CPP/Common/ListFileUtils.h6
-rw-r--r--CPP/Common/MyString.h1
-rw-r--r--DOC/7zFormat.txt6
-rw-r--r--DOC/7zip.inf4
-rw-r--r--DOC/7zip.nsi2
-rw-r--r--DOC/7zip.wxs2
-rw-r--r--DOC/Methods.txt10
-rw-r--r--DOC/readme.txt56
-rw-r--r--DOC/src-history.txt15
113 files changed, 1802 insertions, 929 deletions
diff --git a/C/7zArcIn.c b/C/7zArcIn.c
index e1b03d87..f1f4d518 100644
--- a/C/7zArcIn.c
+++ b/C/7zArcIn.c
@@ -1,5 +1,5 @@
/* 7zArcIn.c -- 7z Input functions
-2017-04-03 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -1744,7 +1744,7 @@ size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex)
UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest)
{
- Bool needSlash;
+ BoolInt needSlash;
if (!p->FileNameOffsets)
{
*(--dest) = 0;
diff --git a/C/7zDec.c b/C/7zDec.c
index 1ae87dfa..2628a70f 100644
--- a/C/7zDec.c
+++ b/C/7zDec.c
@@ -1,5 +1,5 @@
/* 7zDec.c -- Decoding from 7z folder
-2017-04-03 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -44,7 +44,7 @@ typedef struct
const Byte *end;
const Byte *begin;
UInt64 processed;
- Bool extra;
+ BoolInt extra;
SRes res;
const ILookInStream *inStream;
} CByteInToLook;
@@ -269,7 +269,7 @@ static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer
return SZ_OK;
}
-static Bool IS_MAIN_METHOD(UInt32 m)
+static BoolInt IS_MAIN_METHOD(UInt32 m)
{
switch (m)
{
@@ -286,7 +286,7 @@ static Bool IS_MAIN_METHOD(UInt32 m)
return False;
}
-static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)
+static BoolInt IS_SUPPORTED_CODER(const CSzCoderInfo *c)
{
return
c->NumStreams == 1
diff --git a/C/7zTypes.h b/C/7zTypes.h
index 29244b23..65b3af63 100644
--- a/C/7zTypes.h
+++ b/C/7zTypes.h
@@ -1,5 +1,5 @@
/* 7zTypes.h -- Basic types
-2017-07-17 : Igor Pavlov : Public domain */
+2018-08-04 : Igor Pavlov : Public domain */
#ifndef __7Z_TYPES_H
#define __7Z_TYPES_H
@@ -103,7 +103,8 @@ typedef UInt32 SizeT;
typedef size_t SizeT;
#endif
-typedef int Bool;
+typedef int BoolInt;
+/* typedef BoolInt Bool; */
#define True 1
#define False 0
diff --git a/C/7zVersion.h b/C/7zVersion.h
index f3fb623a..a486e424 100644
--- a/C/7zVersion.h
+++ b/C/7zVersion.h
@@ -1,7 +1,7 @@
#define MY_VER_MAJOR 18
-#define MY_VER_MINOR 05
+#define MY_VER_MINOR 06
#define MY_VER_BUILD 0
-#define MY_VERSION_NUMBERS "18.05"
+#define MY_VERSION_NUMBERS "18.06"
#define MY_VERSION MY_VERSION_NUMBERS
#ifdef MY_CPU_NAME
@@ -10,7 +10,7 @@
#define MY_VERSION_CPU MY_VERSION
#endif
-#define MY_DATE "2018-04-30"
+#define MY_DATE "2018-12-30"
#undef MY_COPYRIGHT
#undef MY_VERSION_COPYRIGHT_DATE
#define MY_AUTHOR_NAME "Igor Pavlov"
diff --git a/C/Bcj2Enc.c b/C/Bcj2Enc.c
index 5c682982..b40097e7 100644
--- a/C/Bcj2Enc.c
+++ b/C/Bcj2Enc.c
@@ -1,5 +1,5 @@
/* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code)
-2017-04-28 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -52,7 +52,7 @@ void Bcj2Enc_Init(CBcj2Enc *p)
p->probs[i] = kBitModelTotal >> 1;
}
-static Bool MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p)
+static BoolInt MY_FAST_CALL RangeEnc_ShiftLow(CBcj2Enc *p)
{
if ((UInt32)p->low < (UInt32)0xFF000000 || (UInt32)(p->low >> 32) != 0)
{
@@ -165,7 +165,7 @@ static void Bcj2Enc_Encode_2(CBcj2Enc *p)
{
Byte context = (Byte)(num == 0 ? p->prevByte : src[-1]);
- Bool needConvert;
+ BoolInt needConvert;
p->bufs[BCJ2_STREAM_MAIN] = dest + 1;
p->ip += (UInt32)num + 1;
diff --git a/C/BwtSort.c b/C/BwtSort.c
index aa319201..cc2f4b29 100644
--- a/C/BwtSort.c
+++ b/C/BwtSort.c
@@ -1,5 +1,5 @@
/* BwtSort.c -- BWT block sorting
-2017-04-03 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -448,7 +448,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax);
{
- Bool finishedGroup = ((Indices[i] & 0x80000000) == 0);
+ BoolInt finishedGroup = ((Indices[i] & 0x80000000) == 0);
if ((Indices[i] & 0x40000000) != 0)
{
groupSize += ((Indices[(size_t)i + 1] >> kNumBitsMax) << kNumExtra0Bits);
diff --git a/C/CpuArch.c b/C/CpuArch.c
index 554ffa4f..962eb780 100644
--- a/C/CpuArch.c
+++ b/C/CpuArch.c
@@ -1,5 +1,5 @@
/* CpuArch.c -- CPU specific code
-2016-02-25: Igor Pavlov : Public domain */
+2018-07-04: Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -115,7 +115,7 @@ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
#endif
}
-Bool x86cpuid_CheckAndRead(Cx86cpuid *p)
+BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p)
{
CHECK_CPUID_IS_SUPPORTED
MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
@@ -144,7 +144,7 @@ int x86cpuid_GetFirm(const Cx86cpuid *p)
return -1;
}
-Bool CPU_Is_InOrder()
+BoolInt CPU_Is_InOrder()
{
Cx86cpuid p;
int firm;
@@ -175,7 +175,7 @@ Bool CPU_Is_InOrder()
#if !defined(MY_CPU_AMD64) && defined(_WIN32)
#include <windows.h>
-static Bool CPU_Sys_Is_SSE_Supported()
+static BoolInt CPU_Sys_Is_SSE_Supported()
{
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
@@ -188,7 +188,7 @@ static Bool CPU_Sys_Is_SSE_Supported()
#define CHECK_SYS_SSE_SUPPORT
#endif
-Bool CPU_Is_Aes_Supported()
+BoolInt CPU_Is_Aes_Supported()
{
Cx86cpuid p;
CHECK_SYS_SSE_SUPPORT
diff --git a/C/CpuArch.h b/C/CpuArch.h
index 056116dd..fdc114b8 100644
--- a/C/CpuArch.h
+++ b/C/CpuArch.h
@@ -1,5 +1,5 @@
/* CpuArch.h -- CPU specific code
-2017-09-04 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#ifndef __CPU_ARCH_H
#define __CPU_ARCH_H
@@ -318,15 +318,15 @@ enum
void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);
-Bool x86cpuid_CheckAndRead(Cx86cpuid *p);
+BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p);
int x86cpuid_GetFirm(const Cx86cpuid *p);
#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
#define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF))
#define x86cpuid_GetStepping(ver) (ver & 0xF)
-Bool CPU_Is_InOrder();
-Bool CPU_Is_Aes_Supported();
+BoolInt CPU_Is_InOrder();
+BoolInt CPU_Is_Aes_Supported();
#endif
diff --git a/C/LzFind.c b/C/LzFind.c
index 18ef49dc..df55e86c 100644
--- a/C/LzFind.c
+++ b/C/LzFind.c
@@ -1,5 +1,5 @@
/* LzFind.c -- Match finder for LZ algorithms
-2017-06-10 : Igor Pavlov : Public domain */
+2018-07-08 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -138,7 +138,7 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
void MatchFinder_Construct(CMatchFinder *p)
{
- UInt32 i;
+ unsigned i;
p->bufferBase = NULL;
p->directInput = 0;
p->hash = NULL;
@@ -147,7 +147,7 @@ void MatchFinder_Construct(CMatchFinder *p)
for (i = 0; i < 256; i++)
{
- UInt32 r = i;
+ UInt32 r = (UInt32)i;
unsigned j;
for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));
@@ -368,6 +368,8 @@ static void MatchFinder_Normalize(CMatchFinder *p)
MatchFinder_ReduceOffsets(p, subValue);
}
+
+MY_NO_INLINE
static void MatchFinder_CheckLimits(CMatchFinder *p)
{
if (p->pos == kMaxValForNormalize)
@@ -379,10 +381,16 @@ static void MatchFinder_CheckLimits(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+
+/*
+ (lenLimit > maxLen)
+*/
+MY_FORCE_INLINE
+static UInt32 * Hc_GetMatchesSpec(unsigned lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
- UInt32 *distances, UInt32 maxLen)
+ UInt32 *distances, unsigned maxLen)
{
+ /*
son[_cyclicBufferPos] = curMatch;
for (;;)
{
@@ -400,7 +408,8 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos,
break;
if (maxLen < len)
{
- *distances++ = maxLen = len;
+ maxLen = len;
+ *distances++ = len;
*distances++ = delta - 1;
if (len == lenLimit)
return distances;
@@ -408,15 +417,58 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos,
}
}
}
+ */
+
+ const Byte *lim = cur + lenLimit;
+ son[_cyclicBufferPos] = curMatch;
+ do
+ {
+ UInt32 delta = pos - curMatch;
+ if (delta >= _cyclicBufferSize)
+ break;
+ {
+ ptrdiff_t diff;
+ curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
+ diff = (ptrdiff_t)0 - delta;
+ if (cur[maxLen] == cur[maxLen + diff])
+ {
+ const Byte *c = cur;
+ while (*c == c[diff])
+ {
+ if (++c == lim)
+ {
+ distances[0] = (UInt32)(lim - cur);
+ distances[1] = delta - 1;
+ return distances + 2;
+ }
+ }
+ {
+ unsigned len = (unsigned)(c - cur);
+ if (maxLen < len)
+ {
+ maxLen = len;
+ distances[0] = (UInt32)len;
+ distances[1] = delta - 1;
+ distances += 2;
+ }
+ }
+ }
+ }
+ }
+ while (--cutValue);
+
+ return distances;
}
+
+MY_FORCE_INLINE
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
UInt32 *distances, UInt32 maxLen)
{
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+ unsigned len0 = 0, len1 = 0;
for (;;)
{
UInt32 delta = pos - curMatch;
@@ -426,9 +478,10 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
return distances;
}
{
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
+ unsigned len = (len0 < len1 ? len0 : len1);
+ UInt32 pair0 = pair[0];
if (pb[len] == cur[len])
{
if (++len != lenLimit && pb[len] == cur[len])
@@ -437,11 +490,12 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
break;
if (maxLen < len)
{
- *distances++ = maxLen = len;
+ maxLen = (UInt32)len;
+ *distances++ = (UInt32)len;
*distances++ = delta - 1;
if (len == lenLimit)
{
- *ptr1 = pair[0];
+ *ptr1 = pair0;
*ptr0 = pair[1];
return distances;
}
@@ -468,9 +522,9 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
{
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+ unsigned len0 = 0, len1 = 0;
for (;;)
{
UInt32 delta = pos - curMatch;
@@ -480,9 +534,9 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
return;
}
{
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
+ unsigned len = (len0 < len1 ? len0 : len1);
if (pb[len] == cur[len])
{
while (++len != lenLimit)
@@ -520,13 +574,13 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
p->buffer++; \
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
-#define MOVE_POS_RET MOVE_POS return offset;
+#define MOVE_POS_RET MOVE_POS return (UInt32)offset;
static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define GET_MATCHES_HEADER2(minLen, ret_op) \
- UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \
- lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
+ unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \
+ lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
cur = p->buffer;
#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
@@ -535,22 +589,22 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
#define GET_MATCHES_FOOTER(offset, maxLen) \
- offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
- distances + offset, maxLen) - distances); MOVE_POS_RET;
+ offset = (unsigned)(GetMatchesSpec1((UInt32)lenLimit, curMatch, MF_PARAMS(p), \
+ distances + offset, (UInt32)maxLen) - distances); MOVE_POS_RET;
#define SKIP_FOOTER \
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
+ SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
#define UPDATE_maxLen { \
ptrdiff_t diff = (ptrdiff_t)0 - d2; \
const Byte *c = cur + maxLen; \
const Byte *lim = cur + lenLimit; \
for (; c != lim; c++) if (*(c + diff) != *c) break; \
- maxLen = (UInt32)(c - cur); }
+ maxLen = (unsigned)(c - cur); }
static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
- UInt32 offset;
+ unsigned offset;
GET_MATCHES_HEADER(2)
HASH2_CALC;
curMatch = p->hash[hv];
@@ -561,7 +615,7 @@ static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
- UInt32 offset;
+ unsigned offset;
GET_MATCHES_HEADER(3)
HASH_ZIP_CALC;
curMatch = p->hash[hv];
@@ -572,7 +626,8 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
- UInt32 h2, d2, maxLen, offset, pos;
+ UInt32 h2, d2, pos;
+ unsigned maxLen, offset;
UInt32 *hash;
GET_MATCHES_HEADER(3)
@@ -594,12 +649,12 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
{
UPDATE_maxLen
- distances[0] = maxLen;
+ distances[0] = (UInt32)maxLen;
distances[1] = d2 - 1;
offset = 2;
if (maxLen == lenLimit)
{
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
+ SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
MOVE_POS_RET;
}
}
@@ -609,7 +664,8 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
- UInt32 h2, h3, d2, d3, maxLen, offset, pos;
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen, offset;
UInt32 *hash;
GET_MATCHES_HEADER(4)
@@ -618,12 +674,12 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash;
pos = p->pos;
- d2 = pos - hash[ h2];
+ d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] = pos;
+ hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[hv] = pos;
@@ -632,7 +688,8 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
{
- distances[0] = maxLen = 2;
+ maxLen = 2;
+ distances[0] = 2;
distances[1] = d2 - 1;
offset = 2;
}
@@ -648,10 +705,10 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0)
{
UPDATE_maxLen
- distances[(size_t)offset - 2] = maxLen;
+ distances[(size_t)offset - 2] = (UInt32)maxLen;
if (maxLen == lenLimit)
{
- SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
+ SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
MOVE_POS_RET;
}
}
@@ -674,13 +731,13 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash;
pos = p->pos;
- d2 = pos - hash[ h2];
+ d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3];
d4 = pos - (hash + kFix4HashSize)[h4];
curMatch = (hash + kFix5HashSize)[hv];
- hash[ h2] = pos;
+ hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[h4] = pos;
(hash + kFix5HashSize)[hv] = pos;
@@ -741,7 +798,8 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
- UInt32 h2, h3, d2, d3, maxLen, offset, pos;
+ UInt32 h2, h3, d2, d3, pos;
+ unsigned maxLen, offset;
UInt32 *hash;
GET_MATCHES_HEADER(4)
@@ -750,12 +808,11 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash;
pos = p->pos;
- d2 = pos - hash[ h2];
+ d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3];
-
curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] = pos;
+ hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[hv] = pos;
@@ -764,7 +821,8 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
{
- distances[0] = maxLen = 2;
+ maxLen = 2;
+ distances[0] = 2;
distances[1] = d2 - 1;
offset = 2;
}
@@ -780,7 +838,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0)
{
UPDATE_maxLen
- distances[(size_t)offset - 2] = maxLen;
+ distances[(size_t)offset - 2] = (UInt32)maxLen;
if (maxLen == lenLimit)
{
p->son[p->cyclicBufferPos] = curMatch;
@@ -791,7 +849,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (maxLen < 3)
maxLen = 3;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+ offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
distances + offset, maxLen) - (distances));
MOVE_POS_RET
}
@@ -808,13 +866,13 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash;
pos = p->pos;
- d2 = pos - hash[ h2];
+ d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3];
d4 = pos - (hash + kFix4HashSize)[h4];
curMatch = (hash + kFix5HashSize)[hv];
- hash[ h2] = pos;
+ hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[h4] = pos;
(hash + kFix5HashSize)[hv] = pos;
@@ -877,12 +935,12 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
- UInt32 offset;
+ unsigned offset;
GET_MATCHES_HEADER(3)
HASH_ZIP_CALC;
curMatch = p->hash[hv];
p->hash[hv] = p->pos;
- offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
+ offset = (unsigned)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
distances, 2) - (distances));
MOVE_POS_RET
}
@@ -940,7 +998,7 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH4_CALC;
hash = p->hash;
curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] =
+ hash [h2] =
(hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[hv] = p->pos;
SKIP_FOOTER
@@ -959,7 +1017,7 @@ static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH5_CALC;
hash = p->hash;
curMatch = (hash + kFix5HashSize)[hv];
- hash[ h2] =
+ hash [h2] =
(hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[h4] =
(hash + kFix5HashSize)[hv] = p->pos;
@@ -979,7 +1037,7 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH4_CALC;
hash = p->hash;
curMatch = (hash + kFix4HashSize)[hv];
- hash[ h2] =
+ hash [h2] =
(hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[hv] = p->pos;
p->son[p->cyclicBufferPos] = curMatch;
@@ -999,7 +1057,7 @@ static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH5_CALC;
hash = p->hash;
curMatch = hash + kFix5HashSize)[hv];
- hash[ h2] =
+ hash [h2] =
(hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[h4] =
(hash + kFix5HashSize)[hv] = p->pos;
diff --git a/C/LzFindMt.c b/C/LzFindMt.c
index 65c9ffd7..bb0f42c3 100644
--- a/C/LzFindMt.c
+++ b/C/LzFindMt.c
@@ -1,5 +1,5 @@
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
-2017-06-10 : Igor Pavlov : Public domain */
+2018-12-29 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -232,38 +232,57 @@ static void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
#define kEmptyHashValue 0
-/* #define MFMT_GM_INLINE */
+#define MFMT_GM_INLINE
#ifdef MFMT_GM_INLINE
-#define NO_INLINE MY_FAST_CALL
+/*
+ we use size_t for _cyclicBufferPos instead of UInt32
+ to eliminate "movsx" BUG in old MSVC x64 compiler.
+*/
-static Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
- UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
+MY_NO_INLINE
+static UInt32 *GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
+ size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+ UInt32 *distances, UInt32 _maxLen, const UInt32 *hash, const UInt32 *limit, UInt32 size, UInt32 *posRes)
{
do
{
- UInt32 *distances = _distances + 1;
- UInt32 curMatch = pos - *hash++;
+ UInt32 *_distances = ++distances;
+ UInt32 delta = *hash++;
- CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
- CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
- UInt32 len0 = 0, len1 = 0;
+ CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
+ CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
+ unsigned len0 = 0, len1 = 0;
UInt32 cutValue = _cutValue;
- UInt32 maxLen = _maxLen;
- for (;;)
+ unsigned maxLen = (unsigned)_maxLen;
+
+ /*
+ if (size > 1)
{
- UInt32 delta = pos - curMatch;
- if (cutValue-- == 0 || delta >= _cyclicBufferSize)
+ UInt32 delta = *hash;
+ if (delta < _cyclicBufferSize)
{
- *ptr0 = *ptr1 = kEmptyHashValue;
- break;
+ UInt32 cyc1 = _cyclicBufferPos + 1;
+ CLzRef *pair = son + ((size_t)(cyc1 - delta + ((delta > cyc1) ? _cyclicBufferSize : 0)) << 1);
+ Byte b = *(cur + 1 - delta);
+ _distances[0] = pair[0];
+ _distances[1] = b;
}
+ }
+ */
+ if (cutValue == 0 || delta >= _cyclicBufferSize)
+ {
+ *ptr0 = *ptr1 = kEmptyHashValue;
+ }
+ else
+ for(;;)
+ {
{
- CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
+ CLzRef *pair = son + ((size_t)(_cyclicBufferPos - delta + ((_cyclicBufferPos < delta) ? _cyclicBufferSize : 0)) << 1);
const Byte *pb = cur - delta;
- UInt32 len = (len0 < len1 ? len0 : len1);
+ unsigned len = (len0 < len1 ? len0 : len1);
+ UInt32 pair0 = *pair;
if (pb[len] == cur[len])
{
if (++len != lenLimit && pb[len] == cur[len])
@@ -272,54 +291,66 @@ static Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *
break;
if (maxLen < len)
{
- *distances++ = maxLen = len;
+ maxLen = len;
+ *distances++ = (UInt32)len;
*distances++ = delta - 1;
if (len == lenLimit)
{
- *ptr1 = pair[0];
- *ptr0 = pair[1];
+ UInt32 pair1 = pair[1];
+ *ptr1 = pair0;
+ *ptr0 = pair1;
break;
}
}
}
- if (pb[len] < cur[len])
- {
- *ptr1 = curMatch;
- ptr1 = pair + 1;
- curMatch = *ptr1;
- len1 = len;
- }
- else
{
- *ptr0 = curMatch;
- ptr0 = pair;
- curMatch = *ptr0;
- len0 = len;
+ UInt32 curMatch = pos - delta;
+ // delta = pos - *pair;
+ // delta = pos - pair[((UInt32)pb[len] - (UInt32)cur[len]) >> 31];
+ if (pb[len] < cur[len])
+ {
+ delta = pos - pair[1];
+ *ptr1 = curMatch;
+ ptr1 = pair + 1;
+ len1 = len;
+ }
+ else
+ {
+ delta = pos - *pair;
+ *ptr0 = curMatch;
+ ptr0 = pair;
+ len0 = len;
+ }
}
}
+ if (--cutValue == 0 || delta >= _cyclicBufferSize)
+ {
+ *ptr0 = *ptr1 = kEmptyHashValue;
+ break;
+ }
}
pos++;
_cyclicBufferPos++;
cur++;
{
UInt32 num = (UInt32)(distances - _distances);
- *_distances = num - 1;
- _distances += num;
- limit -= num;
+ _distances[-1] = num;
}
}
- while (limit > 0 && --size != 0);
+ while (distances < limit && --size != 0);
*posRes = pos;
- return limit;
+ return distances;
}
#endif
+
+
static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
{
UInt32 numProcessed = 0;
UInt32 curPos = 2;
- UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2);
+ UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); // * 2
distances[1] = p->hashNumAvail;
@@ -369,8 +400,10 @@ static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
#else
{
UInt32 posRes;
- curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
- distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos), size, &posRes);
+ curPos = (UInt32)(GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
+ distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos,
+ distances + limit,
+ size, &posRes) - distances);
p->hashBufPos += posRes - pos;
cyclicBufferPos += posRes - pos;
p->buffer += posRes - pos;
diff --git a/C/LzFindMt.h b/C/LzFindMt.h
index a6645f53..ef431e3f 100644
--- a/C/LzFindMt.h
+++ b/C/LzFindMt.h
@@ -1,5 +1,5 @@
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
-2017-04-03 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#ifndef __LZ_FIND_MT_H
#define __LZ_FIND_MT_H
@@ -19,10 +19,10 @@ EXTERN_C_BEGIN
typedef struct _CMtSync
{
- Bool wasCreated;
- Bool needStart;
- Bool exit;
- Bool stopWriting;
+ BoolInt wasCreated;
+ BoolInt needStart;
+ BoolInt exit;
+ BoolInt stopWriting;
CThread thread;
CAutoResetEvent canStart;
@@ -30,8 +30,8 @@ typedef struct _CMtSync
CAutoResetEvent wasStopped;
CSemaphore freeSemaphore;
CSemaphore filledSemaphore;
- Bool csWasInitialized;
- Bool csWasEntered;
+ BoolInt csWasInitialized;
+ BoolInt csWasEntered;
CCriticalSection cs;
UInt32 numProcessedBlocks;
} CMtSync;
diff --git a/C/Lzma2Dec.c b/C/Lzma2Dec.c
index ecde5508..b0af5b0f 100644
--- a/C/Lzma2Dec.c
+++ b/C/Lzma2Dec.c
@@ -1,5 +1,5 @@
/* Lzma2Dec.c -- LZMA2 Decoder
-2018-02-19 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
/* #define SHOW_DEBUG_INFO */
@@ -169,7 +169,7 @@ static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT s
p->processedPos += (UInt32)size;
}
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState);
+void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState);
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
@@ -232,7 +232,7 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
if (p->state == LZMA2_STATE_DATA)
{
- Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
+ BoolInt initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC);
LzmaDec_InitDicAndState(&p->decoder, initDic, False);
}
@@ -254,8 +254,8 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
if (p->state == LZMA2_STATE_DATA)
{
- Bool initDic = (p->control >= 0xE0);
- Bool initState = (p->control >= 0xA0);
+ BoolInt initDic = (p->control >= 0xE0);
+ BoolInt initState = (p->control >= 0xA0);
LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
p->state = LZMA2_STATE_DATA_CONT;
}
diff --git a/C/Lzma2DecMt.c b/C/Lzma2DecMt.c
index c0a9d495..476d58f0 100644
--- a/C/Lzma2DecMt.c
+++ b/C/Lzma2DecMt.c
@@ -1,5 +1,5 @@
/* Lzma2DecMt.c -- LZMA2 Decoder Multi-thread
-2018-03-02 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -94,13 +94,13 @@ typedef struct
ISeqOutStream *outStream;
ICompressProgress *progress;
- Bool finishMode;
- Bool outSize_Defined;
+ BoolInt finishMode;
+ BoolInt outSize_Defined;
UInt64 outSize;
UInt64 outProcessed;
UInt64 inProcessed;
- Bool readWasFinished;
+ BoolInt readWasFinished;
SRes readRes;
Byte *inBuf;
@@ -113,7 +113,7 @@ typedef struct
#ifndef _7ZIP_ST
UInt64 outProcessed_Parse;
- Bool mtc_WasConstructed;
+ BoolInt mtc_WasConstructed;
CMtDec mtc;
CLzma2DecMtThread coders[MTDEC__THREADS_MAX];
#endif
@@ -277,7 +277,7 @@ static void Lzma2DecMt_MtCallback_Parse(void *obj, unsigned coderIndex, CMtDecCa
{
ELzma2ParseStatus status;
- Bool overflow;
+ BoolInt overflow;
UInt32 unpackRem = 0;
int checkFinishBlock = True;
@@ -477,7 +477,7 @@ static SRes Lzma2DecMt_MtCallback_Code(void *pp, unsigned coderIndex,
{
ELzmaStatus status;
size_t srcProcessed = srcSize;
- Bool blockWasFinished =
+ BoolInt blockWasFinished =
((int)t->parseStatus == LZMA_STATUS_FINISHED_WITH_MARK
|| t->parseStatus == LZMA2_PARSE_STATUS_NEW_BLOCK);
@@ -526,15 +526,15 @@ static SRes Lzma2DecMt_MtCallback_Code(void *pp, unsigned coderIndex,
#define LZMA2DECMT_STREAM_WRITE_STEP (1 << 24)
static SRes Lzma2DecMt_MtCallback_Write(void *pp, unsigned coderIndex,
- Bool needWriteToStream,
+ BoolInt needWriteToStream,
const Byte *src, size_t srcSize,
- Bool *needContinue, Bool *canRecode)
+ BoolInt *needContinue, BoolInt *canRecode)
{
CLzma2DecMt *me = (CLzma2DecMt *)pp;
const CLzma2DecMtThread *t = &me->coders[coderIndex];
size_t size = t->outCodeSize;
const Byte *data = t->outBuf;
- Bool needContinue2 = True;
+ BoolInt needContinue2 = True;
PRF_STR_INT_2("Write", coderIndex, srcSize);
@@ -633,7 +633,7 @@ static SRes Lzma2Dec_Prepare_ST(CLzma2DecMt *p)
static SRes Lzma2Dec_Decode_ST(CLzma2DecMt *p
#ifndef _7ZIP_ST
- , Bool tMode
+ , BoolInt tMode
#endif
)
{
@@ -674,8 +674,8 @@ static SRes Lzma2Dec_Decode_ST(CLzma2DecMt *p
SRes res;
SizeT outProcessed;
- Bool outFinished;
- Bool needStop;
+ BoolInt outFinished;
+ BoolInt needStop;
if (inPos == inLim)
{
@@ -810,7 +810,7 @@ SRes Lzma2DecMt_Decode(CLzma2DecMtHandle pp,
{
CLzma2DecMt *p = (CLzma2DecMt *)pp;
#ifndef _7ZIP_ST
- Bool tMode;
+ BoolInt tMode;
#endif
*inProcessed = 0;
@@ -903,7 +903,7 @@ SRes Lzma2DecMt_Decode(CLzma2DecMtHandle pp,
vt.Write = Lzma2DecMt_MtCallback_Write;
{
- Bool needContinue = False;
+ BoolInt needContinue = False;
SRes res = MtDec_Code(&p->mtc);
diff --git a/C/Lzma2Enc.c b/C/Lzma2Enc.c
index f83c8008..5c1ad493 100644
--- a/C/Lzma2Enc.c
+++ b/C/Lzma2Enc.c
@@ -1,5 +1,5 @@
/* Lzma2Enc.c -- LZMA2 Encoder
-2018-04-27 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -115,7 +115,7 @@ SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 k
ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig);
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit,
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
void LzmaEnc_Finish(CLzmaEncHandle pp);
@@ -133,7 +133,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
size_t packSize = packSizeLimit;
UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX;
unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0);
- Bool useCopyBlock;
+ BoolInt useCopyBlock;
SRes res;
*packSizeRes = 0;
@@ -373,7 +373,7 @@ typedef struct
size_t outBufSize; /* size of allocated outBufs[i] */
size_t outBufsDataSizes[MTCODER__BLOCKS_MAX];
- Bool mtCoder_WasConstructed;
+ BoolInt mtCoder_WasConstructed;
CMtCoder mtCoder;
Byte *outBufs[MTCODER__BLOCKS_MAX];
diff --git a/C/Lzma86Enc.c b/C/Lzma86Enc.c
index a15b58d6..2617bab8 100644
--- a/C/Lzma86Enc.c
+++ b/C/Lzma86Enc.c
@@ -1,5 +1,5 @@
/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
-2016-05-16 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -18,7 +18,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
{
size_t outSize2 = *destLen;
Byte *filteredStream;
- Bool useFilter;
+ BoolInt useFilter;
int mainResult = SZ_ERROR_OUTPUT_EOF;
CLzmaEncProps props;
LzmaEncProps_Init(&props);
@@ -56,7 +56,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
{
size_t minSize = 0;
- Bool bestIsFiltered = False;
+ BoolInt bestIsFiltered = False;
/* passes for SZ_FILTER_AUTO:
0 - BCJ + LZMA
@@ -71,7 +71,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;
size_t outPropsSize = 5;
SRes curRes;
- Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
+ BoolInt curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
if (curModeIsFiltered && !bestIsFiltered)
break;
if (useFilter && i == 0)
diff --git a/C/LzmaDec.c b/C/LzmaDec.c
index cccb9326..ba3e1dd5 100644
--- a/C/LzmaDec.c
+++ b/C/LzmaDec.c
@@ -1,13 +1,13 @@
/* LzmaDec.c -- LZMA Decoder
-2018-02-28 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
+#include <string.h>
+
/* #include "CpuArch.h" */
#include "LzmaDec.h"
-#include <string.h>
-
#define kNumTopBits 24
#define kTopValue ((UInt32)1 << kNumTopBits)
@@ -19,7 +19,7 @@
#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
-#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define IF_BIT_0(p) ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
#define UPDATE_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
@@ -66,7 +66,7 @@
#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
-#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
+#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * (UInt32)ttt; if (code < bound)
#define UPDATE_0_CHECK range = bound;
#define UPDATE_1_CHECK range -= bound; code -= bound;
#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
@@ -539,7 +539,7 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
curLen = ((rem < len) ? (unsigned)rem : len);
pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
- processedPos += curLen;
+ processedPos += (UInt32)curLen;
len -= curLen;
if (curLen <= dicBufSize - pos)
@@ -547,7 +547,7 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
Byte *dest = dic + dicPos;
ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
const Byte *lim = dest + curLen;
- dicPos += curLen;
+ dicPos += (SizeT)curLen;
do
*(dest) = (Byte)*(dest + src);
while (++dest != lim);
@@ -572,14 +572,14 @@ int MY_FAST_CALL LZMA_DECODE_REAL(CLzmaDec *p, SizeT limit, const Byte *bufLimit
p->buf = buf;
p->range = range;
p->code = code;
- p->remainLen = len;
+ p->remainLen = (UInt32)len;
p->dicPos = dicPos;
p->processedPos = processedPos;
p->reps[0] = rep0;
p->reps[1] = rep1;
p->reps[2] = rep2;
p->reps[3] = rep3;
- p->state = state;
+ p->state = (UInt32)state;
return SZ_OK;
}
@@ -601,8 +601,8 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
p->checkDicSize = p->prop.dicSize;
- p->processedPos += len;
- p->remainLen -= len;
+ p->processedPos += (UInt32)len;
+ p->remainLen -= (UInt32)len;
while (len != 0)
{
len--;
@@ -850,7 +850,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
}
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
+void LzmaDec_InitDicAndState(CLzmaDec *p, BoolInt initDic, BoolInt initState)
{
p->remainLen = kMatchSpecLenStart + 1;
p->tempBufSize = 0;
@@ -979,10 +979,10 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
p->tempBufSize = rem;
if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
{
- int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
+ int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, (SizeT)rem);
if (dummyRes == DUMMY_ERROR)
{
- (*srcLen) += lookAhead;
+ (*srcLen) += (SizeT)lookAhead;
*status = LZMA_STATUS_NEEDS_MORE_INPUT;
return SZ_OK;
}
@@ -1005,9 +1005,9 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
return SZ_ERROR_FAIL; /* some internal error */
lookAhead -= rem;
}
- (*srcLen) += lookAhead;
+ (*srcLen) += (SizeT)lookAhead;
src += lookAhead;
- inSize -= lookAhead;
+ inSize -= (SizeT)lookAhead;
p->tempBufSize = 0;
}
}
diff --git a/C/LzmaEnc.c b/C/LzmaEnc.c
index 24e58264..d78dbe12 100644
--- a/C/LzmaEnc.c
+++ b/C/LzmaEnc.c
@@ -1,5 +1,5 @@
/* LzmaEnc.c -- LZMA Encoder
-2018-04-29 : Igor Pavlov : Public domain */
+2018-12-29: Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -38,6 +38,8 @@ static unsigned g_STAT_OFFSET = 0;
#define kNumBitPriceShiftBits 4
#define kBitPrice (1 << kNumBitPriceShiftBits)
+#define REP_LEN_COUNT 64
+
void LzmaEncProps_Init(CLzmaEncProps *p)
{
p->level = 5;
@@ -183,8 +185,11 @@ typedef struct
} COptimal;
-#define kNumOpts (1 << 12)
-#define kPackReserve (1 + kNumOpts * 2)
+// 18.06
+#define kNumOpts (1 << 11)
+#define kPackReserve (kNumOpts * 8)
+// #define kNumOpts (1 << 12)
+// #define kPackReserve (1 + kNumOpts * 2)
#define kNumLenToPosStates 4
#define kNumPosSlotBits 6
@@ -236,10 +241,18 @@ typedef struct
typedef struct
{
unsigned tableSize;
- unsigned counters[LZMA_NUM_PB_STATES_MAX];
UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal];
+ // UInt32 prices1[LZMA_NUM_PB_STATES_MAX][kLenNumLowSymbols * 2];
+ // UInt32 prices2[kLenNumSymbolsTotal];
} CLenPriceEnc;
+#define GET_PRICE_LEN(p, posState, len) \
+ ((p)->prices[posState][(size_t)(len) - LZMA_MATCH_LEN_MIN])
+
+/*
+#define GET_PRICE_LEN(p, posState, len) \
+ ((p)->prices2[(size_t)(len) - 2] + ((p)->prices1[posState][((len) - 2) & (kLenNumLowSymbols * 2 - 1)] & (((len) - 2 - kLenNumLowSymbols * 2) >> 9)))
+*/
typedef struct
{
@@ -308,16 +321,18 @@ typedef struct
unsigned lc, lp, pb;
unsigned lclp;
- Bool fastMode;
- Bool writeEndMark;
- Bool finished;
- Bool multiThread;
- Bool needInit;
+ BoolInt fastMode;
+ BoolInt writeEndMark;
+ BoolInt finished;
+ BoolInt multiThread;
+ BoolInt needInit;
+ // BoolInt _maxMode;
UInt64 nowPos64;
unsigned matchPriceCount;
- unsigned alignPriceCount;
+ // unsigned alignPriceCount;
+ int repLenEncCounter;
unsigned distTableSize;
@@ -325,7 +340,7 @@ typedef struct
SRes result;
#ifndef _7ZIP_ST
- Bool mtMode;
+ BoolInt mtMode;
// begin of CMatchFinderMt is used in LZ thread
CMatchFinderMt matchFinderMt;
// end of CMatchFinderMt is used in BT and HASH threads
@@ -458,6 +473,7 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
p->lp = props.lp;
p->pb = props.pb;
p->fastMode = (props.algo == 0);
+ // p->_maxMode = True;
p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0);
{
unsigned numHashBytes = 4;
@@ -618,9 +634,9 @@ static void RangeEnc_FlushData(CRangeEnc *p)
#ifdef _LZMA_ENC_USE_BRANCH
-#define RC_BIT(p, prob, symbol) { \
+#define RC_BIT(p, prob, bit) { \
RC_BIT_PRE(p, prob) \
- if (symbol == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
+ if (bit == 0) { range = newBound; ttt += (kBitModelTotal - ttt) >> kNumMoveBits; } \
else { (p)->low += newBound; range -= newBound; ttt -= ttt >> kNumMoveBits; } \
*(prob) = (CLzmaProb)ttt; \
RC_NORM(p) \
@@ -628,15 +644,15 @@ static void RangeEnc_FlushData(CRangeEnc *p)
#else
-#define RC_BIT(p, prob, symbol) { \
+#define RC_BIT(p, prob, bit) { \
UInt32 mask; \
RC_BIT_PRE(p, prob) \
- mask = 0 - (UInt32)symbol; \
+ mask = 0 - (UInt32)bit; \
range &= mask; \
mask &= newBound; \
range -= mask; \
(p)->low += mask; \
- mask = (UInt32)symbol - 1; \
+ mask = (UInt32)bit - 1; \
range += newBound & mask; \
mask &= (kBitModelTotal - ((1 << kNumMoveBits) - 1)); \
mask += ((1 << kNumMoveBits) - 1); \
@@ -673,42 +689,42 @@ static void RangeEnc_EncodeBit_0(CRangeEnc *p, CLzmaProb *prob)
p->range = range;
}
-static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
+static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 sym)
{
UInt32 range = p->range;
- symbol |= 0x100;
+ sym |= 0x100;
do
{
UInt32 ttt, newBound;
- // RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
- CLzmaProb *prob = probs + (symbol >> 8);
- UInt32 bit = (symbol >> 7) & 1;
- symbol <<= 1;
+ // RangeEnc_EncodeBit(p, probs + (sym >> 8), (sym >> 7) & 1);
+ CLzmaProb *prob = probs + (sym >> 8);
+ UInt32 bit = (sym >> 7) & 1;
+ sym <<= 1;
RC_BIT(p, prob, bit);
}
- while (symbol < 0x10000);
+ while (sym < 0x10000);
p->range = range;
}
-static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte)
+static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 sym, UInt32 matchByte)
{
UInt32 range = p->range;
UInt32 offs = 0x100;
- symbol |= 0x100;
+ sym |= 0x100;
do
{
UInt32 ttt, newBound;
CLzmaProb *prob;
UInt32 bit;
matchByte <<= 1;
- // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
- prob = probs + (offs + (matchByte & offs) + (symbol >> 8));
- bit = (symbol >> 7) & 1;
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
+ // RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (sym >> 8)), (sym >> 7) & 1);
+ prob = probs + (offs + (matchByte & offs) + (sym >> 8));
+ bit = (sym >> 7) & 1;
+ sym <<= 1;
+ offs &= ~(matchByte ^ sym);
RC_BIT(p, prob, bit);
}
- while (symbol < 0x10000);
+ while (sym < 0x10000);
p->range = range;
}
@@ -739,11 +755,11 @@ static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
}
-#define GET_PRICE(prob, symbol) \
- p->ProbPrices[((prob) ^ (unsigned)(((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+#define GET_PRICE(prob, bit) \
+ p->ProbPrices[((prob) ^ (unsigned)(((-(int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
-#define GET_PRICEa(prob, symbol) \
- ProbPrices[((prob) ^ (unsigned)((-((int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
+#define GET_PRICEa(prob, bit) \
+ ProbPrices[((prob) ^ (unsigned)((-((int)(bit))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
#define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
#define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
@@ -752,48 +768,48 @@ static void LzmaEnc_InitPriceTables(CProbPrice *ProbPrices)
#define GET_PRICEa_1(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
-static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, const CProbPrice *ProbPrices)
+static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 sym, const CProbPrice *ProbPrices)
{
UInt32 price = 0;
- symbol |= 0x100;
+ sym |= 0x100;
do
{
- unsigned bit = symbol & 1;
- symbol >>= 1;
- price += GET_PRICEa(probs[symbol], bit);
+ unsigned bit = sym & 1;
+ sym >>= 1;
+ price += GET_PRICEa(probs[sym], bit);
}
- while (symbol >= 2);
+ while (sym >= 2);
return price;
}
-static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, const CProbPrice *ProbPrices)
+static UInt32 LitEnc_Matched_GetPrice(const CLzmaProb *probs, UInt32 sym, UInt32 matchByte, const CProbPrice *ProbPrices)
{
UInt32 price = 0;
UInt32 offs = 0x100;
- symbol |= 0x100;
+ sym |= 0x100;
do
{
matchByte <<= 1;
- price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
- symbol <<= 1;
- offs &= ~(matchByte ^ symbol);
+ price += GET_PRICEa(probs[offs + (matchByte & offs) + (sym >> 8)], (sym >> 7) & 1);
+ sym <<= 1;
+ offs &= ~(matchByte ^ sym);
}
- while (symbol < 0x10000);
+ while (sym < 0x10000);
return price;
}
-static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, UInt32 symbol)
+static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, unsigned numBits, unsigned sym)
{
UInt32 range = rc->range;
unsigned m = 1;
do
{
UInt32 ttt, newBound;
- unsigned bit = symbol & 1;
+ unsigned bit = sym & 1;
// RangeEnc_EncodeBit(rc, probs + m, bit);
- symbol >>= 1;
+ sym >>= 1;
RC_BIT(rc, probs + m, bit);
m = (m << 1) | bit;
}
@@ -812,37 +828,37 @@ static void LenEnc_Init(CLenEnc *p)
p->high[i] = kProbInitValue;
}
-static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned symbol, unsigned posState)
+static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, unsigned sym, unsigned posState)
{
UInt32 range, ttt, newBound;
CLzmaProb *probs = p->low;
range = rc->range;
RC_BIT_PRE(rc, probs);
- if (symbol >= kLenNumLowSymbols)
+ if (sym >= kLenNumLowSymbols)
{
RC_BIT_1(rc, probs);
probs += kLenNumLowSymbols;
RC_BIT_PRE(rc, probs);
- if (symbol >= kLenNumLowSymbols * 2)
+ if (sym >= kLenNumLowSymbols * 2)
{
RC_BIT_1(rc, probs);
rc->range = range;
- // RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols * 2);
- LitEnc_Encode(rc, p->high, symbol - kLenNumLowSymbols * 2);
+ // RcTree_Encode(rc, p->high, kLenNumHighBits, sym - kLenNumLowSymbols * 2);
+ LitEnc_Encode(rc, p->high, sym - kLenNumLowSymbols * 2);
return;
}
- symbol -= kLenNumLowSymbols;
+ sym -= kLenNumLowSymbols;
}
- // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, symbol);
+ // RcTree_Encode(rc, probs + (posState << kLenNumLowBits), kLenNumLowBits, sym);
{
unsigned m;
unsigned bit;
RC_BIT_0(rc, probs);
probs += (posState << (1 + kLenNumLowBits));
- bit = (symbol >> 2) ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit;
- bit = (symbol >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit;
- bit = symbol & 1; RC_BIT(rc, probs + m, bit);
+ bit = (sym >> 2) ; RC_BIT(rc, probs + 1, bit); m = (1 << 1) + bit;
+ bit = (sym >> 1) & 1; RC_BIT(rc, probs + m, bit); m = (m << 1) + bit;
+ bit = sym & 1; RC_BIT(rc, probs + m, bit);
rc->range = range;
}
}
@@ -863,50 +879,93 @@ static void SetPrices_3(const CLzmaProb *probs, UInt32 startPrice, UInt32 *price
}
-MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTable(
- CLenPriceEnc *p, unsigned posState,
+MY_NO_INLINE static void MY_FAST_CALL LenPriceEnc_UpdateTables(
+ CLenPriceEnc *p,
+ unsigned numPosStates,
const CLenEnc *enc,
const CProbPrice *ProbPrices)
{
- // int y; for (y = 0; y < 100; y++) {
- UInt32 a;
- unsigned i, numSymbols;
+ UInt32 b;
+
+ {
+ unsigned prob = enc->low[0];
+ UInt32 a, c;
+ unsigned posState;
+ b = GET_PRICEa_1(prob);
+ a = GET_PRICEa_0(prob);
+ c = b + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
+ for (posState = 0; posState < numPosStates; posState++)
+ {
+ UInt32 *prices = p->prices[posState];
+ const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
+ SetPrices_3(probs, a, prices, ProbPrices);
+ SetPrices_3(probs + kLenNumLowSymbols, c, prices + kLenNumLowSymbols, ProbPrices);
+ }
+ }
- UInt32 *prices = p->prices[posState];
+ /*
{
- const CLzmaProb *probs = enc->low + (posState << (1 + kLenNumLowBits));
- SetPrices_3(probs, GET_PRICEa_0(enc->low[0]), prices, ProbPrices);
+ unsigned i;
+ UInt32 b;
+ a = GET_PRICEa_0(enc->low[0]);
+ for (i = 0; i < kLenNumLowSymbols; i++)
+ p->prices2[i] = a;
a = GET_PRICEa_1(enc->low[0]);
- SetPrices_3(probs + kLenNumLowSymbols, a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]), prices + kLenNumLowSymbols, ProbPrices);
+ b = a + GET_PRICEa_0(enc->low[kLenNumLowSymbols]);
+ for (i = kLenNumLowSymbols; i < kLenNumLowSymbols * 2; i++)
+ p->prices2[i] = b;
a += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
}
- numSymbols = p->tableSize;
- p->counters[posState] = numSymbols;
- for (i = kLenNumLowSymbols * 2; i < numSymbols; i += 1)
+ */
+
+ // p->counter = numSymbols;
+ // p->counter = 64;
+
{
- prices[i] = a +
- // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
- LitEnc_GetPrice(enc->high, i - kLenNumLowSymbols * 2, ProbPrices);
- /*
- unsigned sym = (i - kLenNumLowSymbols * 2) >> 1;
- UInt32 price = a + RcTree_GetPrice(enc->high, kLenNumHighBits - 1, sym, ProbPrices);
- UInt32 prob = enc->high[(1 << 7) + sym];
- prices[i ] = price + GET_PRICEa_0(prob);
- prices[i + 1] = price + GET_PRICEa_1(prob);
- */
- }
- // }
-}
+ unsigned i = p->tableSize;
+
+ if (i > kLenNumLowSymbols * 2)
+ {
+ const CLzmaProb *probs = enc->high;
+ UInt32 *prices = p->prices[0] + kLenNumLowSymbols * 2;
+ i -= kLenNumLowSymbols * 2 - 1;
+ i >>= 1;
+ b += GET_PRICEa_1(enc->low[kLenNumLowSymbols]);
+ do
+ {
+ /*
+ p->prices2[i] = a +
+ // RcTree_GetPrice(enc->high, kLenNumHighBits, i - kLenNumLowSymbols * 2, ProbPrices);
+ LitEnc_GetPrice(probs, i - kLenNumLowSymbols * 2, ProbPrices);
+ */
+ // UInt32 price = a + RcTree_GetPrice(probs, kLenNumHighBits - 1, sym, ProbPrices);
+ unsigned sym = --i + (1 << (kLenNumHighBits - 1));
+ UInt32 price = b;
+ do
+ {
+ unsigned bit = sym & 1;
+ sym >>= 1;
+ price += GET_PRICEa(probs[sym], bit);
+ }
+ while (sym >= 2);
-static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, unsigned numPosStates,
- const CLenEnc *enc,
- const CProbPrice *ProbPrices)
-{
- unsigned posState;
- for (posState = 0; posState < numPosStates; posState++)
- LenPriceEnc_UpdateTable(p, posState, enc, ProbPrices);
-}
+ {
+ unsigned prob = probs[(size_t)i + (1 << (kLenNumHighBits - 1))];
+ prices[(size_t)i * 2 ] = price + GET_PRICEa_0(prob);
+ prices[(size_t)i * 2 + 1] = price + GET_PRICEa_1(prob);
+ }
+ }
+ while (i);
+ {
+ unsigned posState;
+ size_t num = (p->tableSize - kLenNumLowSymbols * 2) * sizeof(p->prices[0][0]);
+ for (posState = 1; posState < numPosStates; posState++)
+ memcpy(p->prices[posState] + kLenNumLowSymbols * 2, p->prices[0] + kLenNumLowSymbols * 2, num);
+ }
+ }
+ }
+}
/*
#ifdef SHOW_STAT
@@ -917,7 +976,7 @@ static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, unsigned numPosStates,
#define MOVE_POS(p, num) { \
p->additionalOffset += (num); \
- p->matchFinder.Skip(p->matchFinderObj, (num)); }
+ p->matchFinder.Skip(p->matchFinderObj, (UInt32)(num)); }
static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes)
@@ -954,7 +1013,8 @@ static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes)
const Byte *p2 = p1 + len;
ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[(size_t)numPairs - 1];
const Byte *lim = p1 + numAvail;
- for (; p2 != lim && *p2 == p2[dif]; p2++);
+ for (; p2 != lim && *p2 == p2[dif]; p2++)
+ {}
return (unsigned)(p2 - p1);
}
}
@@ -977,7 +1037,7 @@ static unsigned ReadMatchDistances(CLzmaEnc *p, unsigned *numPairsRes)
+ GET_PRICE_1(p->isRep[state]) \
+ GET_PRICE_0(p->isRepG0[state])
-
+MY_FORCE_INLINE
static UInt32 GetPrice_PureRep(const CLzmaEnc *p, unsigned repIndex, size_t state, size_t posState)
{
UInt32 price;
@@ -1011,14 +1071,14 @@ static unsigned Backward(CLzmaEnc *p, unsigned cur)
for (;;)
{
UInt32 dist = p->opt[cur].dist;
- UInt32 len = p->opt[cur].len;
- UInt32 extra = p->opt[cur].extra;
+ unsigned len = (unsigned)p->opt[cur].len;
+ unsigned extra = (unsigned)p->opt[cur].extra;
cur -= len;
if (extra)
{
wr--;
- p->opt[wr].len = len;
+ p->opt[wr].len = (UInt32)len;
cur -= extra;
len = extra;
if (extra == 1)
@@ -1045,7 +1105,7 @@ static unsigned Backward(CLzmaEnc *p, unsigned cur)
wr--;
p->opt[wr].dist = dist;
- p->opt[wr].len = len;
+ p->opt[wr].len = (UInt32)len;
}
}
@@ -1102,7 +1162,8 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
repLens[i] = 0;
continue;
}
- for (len = 2; len < numAvail && data[len] == data2[len]; len++);
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++)
+ {}
repLens[i] = len;
if (len > repLens[repMaxIndex])
repMaxIndex = i;
@@ -1111,7 +1172,7 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
if (repLens[repMaxIndex] >= p->numFastBytes)
{
unsigned len;
- p->backRes = repMaxIndex;
+ p->backRes = (UInt32)repMaxIndex;
len = repLens[repMaxIndex];
MOVE_POS(p, len - 1)
return len;
@@ -1128,8 +1189,12 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
curByte = *data;
matchByte = *(data - reps[0]);
+
+ last = repLens[repMaxIndex];
+ if (last <= mainLen)
+ last = mainLen;
- if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)
+ if (last < 2 && curByte != matchByte)
{
p->backRes = MARK_LIT;
return 1;
@@ -1146,13 +1211,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
LitEnc_Matched_GetPrice(probs, curByte, matchByte, p->ProbPrices) :
LitEnc_GetPrice(probs, curByte, p->ProbPrices));
}
-
+
MakeAs_Lit(&p->opt[1]);
matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
- if (matchByte == curByte)
+ // 18.06
+ if (matchByte == curByte && repLens[0] == 0)
{
UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, p->state, posState);
if (shortRepPrice < p->opt[1].price)
@@ -1160,16 +1226,13 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
p->opt[1].price = shortRepPrice;
MakeAs_ShortRep(&p->opt[1]);
}
+ if (last < 2)
+ {
+ p->backRes = p->opt[1].dist;
+ return 1;
+ }
}
-
- last = (mainLen >= repLens[repMaxIndex] ? mainLen : repLens[repMaxIndex]);
-
- if (last < 2)
- {
- p->backRes = p->opt[1].dist;
- return 1;
- }
-
+
p->opt[1].len = 1;
p->opt[0].reps[0] = reps[0];
@@ -1177,13 +1240,6 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
p->opt[0].reps[2] = reps[2];
p->opt[0].reps[3] = reps[3];
- {
- unsigned len = last;
- do
- p->opt[len--].price = kInfinityPrice;
- while (len >= 2);
- }
-
// ---------- REP ----------
for (i = 0; i < LZMA_NUM_REPS; i++)
@@ -1195,13 +1251,13 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
price = repMatchPrice + GetPrice_PureRep(p, i, p->state, posState);
do
{
- UInt32 price2 = price + p->repLenEnc.prices[posState][(size_t)repLen - 2];
+ UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, repLen);
COptimal *opt = &p->opt[repLen];
if (price2 < opt->price)
{
opt->price = price2;
- opt->len = repLen;
- opt->dist = i;
+ opt->len = (UInt32)repLen;
+ opt->dist = (UInt32)i;
opt->extra = 0;
}
}
@@ -1211,38 +1267,41 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
// ---------- MATCH ----------
{
- unsigned len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
+ unsigned len = repLens[0] + 1;
if (len <= mainLen)
{
unsigned offs = 0;
UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
- while (len > matches[offs])
- offs += 2;
+ if (len < 2)
+ len = 2;
+ else
+ while (len > matches[offs])
+ offs += 2;
for (; ; len++)
{
COptimal *opt;
UInt32 dist = matches[(size_t)offs + 1];
- UInt32 price2 = normalMatchPrice + p->lenEnc.prices[posState][(size_t)len - LZMA_MATCH_LEN_MIN];
+ UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len);
unsigned lenToPosState = GetLenToPosState(len);
if (dist < kNumFullDistances)
- price2 += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)];
+ price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)];
else
{
unsigned slot;
GetPosSlot2(dist, slot);
- price2 += p->alignPrices[dist & kAlignMask];
- price2 += p->posSlotPrices[lenToPosState][slot];
+ price += p->alignPrices[dist & kAlignMask];
+ price += p->posSlotPrices[lenToPosState][slot];
}
opt = &p->opt[len];
- if (price2 < opt->price)
+ if (price < opt->price)
{
- opt->price = price2;
- opt->len = len;
+ opt->price = price;
+ opt->len = (UInt32)len;
opt->dist = dist + LZMA_NUM_REPS;
opt->extra = 0;
}
@@ -1277,16 +1336,43 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
for (;;)
{
- UInt32 numAvail, numAvailFull;
+ unsigned numAvail;
+ UInt32 numAvailFull;
unsigned newLen, numPairs, prev, state, posState, startLen;
- UInt32 curPrice, litPrice, matchPrice, repMatchPrice;
- Bool nextIsLit;
+ UInt32 litPrice, matchPrice, repMatchPrice;
+ BoolInt nextIsLit;
Byte curByte, matchByte;
const Byte *data;
COptimal *curOpt, *nextOpt;
if (++cur == last)
- return Backward(p, cur);
+ break;
+
+ // 18.06
+ if (cur >= kNumOpts - 64)
+ {
+ unsigned j, best;
+ UInt32 price = p->opt[cur].price;
+ best = cur;
+ for (j = cur + 1; j <= last; j++)
+ {
+ UInt32 price2 = p->opt[j].price;
+ if (price >= price2)
+ {
+ price = price2;
+ best = j;
+ }
+ }
+ {
+ unsigned delta = best - cur;
+ if (delta != 0)
+ {
+ MOVE_POS(p, delta);
+ }
+ }
+ cur = best;
+ break;
+ }
newLen = ReadMatchDistances(p, &numPairs);
@@ -1294,15 +1380,24 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
{
p->numPairs = numPairs;
p->longestMatchLen = newLen;
- return Backward(p, cur);
+ break;
}
curOpt = &p->opt[cur];
+
+ position++;
+
+ // we need that check here, if skip_items in p->opt are possible
+ /*
+ if (curOpt->price >= kInfinityPrice)
+ continue;
+ */
+
prev = cur - curOpt->len;
-
+
if (curOpt->len == 1)
{
- state = p->opt[prev].state;
+ state = (unsigned)p->opt[prev].state;
if (IsShortRep(curOpt))
state = kShortRepNextStates[state];
else
@@ -1316,14 +1411,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
if (curOpt->extra)
{
- prev -= curOpt->extra;
+ prev -= (unsigned)curOpt->extra;
state = kState_RepAfterLit;
if (curOpt->extra == 1)
- state = (dist < LZMA_NUM_REPS) ? kState_RepAfterLit : kState_MatchAfterLit;
+ state = (dist < LZMA_NUM_REPS ? kState_RepAfterLit : kState_MatchAfterLit);
}
else
{
- state = p->opt[prev].state;
+ state = (unsigned)p->opt[prev].state;
if (dist < LZMA_NUM_REPS)
state = kRepNextStates[state];
else
@@ -1379,7 +1474,6 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
curByte = *data;
matchByte = *(data - reps[0]);
- position++;
posState = (position & p->pbMask);
/*
@@ -1391,13 +1485,25 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
< MATCH [ : LIT : REP_0 ]
*/
- curPrice = curOpt->price;
- litPrice = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
+ {
+ UInt32 curPrice = curOpt->price;
+ unsigned prob = p->isMatch[state][posState];
+ matchPrice = curPrice + GET_PRICE_1(prob);
+ litPrice = curPrice + GET_PRICE_0(prob);
+ }
nextOpt = &p->opt[(size_t)cur + 1];
nextIsLit = False;
- // if (litPrice >= nextOpt->price) litPrice = 0; else // 18.new
+ // here we can allow skip_items in p->opt, if we don't check (nextOpt->price < kInfinityPrice)
+ // 18.new.06
+ if (nextOpt->price < kInfinityPrice
+ // && !IsLitState(state)
+ && matchByte == curByte
+ || litPrice > nextOpt->price
+ )
+ litPrice = 0;
+ else
{
const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
litPrice += (!IsLitState(state) ?
@@ -1413,21 +1519,32 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
}
}
- matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
+ numAvailFull = p->numAvail;
+ {
+ unsigned temp = kNumOpts - 1 - cur;
+ if (numAvailFull > temp)
+ numAvailFull = (UInt32)temp;
+ }
+
+ // 18.06
// ---------- SHORT_REP ----------
- // if (IsLitState(state)) // 18.new
+ if (IsLitState(state)) // 18.new
if (matchByte == curByte)
- // if (repMatchPrice < nextOpt->price) // 18.new
- if (nextOpt->len < 2
+ if (repMatchPrice < nextOpt->price) // 18.new
+ // if (numAvailFull < 2 || data[1] != *(data - reps[0] + 1))
+ if (
+ // nextOpt->price >= kInfinityPrice ||
+ nextOpt->len < 2 // we can check nextOpt->len, if skip items are not allowed in p->opt
|| (nextOpt->dist != 0
- && nextOpt->extra <= 1 // 17.old
- ))
+ // && nextOpt->extra <= 1 // 17.old
+ )
+ )
{
UInt32 shortRepPrice = repMatchPrice + GetPrice_ShortRep(p, state, posState);
- if (shortRepPrice <= nextOpt->price) // 17.old
- // if (shortRepPrice < nextOpt->price) // 18.new
+ // if (shortRepPrice <= nextOpt->price) // 17.old
+ if (shortRepPrice < nextOpt->price) // 18.new
{
nextOpt->price = shortRepPrice;
nextOpt->len = 1;
@@ -1436,13 +1553,6 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
}
}
- numAvailFull = p->numAvail;
- {
- UInt32 temp = kNumOpts - 1 - cur;
- if (numAvailFull > temp)
- numAvailFull = temp;
- }
-
if (numAvailFull < 2)
continue;
numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
@@ -1451,9 +1561,8 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
// ---------- LIT : REP_0 ----------
- if (
- // litPrice != 0 && // 18.new
- !nextIsLit
+ if (!nextIsLit
+ && litPrice != 0 // 18.new
&& matchByte != curByte
&& numAvailFull > 2)
{
@@ -1464,7 +1573,8 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
unsigned limit = p->numFastBytes + 1;
if (limit > numAvailFull)
limit = numAvailFull;
- for (len = 3; len < limit && data[len] == data2[len]; len++);
+ for (len = 3; len < limit && data[len] == data2[len]; len++)
+ {}
{
unsigned state2 = kLiteralNextStates[state];
@@ -1472,8 +1582,9 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
UInt32 price = litPrice + GetPrice_Rep_0(p, state2, posState2);
{
unsigned offset = cur + len;
- while (last < offset)
- p->opt[++last].price = kInfinityPrice;
+
+ if (last < offset)
+ last = offset;
// do
{
@@ -1481,14 +1592,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
COptimal *opt;
len--;
// price2 = price + GetPrice_Len_Rep_0(p, len, state2, posState2);
- price2 = price + p->repLenEnc.prices[posState2][len - LZMA_MATCH_LEN_MIN];
+ price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len);
opt = &p->opt[offset];
// offset--;
if (price2 < opt->price)
{
opt->price = price2;
- opt->len = len;
+ opt->len = (UInt32)len;
opt->dist = 0;
opt->extra = 1;
}
@@ -1500,6 +1611,7 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
}
startLen = 2; /* speed optimization */
+
{
// ---------- REP ----------
unsigned repIndex = 0; // 17.old
@@ -1512,24 +1624,28 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
if (data[0] != data2[0] || data[1] != data2[1])
continue;
- for (len = 2; len < numAvail && data[len] == data2[len]; len++);
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++)
+ {}
// if (len < startLen) continue; // 18.new: speed optimization
- while (last < cur + len)
- p->opt[++last].price = kInfinityPrice;
+ {
+ unsigned offset = cur + len;
+ if (last < offset)
+ last = offset;
+ }
{
unsigned len2 = len;
price = repMatchPrice + GetPrice_PureRep(p, repIndex, state, posState);
do
{
- UInt32 price2 = price + p->repLenEnc.prices[posState][(size_t)len2 - 2];
+ UInt32 price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState, len2);
COptimal *opt = &p->opt[cur + len2];
if (price2 < opt->price)
{
opt->price = price2;
- opt->len = len2;
- opt->dist = repIndex;
+ opt->len = (UInt32)len2;
+ opt->dist = (UInt32)repIndex;
opt->extra = 0;
}
}
@@ -1549,15 +1665,14 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
if (limit > numAvailFull)
limit = numAvailFull;
- for (; len2 < limit && data[len2] == data2[len2]; len2++);
-
- len2 -= len;
- if (len2 >= 3)
+ len2 += 2;
+ if (len2 <= limit)
+ if (data[len2 - 2] == data2[len2 - 2])
+ if (data[len2 - 1] == data2[len2 - 1])
{
unsigned state2 = kRepNextStates[state];
unsigned posState2 = (position + len) & p->pbMask;
- price +=
- p->repLenEnc.prices[posState][(size_t)len - 2]
+ price += GET_PRICE_LEN(&p->repLenEnc, posState, len)
+ GET_PRICE_0(p->isMatch[state2][posState2])
+ LitEnc_Matched_GetPrice(LIT_PROBS(position + len, data[(size_t)len - 1]),
data[len], data2[len], p->ProbPrices);
@@ -1568,31 +1683,40 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
price += GetPrice_Rep_0(p, state2, posState2);
+
+ for (; len2 < limit && data[len2] == data2[len2]; len2++)
+ {}
+
+ len2 -= len;
+ // if (len2 >= 3)
+ {
{
unsigned offset = cur + len + len2;
- while (last < offset)
- p->opt[++last].price = kInfinityPrice;
+
+ if (last < offset)
+ last = offset;
// do
{
- unsigned price2;
+ UInt32 price2;
COptimal *opt;
len2--;
// price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2);
- price2 = price + p->repLenEnc.prices[posState2][len2 - LZMA_MATCH_LEN_MIN];
+ price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2);
opt = &p->opt[offset];
// offset--;
if (price2 < opt->price)
{
opt->price = price2;
- opt->len = len2;
+ opt->len = (UInt32)len2;
opt->extra = (CExtra)(len + 1);
- opt->dist = repIndex;
+ opt->dist = (UInt32)repIndex;
}
}
// while (len2 >= 3);
}
}
+ }
}
}
}
@@ -1604,17 +1728,23 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
{
newLen = numAvail;
for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);
- matches[numPairs] = newLen;
+ matches[numPairs] = (UInt32)newLen;
numPairs += 2;
}
+ // startLen = 2; /* speed optimization */
+
if (newLen >= startLen)
{
UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]);
UInt32 dist;
unsigned offs, posSlot, len;
- while (last < cur + newLen)
- p->opt[++last].price = kInfinityPrice;
+
+ {
+ unsigned offset = cur + newLen;
+ if (last < offset)
+ last = offset;
+ }
offs = 0;
while (startLen > matches[offs])
@@ -1626,27 +1756,29 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
for (len = /*2*/ startLen; ; len++)
{
- UInt32 price = normalMatchPrice + p->lenEnc.prices[posState][(size_t)len - LZMA_MATCH_LEN_MIN];
+ UInt32 price = normalMatchPrice + GET_PRICE_LEN(&p->lenEnc, posState, len);
{
COptimal *opt;
- unsigned lenToPosState = len - 2; lenToPosState = GetLenToPosState2(lenToPosState);
+ unsigned lenNorm = len - 2;
+ lenNorm = GetLenToPosState2(lenNorm);
if (dist < kNumFullDistances)
- price += p->distancesPrices[lenToPosState][dist & (kNumFullDistances - 1)];
+ price += p->distancesPrices[lenNorm][dist & (kNumFullDistances - 1)];
else
- price += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[dist & kAlignMask];
+ price += p->posSlotPrices[lenNorm][posSlot] + p->alignPrices[dist & kAlignMask];
opt = &p->opt[cur + len];
if (price < opt->price)
{
opt->price = price;
- opt->len = len;
+ opt->len = (UInt32)len;
opt->dist = dist + LZMA_NUM_REPS;
opt->extra = 0;
}
}
- if (/*_maxMode && */ len == matches[offs])
+ if (len == matches[offs])
{
+ // if (p->_maxMode) {
// MATCH : LIT : REP_0
const Byte *data2 = data - dist - 1;
@@ -1655,11 +1787,17 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
if (limit > numAvailFull)
limit = numAvailFull;
- for (; len2 < limit && data[len2] == data2[len2]; len2++);
+ len2 += 2;
+ if (len2 <= limit)
+ if (data[len2 - 2] == data2[len2 - 2])
+ if (data[len2 - 1] == data2[len2 - 1])
+ {
+ for (; len2 < limit && data[len2] == data2[len2]; len2++)
+ {}
len2 -= len;
- if (len2 >= 3)
+ // if (len2 >= 3)
{
unsigned state2 = kMatchNextStates[state];
unsigned posState2 = (position + len) & p->pbMask;
@@ -1675,27 +1813,30 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
price += GetPrice_Rep_0(p, state2, posState2);
offset = cur + len + len2;
- while (last < offset)
- p->opt[++last].price = kInfinityPrice;
+
+ if (last < offset)
+ last = offset;
// do
{
UInt32 price2;
COptimal *opt;
len2--;
// price2 = price + GetPrice_Len_Rep_0(p, len2, state2, posState2);
- price2 = price + p->repLenEnc.prices[posState2][len2 - LZMA_MATCH_LEN_MIN];
+ price2 = price + GET_PRICE_LEN(&p->repLenEnc, posState2, len2);
opt = &p->opt[offset];
// offset--;
if (price2 < opt->price)
{
opt->price = price2;
- opt->len = len2;
+ opt->len = (UInt32)len2;
opt->extra = (CExtra)(len + 1);
opt->dist = dist + LZMA_NUM_REPS;
}
}
// while (len2 >= 3);
}
+
+ }
offs += 2;
if (offs == numPairs)
@@ -1707,6 +1848,12 @@ static unsigned GetOptimum(CLzmaEnc *p, UInt32 position)
}
}
}
+
+ do
+ p->opt[last].price = kInfinityPrice;
+ while (--last);
+
+ return Backward(p, cur);
}
@@ -1733,6 +1880,7 @@ static unsigned GetOptimumFast(CLzmaEnc *p)
p->backRes = MARK_LIT;
if (numAvail < 2)
return 1;
+ // if (mainLen < 2 && p->state == 0) return 1; // 18.06.notused
if (numAvail > LZMA_MATCH_LEN_MAX)
numAvail = LZMA_MATCH_LEN_MAX;
data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
@@ -1744,10 +1892,11 @@ static unsigned GetOptimumFast(CLzmaEnc *p)
const Byte *data2 = data - p->reps[i];
if (data[0] != data2[0] || data[1] != data2[1])
continue;
- for (len = 2; len < numAvail && data[len] == data2[len]; len++);
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++)
+ {}
if (len >= p->numFastBytes)
{
- p->backRes = i;
+ p->backRes = (UInt32)i;
MOVE_POS(p, len - 1)
return len;
}
@@ -1791,7 +1940,7 @@ static unsigned GetOptimumFast(CLzmaEnc *p)
|| (repLen + 2 >= mainLen && mainDist >= (1 << 9))
|| (repLen + 3 >= mainLen && mainDist >= (1 << 15)))
{
- p->backRes = repIndex;
+ p->backRes = (UInt32)repIndex;
MOVE_POS(p, repLen - 1)
return repLen;
}
@@ -1930,23 +2079,22 @@ MY_NO_INLINE static SRes Flush(CLzmaEnc *p, UInt32 nowPos)
}
-
-static void FillAlignPrices(CLzmaEnc *p)
+MY_NO_INLINE static void FillAlignPrices(CLzmaEnc *p)
{
unsigned i;
const CProbPrice *ProbPrices = p->ProbPrices;
const CLzmaProb *probs = p->posAlignEncoder;
- p->alignPriceCount = 0;
+ // p->alignPriceCount = 0;
for (i = 0; i < kAlignTableSize / 2; i++)
{
UInt32 price = 0;
- unsigned symbol = i;
+ unsigned sym = i;
unsigned m = 1;
unsigned bit;
UInt32 prob;
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) + bit;
prob = probs[m];
p->alignPrices[i ] = price + GET_PRICEa_0(prob);
p->alignPrices[i + 8] = price + GET_PRICEa_1(prob);
@@ -1955,78 +2103,97 @@ static void FillAlignPrices(CLzmaEnc *p)
}
-static void FillDistancesPrices(CLzmaEnc *p)
+MY_NO_INLINE static void FillDistancesPrices(CLzmaEnc *p)
{
+ // int y; for (y = 0; y < 100; y++) {
+
UInt32 tempPrices[kNumFullDistances];
- unsigned i, lenToPosState;
+ unsigned i, lps;
const CProbPrice *ProbPrices = p->ProbPrices;
p->matchPriceCount = 0;
- for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
+ for (i = kStartPosModelIndex / 2; i < kNumFullDistances / 2; i++)
{
unsigned posSlot = GetPosSlot1(i);
- unsigned footerBits = ((posSlot >> 1) - 1);
+ unsigned footerBits = (posSlot >> 1) - 1;
unsigned base = ((2 | (posSlot & 1)) << footerBits);
+ const CLzmaProb *probs = p->posEncoders + (size_t)base * 2;
// tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base, footerBits, i - base, p->ProbPrices);
-
- const CLzmaProb *probs = p->posEncoders + base;
UInt32 price = 0;
unsigned m = 1;
- unsigned symbol = i - base;
+ unsigned sym = i;
+ unsigned offset = (unsigned)1 << footerBits;
+ base += i;
+
+ if (footerBits)
do
{
- unsigned bit = symbol & 1;
- symbol >>= 1;
+ unsigned bit = sym & 1;
+ sym >>= 1;
price += GET_PRICEa(probs[m], bit);
m = (m << 1) + bit;
}
while (--footerBits);
- tempPrices[i] = price;
+
+ {
+ unsigned prob = probs[m];
+ tempPrices[base ] = price + GET_PRICEa_0(prob);
+ tempPrices[base + offset] = price + GET_PRICEa_1(prob);
+ }
}
- for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++)
+ for (lps = 0; lps < kNumLenToPosStates; lps++)
{
- unsigned posSlot;
- const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState];
- UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState];
- unsigned distTableSize = p->distTableSize;
- const CLzmaProb *probs = encoder;
- for (posSlot = 0; posSlot < distTableSize; posSlot += 2)
+ unsigned slot;
+ unsigned distTableSize2 = (p->distTableSize + 1) >> 1;
+ UInt32 *posSlotPrices = p->posSlotPrices[lps];
+ const CLzmaProb *probs = p->posSlotEncoder[lps];
+
+ for (slot = 0; slot < distTableSize2; slot++)
{
- // posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices);
- UInt32 price = 0;
+ // posSlotPrices[slot] = RcTree_GetPrice(encoder, kNumPosSlotBits, slot, p->ProbPrices);
+ UInt32 price;
unsigned bit;
- unsigned symbol = (posSlot >> 1) + (1 << (kNumPosSlotBits - 1));
- UInt32 prob;
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit);
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit);
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit);
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit);
- bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[symbol], bit);
- prob = probs[(posSlot >> 1) + (1 << (kNumPosSlotBits - 1))];
- posSlotPrices[posSlot ] = price + GET_PRICEa_0(prob);
- posSlotPrices[posSlot + 1] = price + GET_PRICEa_1(prob);
+ unsigned sym = slot + (1 << (kNumPosSlotBits - 1));
+ unsigned prob;
+ bit = sym & 1; sym >>= 1; price = GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ bit = sym & 1; sym >>= 1; price += GET_PRICEa(probs[sym], bit);
+ prob = probs[(size_t)slot + (1 << (kNumPosSlotBits - 1))];
+ posSlotPrices[(size_t)slot * 2 ] = price + GET_PRICEa_0(prob);
+ posSlotPrices[(size_t)slot * 2 + 1] = price + GET_PRICEa_1(prob);
}
- for (posSlot = kEndPosModelIndex; posSlot < distTableSize; posSlot++)
- posSlotPrices[posSlot] += ((UInt32)(((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
-
+
{
- UInt32 *distancesPrices = p->distancesPrices[lenToPosState];
+ UInt32 delta = ((UInt32)((kEndPosModelIndex / 2 - 1) - kNumAlignBits) << kNumBitPriceShiftBits);
+ for (slot = kEndPosModelIndex / 2; slot < distTableSize2; slot++)
{
- distancesPrices[0] = posSlotPrices[0];
- distancesPrices[1] = posSlotPrices[1];
- distancesPrices[2] = posSlotPrices[2];
- distancesPrices[3] = posSlotPrices[3];
+ posSlotPrices[(size_t)slot * 2 ] += delta;
+ posSlotPrices[(size_t)slot * 2 + 1] += delta;
+ delta += ((UInt32)1 << kNumBitPriceShiftBits);
}
+ }
+
+ {
+ UInt32 *dp = p->distancesPrices[lps];
+
+ dp[0] = posSlotPrices[0];
+ dp[1] = posSlotPrices[1];
+ dp[2] = posSlotPrices[2];
+ dp[3] = posSlotPrices[3];
+
for (i = 4; i < kNumFullDistances; i += 2)
{
UInt32 slotPrice = posSlotPrices[GetPosSlot1(i)];
- distancesPrices[i ] = slotPrice + tempPrices[i];
- distancesPrices[i + 1] = slotPrice + tempPrices[i + 1];
+ dp[i ] = slotPrice + tempPrices[i];
+ dp[i + 1] = slotPrice + tempPrices[i + 1];
}
}
}
+ // }
}
@@ -2243,10 +2410,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa
if (len != 1)
{
LenEnc_Encode(&p->repLenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState);
- if (!p->fastMode)
- if (--p->repLenEnc.counters[posState] == 0)
- LenPriceEnc_UpdateTable(&p->repLenEnc, posState, &p->repLenProbs, p->ProbPrices);
-
+ --p->repLenEncCounter;
p->state = kRepNextStates[p->state];
}
}
@@ -2258,9 +2422,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa
p->state = kMatchNextStates[p->state];
LenEnc_Encode(&p->lenProbs, &p->rc, len - LZMA_MATCH_LEN_MIN, posState);
- if (!p->fastMode)
- if (--p->lenEnc.counters[posState] == 0)
- LenPriceEnc_UpdateTable(&p->lenEnc, posState, &p->lenProbs, p->ProbPrices);
+ // --p->lenEnc.counter;
dist -= LZMA_NUM_REPS;
p->reps[3] = p->reps[2];
@@ -2272,17 +2434,17 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa
GetPosSlot(dist, posSlot);
// RcTree_Encode_PosSlot(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], posSlot);
{
- UInt32 symbol = posSlot + (1 << kNumPosSlotBits);
+ UInt32 sym = (UInt32)posSlot + (1 << kNumPosSlotBits);
range = p->rc.range;
probs = p->posSlotEncoder[GetLenToPosState(len)];
do
{
- CLzmaProb *prob = probs + (symbol >> kNumPosSlotBits);
- UInt32 bit = (symbol >> (kNumPosSlotBits - 1)) & 1;
- symbol <<= 1;
+ CLzmaProb *prob = probs + (sym >> kNumPosSlotBits);
+ UInt32 bit = (sym >> (kNumPosSlotBits - 1)) & 1;
+ sym <<= 1;
RC_BIT(&p->rc, prob, bit);
}
- while (symbol < (1 << kNumPosSlotBits * 2));
+ while (sym < (1 << kNumPosSlotBits * 2));
p->rc.range = range;
}
@@ -2293,7 +2455,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa
if (dist < kNumFullDistances)
{
unsigned base = ((2 | (posSlot & 1)) << footerBits);
- RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, dist - base);
+ RcTree_ReverseEncode(&p->rc, p->posEncoders + base, footerBits, (unsigned)(dist /* - base */));
}
else
{
@@ -2329,14 +2491,14 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa
bit = dist & 1; dist >>= 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit); m = (m << 1) + bit;
bit = dist & 1; RC_BIT(&p->rc, p->posAlignEncoder + m, bit);
p->rc.range = range;
- p->alignPriceCount++;
+ // p->alignPriceCount++;
}
}
}
}
}
- nowPos32 += len;
+ nowPos32 += (UInt32)len;
p->additionalOffset -= len;
if (p->additionalOffset == 0)
@@ -2345,10 +2507,27 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, UInt32 maxPackSize, UInt32 maxUnpa
if (!p->fastMode)
{
- if (p->matchPriceCount >= (1 << 7))
+ /*
+ if (p->alignPriceCount >= 16) // kAlignTableSize
+ FillAlignPrices(p);
+ if (p->matchPriceCount >= 128)
FillDistancesPrices(p);
- if (p->alignPriceCount >= kAlignTableSize)
+ if (p->lenEnc.counter <= 0)
+ LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
+ */
+ if (p->matchPriceCount >= 64)
+ {
FillAlignPrices(p);
+ // { int y; for (y = 0; y < 100; y++) {
+ FillDistancesPrices(p);
+ // }}
+ LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
+ }
+ if (p->repLenEncCounter <= 0)
+ {
+ p->repLenEncCounter = REP_LEN_COUNT;
+ LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices);
+ }
}
if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
@@ -2488,12 +2667,19 @@ void LzmaEnc_Init(CLzmaEnc *p)
p->optEnd = 0;
p->optCur = 0;
+
+ {
+ for (i = 0; i < kNumOpts; i++)
+ p->opt[i].price = kInfinityPrice;
+ }
+
p->additionalOffset = 0;
p->pbMask = (1 << p->pb) - 1;
p->lpMask = ((UInt32)0x100 << p->lp) - ((unsigned)0x100 >> p->lc);
}
+
void LzmaEnc_InitPrices(CLzmaEnc *p)
{
if (!p->fastMode)
@@ -2505,6 +2691,9 @@ void LzmaEnc_InitPrices(CLzmaEnc *p)
p->lenEnc.tableSize =
p->repLenEnc.tableSize =
p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
+
+ p->repLenEncCounter = REP_LEN_COUNT;
+
LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, &p->lenProbs, p->ProbPrices);
LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, &p->repLenProbs, p->ProbPrices);
}
@@ -2581,7 +2770,7 @@ typedef struct
ISeqOutStream vt;
Byte *data;
SizeT rem;
- Bool overflow;
+ BoolInt overflow;
} CLzmaEnc_SeqOutStreamBuf;
static size_t SeqOutStreamBuf_Write(const ISeqOutStream *pp, const void *data, size_t size)
@@ -2613,7 +2802,7 @@ const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
}
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, BoolInt reInit,
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
{
CLzmaEnc *p = (CLzmaEnc *)pp;
diff --git a/C/MtCoder.c b/C/MtCoder.c
index 389a70a5..95359857 100644
--- a/C/MtCoder.c
+++ b/C/MtCoder.c
@@ -1,5 +1,5 @@
/* MtCoder.c -- Multi-thread Coder
-2018-02-21 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -119,7 +119,7 @@ static SRes ThreadFunc2(CMtCoderThread *t)
unsigned bi;
SRes res;
SRes res2;
- Bool finished;
+ BoolInt finished;
unsigned bufIndex;
size_t size;
const Byte *inData;
@@ -294,7 +294,7 @@ static SRes ThreadFunc2(CMtCoderThread *t)
if (++wi >= mtc->numBlocksMax)
wi = 0;
{
- Bool isReady;
+ BoolInt isReady;
CriticalSection_Enter(&mtc->cs);
@@ -547,7 +547,7 @@ SRes MtCoder_Code(CMtCoder *p)
{
const CMtCoderBlock *block = &p->blocks[bi];
unsigned bufIndex = block->bufIndex;
- Bool finished = block->finished;
+ BoolInt finished = block->finished;
if (res == SZ_OK && block->res != SZ_OK)
res = block->res;
diff --git a/C/MtCoder.h b/C/MtCoder.h
index ed584e12..5a5f4d11 100644
--- a/C/MtCoder.h
+++ b/C/MtCoder.h
@@ -1,5 +1,5 @@
/* MtCoder.h -- Multi-thread Coder
-2018-02-21 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#ifndef __MT_CODER_H
#define __MT_CODER_H
@@ -67,7 +67,7 @@ typedef struct
{
SRes res;
unsigned bufIndex;
- Bool finished;
+ BoolInt finished;
} CMtCoderBlock;
@@ -97,7 +97,7 @@ typedef struct _CMtCoder
CAutoResetEvent readEvent;
CSemaphore blocksSemaphore;
- Bool stopReading;
+ BoolInt stopReading;
SRes readRes;
#ifdef MTCODER__USE_WRITE_THREAD
diff --git a/C/MtDec.c b/C/MtDec.c
index f8ab6b38..5ca89b73 100644
--- a/C/MtDec.c
+++ b/C/MtDec.c
@@ -1,5 +1,5 @@
/* MtDec.c -- Multi-thread Decoder
-2018-03-02 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -197,7 +197,7 @@ static SRes FullRead(ISeqInStream *stream, Byte *data, size_t *processedSize)
}
-static SRes MtDec_GetError_Spec(CMtDec *p, UInt64 interruptIndex, Bool *wasInterrupted)
+static SRes MtDec_GetError_Spec(CMtDec *p, UInt64 interruptIndex, BoolInt *wasInterrupted)
{
SRes res;
CriticalSection_Enter(&p->mtProgress.cs);
@@ -207,7 +207,7 @@ static SRes MtDec_GetError_Spec(CMtDec *p, UInt64 interruptIndex, Bool *wasInter
return res;
}
-static SRes MtDec_Progress_GetError_Spec(CMtDec *p, UInt64 inSize, UInt64 outSize, UInt64 interruptIndex, Bool *wasInterrupted)
+static SRes MtDec_Progress_GetError_Spec(CMtDec *p, UInt64 inSize, UInt64 outSize, UInt64 interruptIndex, BoolInt *wasInterrupted)
{
SRes res;
CriticalSection_Enter(&p->mtProgress.cs);
@@ -271,9 +271,9 @@ static WRes ThreadFunc2(CMtDecThread *t)
for (;;)
{
SRes res, codeRes;
- Bool wasInterrupted, isAllocError, overflow, finish;
+ BoolInt wasInterrupted, isAllocError, overflow, finish;
SRes threadingErrorSRes;
- Bool needCode, needWrite, needContinue;
+ BoolInt needCode, needWrite, needContinue;
size_t inDataSize_Start;
UInt64 inDataSize;
@@ -289,7 +289,7 @@ static WRes ThreadFunc2(CMtDecThread *t)
Byte *afterEndData = NULL;
size_t afterEndData_Size = 0;
- Bool canCreateNewThread = False;
+ BoolInt canCreateNewThread = False;
// CMtDecCallbackInfo parse;
CMtDecThread *nextThread;
@@ -629,7 +629,7 @@ static WRes ThreadFunc2(CMtDecThread *t)
if (res == SZ_OK && needCode && codeRes == SZ_OK)
{
- Bool isStartBlock = True;
+ BoolInt isStartBlock = True;
CMtDecBufLink *link = (CMtDecBufLink *)t->inBuf;
for (;;)
@@ -691,9 +691,9 @@ static WRes ThreadFunc2(CMtDecThread *t)
RINOK_THREAD(Event_Wait(&t->canWrite));
{
- Bool isErrorMode = False;
- Bool canRecode = True;
- Bool needWriteToStream = needWrite;
+ BoolInt isErrorMode = False;
+ BoolInt canRecode = True;
+ BoolInt needWriteToStream = needWrite;
if (p->exitThread) return 0; // it's never executed in normal cases
diff --git a/C/MtDec.h b/C/MtDec.h
index 760bbc84..9b577667 100644
--- a/C/MtDec.h
+++ b/C/MtDec.h
@@ -1,5 +1,5 @@
/* MtDec.h -- Multi-thread Decoder
-2018-03-02 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#ifndef __MT_DEC_H
#define __MT_DEC_H
@@ -76,7 +76,7 @@ typedef struct
// out
EMtDecParseState state;
- Bool canCreateNewThread;
+ BoolInt canCreateNewThread;
UInt64 outPos; // check it (size_t)
} CMtDecCallbackInfo;
@@ -107,11 +107,11 @@ typedef struct
if (*canRecode), we didn't flush current block data, so we still can decode current block later.
*/
SRes (*Write)(void *p, unsigned coderIndex,
- Bool needWriteToStream,
+ BoolInt needWriteToStream,
const Byte *src, size_t srcSize,
// int srcFinished,
- Bool *needContinue,
- Bool *canRecode);
+ BoolInt *needContinue,
+ BoolInt *canRecode);
} IMtDecCallback;
@@ -140,22 +140,22 @@ typedef struct _CMtDec
size_t allocatedBufsSize;
- Bool exitThread;
+ BoolInt exitThread;
WRes exitThreadWRes;
UInt64 blockIndex;
- Bool isAllocError;
- Bool overflow;
+ BoolInt isAllocError;
+ BoolInt overflow;
SRes threadingErrorSRes;
- Bool needContinue;
+ BoolInt needContinue;
// CAutoResetEvent finishedEvent;
SRes readRes;
SRes codeRes;
- Bool wasInterrupted;
+ BoolInt wasInterrupted;
unsigned numStartedThreads_Limit;
unsigned numStartedThreads;
@@ -164,14 +164,14 @@ typedef struct _CMtDec
size_t crossStart;
size_t crossEnd;
UInt64 readProcessed;
- Bool readWasFinished;
+ BoolInt readWasFinished;
UInt64 inProcessed;
unsigned filledThreadStart;
unsigned numFilledThreads;
#ifndef _7ZIP_ST
- Bool needInterrupt;
+ BoolInt needInterrupt;
UInt64 interruptIndex;
CMtProgress mtProgress;
CMtDecThread threads[MTDEC__THREADS_MAX];
diff --git a/C/Ppmd7.c b/C/Ppmd7.c
index 0951a7c7..470aadcc 100644
--- a/C/Ppmd7.c
+++ b/C/Ppmd7.c
@@ -1,5 +1,5 @@
/* Ppmd7.c -- PPMdH codec
-2017-04-03 : Igor Pavlov : Public domain
+2018-07-04 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h"
@@ -95,7 +95,7 @@ void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc)
p->Base = 0;
}
-Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc)
+BoolInt Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc)
{
if (!p->Base || p->Size != size)
{
@@ -342,7 +342,7 @@ void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)
p->DummySee.Count = 64; /* unused */
}
-static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
+static CTX_PTR CreateSuccessors(CPpmd7 *p, BoolInt skip)
{
CPpmd_State upState;
CTX_PTR c = p->MinContext;
diff --git a/C/Ppmd7.h b/C/Ppmd7.h
index 45002d95..610539a0 100644
--- a/C/Ppmd7.h
+++ b/C/Ppmd7.h
@@ -1,5 +1,5 @@
/* Ppmd7.h -- PPMdH compression codec
-2017-04-03 : Igor Pavlov : Public domain
+2018-07-04 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
/* This code supports virtual RangeDecoder and includes the implementation
@@ -60,7 +60,7 @@ typedef struct
} CPpmd7;
void Ppmd7_Construct(CPpmd7 *p);
-Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc);
+BoolInt Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAllocPtr alloc);
void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc);
void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);
#define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
@@ -115,7 +115,7 @@ typedef struct
} CPpmd7z_RangeDec;
void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p);
-Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p);
+BoolInt Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p);
#define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc);
diff --git a/C/Ppmd7Dec.c b/C/Ppmd7Dec.c
index 7953bb07..311e9f9d 100644
--- a/C/Ppmd7Dec.c
+++ b/C/Ppmd7Dec.c
@@ -1,5 +1,5 @@
/* Ppmd7Dec.c -- PPMdH Decoder
-2017-04-03 : Igor Pavlov : Public domain
+2018-07-04 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h"
@@ -8,7 +8,7 @@ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#define kTopValue (1 << 24)
-Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
+BoolInt Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
{
unsigned i;
p->Code = 0;
diff --git a/C/Ppmd8.c b/C/Ppmd8.c
index 15c76bb5..58141633 100644
--- a/C/Ppmd8.c
+++ b/C/Ppmd8.c
@@ -1,5 +1,5 @@
/* Ppmd8.c -- PPMdI codec
-2017-04-03 : Igor Pavlov : Public domain
+2018-07-04 : Igor Pavlov : Public domain
This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
#include "Precomp.h"
@@ -93,7 +93,7 @@ void Ppmd8_Free(CPpmd8 *p, ISzAllocPtr alloc)
p->Base = 0;
}
-Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc)
+BoolInt Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc)
{
if (!p->Base || p->Size != size)
{
@@ -605,7 +605,7 @@ static void RestoreModel(CPpmd8 *p, CTX_PTR c1
}
}
-static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c)
+static CTX_PTR CreateSuccessors(CPpmd8 *p, BoolInt skip, CPpmd_State *s1, CTX_PTR c)
{
CPpmd_State upState;
Byte flags;
diff --git a/C/Ppmd8.h b/C/Ppmd8.h
index 3b15920e..51c497dc 100644
--- a/C/Ppmd8.h
+++ b/C/Ppmd8.h
@@ -1,5 +1,5 @@
/* Ppmd8.h -- PPMdI codec
-2017-04-03 : Igor Pavlov : Public domain
+2018-07-04 : Igor Pavlov : Public domain
This code is based on:
PPMd var.I (2002): Dmitry Shkarin : Public domain
Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
@@ -86,7 +86,7 @@ typedef struct
} CPpmd8;
void Ppmd8_Construct(CPpmd8 *p);
-Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc);
+BoolInt Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAllocPtr alloc);
void Ppmd8_Free(CPpmd8 *p, ISzAllocPtr alloc);
void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod);
#define Ppmd8_WasAllocated(p) ((p)->Base != NULL)
@@ -121,7 +121,7 @@ CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked, UInt32 *scale);
/* ---------- Decode ---------- */
-Bool Ppmd8_RangeDec_Init(CPpmd8 *p);
+BoolInt Ppmd8_RangeDec_Init(CPpmd8 *p);
#define Ppmd8_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
int Ppmd8_DecodeSymbol(CPpmd8 *p); /* returns: -1 as EndMarker, -2 as DataError */
diff --git a/C/Ppmd8Dec.c b/C/Ppmd8Dec.c
index dc79f0fd..a18ec677 100644
--- a/C/Ppmd8Dec.c
+++ b/C/Ppmd8Dec.c
@@ -1,5 +1,5 @@
/* Ppmd8Dec.c -- PPMdI Decoder
-2017-04-03 : Igor Pavlov : Public domain
+2018-07-04 : Igor Pavlov : Public domain
This code is based on:
PPMd var.I (2002): Dmitry Shkarin : Public domain
Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
@@ -11,7 +11,7 @@ This code is based on:
#define kTop (1 << 24)
#define kBot (1 << 15)
-Bool Ppmd8_RangeDec_Init(CPpmd8 *p)
+BoolInt Ppmd8_RangeDec_Init(CPpmd8 *p)
{
unsigned i;
p->Low = 0;
diff --git a/C/Util/7z/7zMain.c b/C/Util/7z/7zMain.c
index ea93d63f..33dcaaf5 100644
--- a/C/Util/7z/7zMain.c
+++ b/C/Util/7z/7zMain.c
@@ -1,5 +1,5 @@
/* 7zMain.c - Test application for 7z Decoder
-2018-04-19 : Igor Pavlov : Public domain */
+2018-08-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -354,7 +354,7 @@ static void PrintError(char *s)
PrintLF();
}
-static void GetAttribString(UInt32 wa, Bool isDir, char *s)
+static void GetAttribString(UInt32 wa, BoolInt isDir, char *s)
{
#ifdef USE_WINDOWS_FILE
s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.');
diff --git a/C/Util/7zipInstall/7zipInstall.c b/C/Util/7zipInstall/7zipInstall.c
index db09a32d..01acaebf 100644
--- a/C/Util/7zipInstall/7zipInstall.c
+++ b/C/Util/7zipInstall/7zipInstall.c
@@ -1,5 +1,5 @@
/* 7zipInstall.c - 7-Zip Installer
-2017-08-28 : Igor Pavlov : Public domain */
+2018-08-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -89,9 +89,9 @@ static LPCWSTR const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\\Inpro
#define g_AllUsers True
-static Bool g_Install_was_Pressed;
-static Bool g_Finished;
-static Bool g_SilentMode;
+static BoolInt g_Install_was_Pressed;
+static BoolInt g_Finished;
+static BoolInt g_SilentMode;
static HWND g_HWND;
static HWND g_Path_HWND;
@@ -270,7 +270,7 @@ static int MyRegistry_QueryString2(HKEY hKey, LPCWSTR keyName, LPCWSTR valName,
if (res != ERROR_SUCCESS)
return False;
{
- Bool res2 = MyRegistry_QueryString(key, valName, dest);
+ BoolInt res2 = MyRegistry_QueryString(key, valName, dest);
RegCloseKey(key);
return res2;
}
@@ -343,7 +343,7 @@ static LONG MyRegistry_CreateKeyAndVal_32(HKEY parentKey, LPCWSTR keyName, LPCWS
#define kSignatureSearchLimit (1 << 22)
-static Bool FindSignature(CSzFile *stream, UInt64 *resPos)
+static BoolInt FindSignature(CSzFile *stream, UInt64 *resPos)
{
Byte buf[kBufSize];
size_t numPrevBytes = 0;
@@ -431,7 +431,7 @@ int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data)
return 0;
}
-static Bool MyBrowseForFolder(HWND owner, LPCWSTR title, UINT ulFlags,
+static BoolInt MyBrowseForFolder(HWND owner, LPCWSTR title, UINT ulFlags,
LPCWSTR initialFolder, LPWSTR resultPath)
{
WCHAR displayName[MAX_PATH];
@@ -694,7 +694,7 @@ static void SetShellProgramsGroup(HWND hwndOwner)
for (; i < 3; i++)
{
- Bool isOK = True;
+ BoolInt isOK = True;
WCHAR link[MAX_PATH + 40];
WCHAR destPath[MAX_PATH + 40];
@@ -874,7 +874,7 @@ static void WriteShellEx()
static const wchar_t *GetCmdParam(const wchar_t *s)
{
- Bool quoteMode = False;
+ BoolInt quoteMode = False;
for (;; s++)
{
wchar_t c = *s;
@@ -988,7 +988,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (path[0] == 0)
{
HKEY key = 0;
- Bool ok = False;
+ BoolInt ok = False;
LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, k_Reg_Software_7zip, 0, KEY_READ | k_Reg_WOW_Flag, &key);
if (res == ERROR_SUCCESS)
{
@@ -1101,7 +1101,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
}
-static Bool GetErrorMessage(DWORD errorCode, WCHAR *message)
+static BoolInt GetErrorMessage(DWORD errorCode, WCHAR *message)
{
LPVOID msgBuf;
if (FormatMessageW(
@@ -1313,7 +1313,7 @@ if (res == SZ_OK)
}
{
- // Bool skipFile = False;
+ // BoolInt skipFile = False;
wcscpy(origPath, path);
diff --git a/C/Util/7zipUninstall/7zipUninstall.c b/C/Util/7zipUninstall/7zipUninstall.c
index 2effeed6..9faf8b00 100644
--- a/C/Util/7zipUninstall/7zipUninstall.c
+++ b/C/Util/7zipUninstall/7zipUninstall.c
@@ -1,5 +1,5 @@
/* 7zipUninstall.c - 7-Zip Uninstaller
-2018-03-01 : Igor Pavlov : Public domain */
+2018-08-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -70,9 +70,9 @@ static const WCHAR * const k_Reg_CLSID_7zip_Inproc = L"CLSID\\" k_7zip_CLSID L"\
#define g_AllUsers True
-static Bool g_Install_was_Pressed;
-static Bool g_Finished;
-static Bool g_SilentMode;
+static BoolInt g_Install_was_Pressed;
+static BoolInt g_Finished;
+static BoolInt g_SilentMode;
static HWND g_HWND;
static HWND g_Path_HWND;
@@ -94,7 +94,7 @@ static const WCHAR * const kUninstallExe = L"Uninstall.exe";
#define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c)))
-static Bool AreStringsEqual_NoCase(const wchar_t *s1, const wchar_t *s2)
+static BoolInt AreStringsEqual_NoCase(const wchar_t *s1, const wchar_t *s2)
{
for (;;)
{
@@ -107,7 +107,7 @@ static Bool AreStringsEqual_NoCase(const wchar_t *s1, const wchar_t *s2)
}
}
-static Bool IsString1PrefixedByString2_NoCase(const wchar_t *s1, const wchar_t *s2)
+static BoolInt IsString1PrefixedByString2_NoCase(const wchar_t *s1, const wchar_t *s2)
{
for (;;)
{
@@ -149,7 +149,7 @@ static int MyRegistry_QueryString2(HKEY hKey, LPCWSTR keyName, LPCWSTR valName,
if (res != ERROR_SUCCESS)
return False;
{
- Bool res2 = MyRegistry_QueryString(key, valName, dest);
+ BoolInt res2 = MyRegistry_QueryString(key, valName, dest);
RegCloseKey(key);
return res2;
}
@@ -180,7 +180,7 @@ static int MyRegistry_QueryString2_32(HKEY hKey, LPCWSTR keyName, LPCWSTR valNam
if (res != ERROR_SUCCESS)
return False;
{
- Bool res2 = MyRegistry_QueryString(key, valName, dest);
+ BoolInt res2 = MyRegistry_QueryString(key, valName, dest);
RegCloseKey(key);
return res2;
}
@@ -283,7 +283,7 @@ static void SetShellProgramsGroup(HWND hwndOwner)
for (; i < 3; i++)
{
- // Bool isOK = True;
+ // BoolInt isOK = True;
WCHAR link[MAX_PATH + 40];
WCHAR destPath[MAX_PATH + 40];
@@ -300,7 +300,7 @@ static void SetShellProgramsGroup(HWND hwndOwner)
{
const size_t baseLen = wcslen(link);
unsigned k;
- Bool needDelete = False;
+ BoolInt needDelete = False;
for (k = 0; k < 2; k++)
{
@@ -347,7 +347,7 @@ static const WCHAR * const k_AppPaths_7zFm = L"Software\\Microsoft\\Windows\\Cur
static const WCHAR * const k_Uninstall_7zip = k_REG_Uninstall L"7-Zip";
-static Bool AreEqual_Path_PrefixName(const wchar_t *s, const wchar_t *prefix, const wchar_t *name)
+static BoolInt AreEqual_Path_PrefixName(const wchar_t *s, const wchar_t *prefix, const wchar_t *name)
{
if (!IsString1PrefixedByString2_NoCase(s, prefix))
return False;
@@ -444,7 +444,7 @@ static void WriteCLSID()
static const wchar_t *GetCmdParam(const wchar_t *s)
{
- Bool quoteMode = False;
+ BoolInt quoteMode = False;
for (;; s++)
{
wchar_t c = *s;
@@ -469,7 +469,7 @@ static void RemoveQuotes(wchar_t *s)
}
}
-static Bool DoesFileOrDirExist()
+static BoolInt DoesFileOrDirExist()
{
return (GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES);
}
@@ -491,7 +491,7 @@ static BOOL RemoveFileAfterReboot()
#define IS_LIMIT_CHAR(c) (c == 0 || c == ' ')
-static Bool IsThereSpace(const wchar_t *s)
+static BoolInt IsThereSpace(const wchar_t *s)
{
for (;;)
{
@@ -505,7 +505,7 @@ static Bool IsThereSpace(const wchar_t *s)
static void AddPathParam(wchar_t *dest, const wchar_t *src)
{
- Bool needQuote = IsThereSpace(src);
+ BoolInt needQuote = IsThereSpace(src);
if (needQuote)
wcscat(dest, L"\"");
wcscat(dest, src);
@@ -515,7 +515,7 @@ static void AddPathParam(wchar_t *dest, const wchar_t *src)
-static Bool GetErrorMessage(DWORD errorCode, WCHAR *message)
+static BoolInt GetErrorMessage(DWORD errorCode, WCHAR *message)
{
LPVOID msgBuf;
if (FormatMessageW(
@@ -586,7 +586,7 @@ static int Install()
SRes res = SZ_OK;
WRes winRes = 0;
- // Bool needReboot = False;
+ // BoolInt needReboot = False;
const size_t pathLen = wcslen(path);
if (!g_SilentMode)
@@ -805,7 +805,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
lpCmdLine, int nCmdShow)
{
const wchar_t *cmdParams;
- Bool useTemp = True;
+ BoolInt useTemp = True;
UNUSED_VAR(hPrevInstance)
UNUSED_VAR(lpCmdLine)
@@ -1005,7 +1005,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (path[0] == 0)
{
HKEY key = 0;
- Bool ok = False;
+ BoolInt ok = False;
LONG res = RegOpenKeyExW(HKEY_CURRENT_USER, k_Reg_Software_7zip, 0, KEY_READ | k_Reg_WOW_Flag, &key);
if (res == ERROR_SUCCESS)
{
diff --git a/C/Util/Lzma/LzmaUtil.c b/C/Util/Lzma/LzmaUtil.c
index 33db3e16..739bc0fd 100644
--- a/C/Util/Lzma/LzmaUtil.c
+++ b/C/Util/Lzma/LzmaUtil.c
@@ -1,5 +1,5 @@
/* LzmaUtil.c -- Test application for LZMA compression
-2017-04-27 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "../../Precomp.h"
@@ -177,7 +177,7 @@ static int main2(int numArgs, const char *args[], char *rs)
char c;
int res;
int encodeMode;
- Bool useOutFile = False;
+ BoolInt useOutFile = False;
FileSeqInStream_CreateVTable(&inStream);
File_Construct(&inStream.file);
diff --git a/C/Util/SfxSetup/SfxSetup.c b/C/Util/SfxSetup/SfxSetup.c
index 8275dfea..5e8a3086 100644
--- a/C/Util/SfxSetup/SfxSetup.c
+++ b/C/Util/SfxSetup/SfxSetup.c
@@ -1,5 +1,5 @@
/* SfxSetup.c - 7z SFX Setup
-2017-04-04 : Igor Pavlov : Public domain */
+2018-08-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -127,7 +127,7 @@ static WRes MyCreateDir(const WCHAR *name)
#define kSignatureSearchLimit (1 << 22)
-static Bool FindSignature(CSzFile *stream, UInt64 *resPos)
+static BoolInt FindSignature(CSzFile *stream, UInt64 *resPos)
{
Byte buf[kBufferSize];
size_t numPrevBytes = 0;
@@ -163,7 +163,7 @@ static Bool FindSignature(CSzFile *stream, UInt64 *resPos)
}
}
-static Bool DoesFileOrDirExist(const WCHAR *path)
+static BoolInt DoesFileOrDirExist(const WCHAR *path)
{
WIN32_FIND_DATAW fd;
HANDLE handle;
@@ -254,7 +254,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
DWORD winRes;
const wchar_t *cmdLineParams;
const char *errorMessage = NULL;
- Bool useShellExecute = True;
+ BoolInt useShellExecute = True;
DWORD exitCode = 0;
LoadSecurityDlls();
@@ -287,7 +287,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
cmdLineParams = GetCommandLineW();
#ifndef UNDER_CE
{
- Bool quoteMode = False;
+ BoolInt quoteMode = False;
for (;; cmdLineParams++)
{
wchar_t c = *cmdLineParams;
diff --git a/C/Xz.h b/C/Xz.h
index ef067e0e..544ee18f 100644
--- a/C/Xz.h
+++ b/C/Xz.h
@@ -1,5 +1,5 @@
/* Xz.h - Xz interface
-2018-02-28 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#ifndef __XZ_H
#define __XZ_H
@@ -53,7 +53,7 @@ typedef struct
#define XzBlock_HasUnsupportedFlags(p) (((p)->flags & ~(XZ_BF_NUM_FILTERS_MASK | XZ_BF_PACK_SIZE | XZ_BF_UNPACK_SIZE)) != 0)
SRes XzBlock_Parse(CXzBlock *p, const Byte *header);
-SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes);
+SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, BoolInt *isIndex, UInt32 *headerSizeRes);
/* ---------- xz stream ---------- */
@@ -186,10 +186,10 @@ typedef struct
Byte *outBuf;
size_t outBufSize;
size_t outWritten; // is equal to lzmaDecoder.dicPos (in outBuf mode)
- Bool wasFinished;
+ BoolInt wasFinished;
SRes res;
ECoderStatus status;
- // Bool SingleBufMode;
+ // BoolInt SingleBufMode;
int finished[MIXCODER_NUM_FILTERS_MAX - 1];
size_t pos[MIXCODER_NUM_FILTERS_MAX - 1];
@@ -241,9 +241,9 @@ typedef struct
CXzCheck check;
CSha256 sha;
- Bool parseMode;
- Bool headerParsedOk;
- Bool decodeToStreamSignature;
+ BoolInt parseMode;
+ BoolInt headerParsedOk;
+ BoolInt decodeToStreamSignature;
unsigned decodeOnlyOneBlock;
Byte *outBuf;
@@ -335,7 +335,7 @@ SRes XzUnpacker_CodeFull(CXzUnpacker *p, Byte *dest, SizeT *destLen,
const Byte *src, SizeT *srcLen,
ECoderFinishMode finishMode, ECoderStatus *status);
-Bool XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p);
+BoolInt XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p);
/*
XzUnpacker_GetExtraSize() returns then number of uncofirmed bytes,
@@ -365,7 +365,7 @@ UInt64 XzUnpacker_GetExtraSize(const CXzUnpacker *p);
*/
void XzUnpacker_PrepareToRandomBlockDecoding(CXzUnpacker *p);
-Bool XzUnpacker_IsBlockFinished(const CXzUnpacker *p);
+BoolInt XzUnpacker_IsBlockFinished(const CXzUnpacker *p);
#define XzUnpacker_GetPackSizeForIndex(p) ((p)->packSize + (p)->blockHeaderSize + XzFlags_GetCheckSize((p)->streamFlags))
@@ -378,7 +378,7 @@ typedef struct
{
size_t inBufSize_ST;
size_t outStep_ST;
- Bool ignoreErrors;
+ BoolInt ignoreErrors;
#ifndef _7ZIP_ST
unsigned numThreads;
diff --git a/C/XzDec.c b/C/XzDec.c
index b973e686..77511519 100644
--- a/C/XzDec.c
+++ b/C/XzDec.c
@@ -1,5 +1,5 @@
/* XzDec.c -- Xz Decode
-2018-04-24 : Igor Pavlov : Public domain */
+2018-12-29 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -341,7 +341,7 @@ static SRes SbState_SetFromMethod(IStateCoder *p, ISzAllocPtr alloc)
typedef struct
{
CLzma2Dec decoder;
- Bool outBufMode;
+ BoolInt outBufMode;
} CLzma2Dec_Spec;
@@ -637,8 +637,8 @@ static SRes MixCoder_Code(CMixCoder *p,
for (;;)
{
- Bool processed = False;
- Bool allFinished = True;
+ BoolInt processed = False;
+ BoolInt allFinished = True;
SRes resMain = SZ_OK;
unsigned i;
@@ -761,7 +761,7 @@ SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf)
return XzFlags_IsSupported(*p) ? SZ_OK : SZ_ERROR_UNSUPPORTED;
}
-static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf)
+static BoolInt Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *buf)
{
return indexSize == (((UInt64)GetUi32(buf + 4) + 1) << 2)
&& GetUi32(buf) == CrcCalc(buf + 4, 6)
@@ -775,7 +775,7 @@ static Bool Xz_CheckFooter(CXzStreamFlags flags, UInt64 indexSize, const Byte *b
if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }
-static Bool XzBlock_AreSupportedFilters(const CXzBlock *p)
+static BoolInt XzBlock_AreSupportedFilters(const CXzBlock *p)
{
unsigned numFilters = XzBlock_GetNumFilters(p) - 1;
unsigned i;
@@ -866,7 +866,7 @@ SRes XzBlock_Parse(CXzBlock *p, const Byte *header)
static SRes XzDecMix_Init(CMixCoder *p, const CXzBlock *block, Byte *outBuf, size_t outBufSize)
{
unsigned i;
- Bool needReInit = True;
+ BoolInt needReInit = True;
unsigned numFilters = XzBlock_GetNumFilters(block);
if (numFilters == p->numCoders && ((p->outBuf && outBuf) || (!p->outBuf && !outBuf)))
@@ -999,8 +999,8 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
SRes res;
ECoderFinishMode finishMode2 = finishMode;
- Bool srcFinished2 = srcFinished;
- Bool destFinish = False;
+ BoolInt srcFinished2 = srcFinished;
+ BoolInt destFinish = False;
if (p->block.packSize != (UInt64)(Int64)-1)
{
@@ -1346,12 +1346,12 @@ SRes XzUnpacker_CodeFull(CXzUnpacker *p, Byte *dest, SizeT *destLen,
}
-Bool XzUnpacker_IsBlockFinished(const CXzUnpacker *p)
+BoolInt XzUnpacker_IsBlockFinished(const CXzUnpacker *p)
{
return (p->state == XZ_STATE_BLOCK_HEADER) && (p->pos == 0);
}
-Bool XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p)
+BoolInt XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p)
{
return (p->state == XZ_STATE_STREAM_PADDING) && (((UInt32)p->padSize & 3) == 0);
}
@@ -1423,18 +1423,18 @@ typedef struct
size_t outCodeSize;
ECoderStatus status;
SRes codeRes;
- Bool skipMode;
- // Bool finishedWithMark;
+ BoolInt skipMode;
+ // BoolInt finishedWithMark;
EMtDecParseState parseState;
- Bool parsing_Truncated;
- Bool atBlockHeader;
+ BoolInt parsing_Truncated;
+ BoolInt atBlockHeader;
CXzStreamFlags streamFlags;
// UInt64 numFinishedStreams
UInt64 numStreams;
UInt64 numTotalBlocks;
UInt64 numBlocks;
- Bool dec_created;
+ BoolInt dec_created;
CXzUnpacker dec;
Byte mtPad[1 << 7];
@@ -1458,14 +1458,14 @@ typedef struct
ICompressProgress *progress;
// CXzStatInfo *stat;
- Bool finishMode;
- Bool outSize_Defined;
+ BoolInt finishMode;
+ BoolInt outSize_Defined;
UInt64 outSize;
UInt64 outProcessed;
UInt64 inProcessed;
UInt64 readProcessed;
- Bool readWasFinished;
+ BoolInt readWasFinished;
SRes readRes;
SRes writeRes;
@@ -1473,14 +1473,14 @@ typedef struct
size_t outBufSize;
Byte *inBuf;
size_t inBufSize;
- Bool dec_created;
+
CXzUnpacker dec;
ECoderStatus status;
SRes codeRes;
#ifndef _7ZIP_ST
- Bool mainDecoderWasCalled;
+ BoolInt mainDecoderWasCalled;
// int statErrorDefined;
int finishedDecoderIndex;
@@ -1494,12 +1494,12 @@ typedef struct
// UInt64 numBadBlocks;
SRes mainErrorCode;
- Bool isBlockHeaderState_Parse;
- Bool isBlockHeaderState_Write;
+ BoolInt isBlockHeaderState_Parse;
+ BoolInt isBlockHeaderState_Write;
UInt64 outProcessed_Parse;
- Bool parsing_Truncated;
+ BoolInt parsing_Truncated;
- Bool mtc_WasConstructed;
+ BoolInt mtc_WasConstructed;
CMtDec mtc;
CXzDecMtThread coders[MTDEC__THREADS_MAX];
#endif
@@ -1525,7 +1525,8 @@ CXzDecMtHandle XzDecMt_Create(ISzAllocPtr alloc, ISzAllocPtr allocMid)
p->outBufSize = 0;
p->inBuf = NULL;
p->inBufSize = 0;
- p->dec_created = False;
+
+ XzUnpacker_Construct(&p->dec, &p->alignOffsetAlloc.vt);
p->unpackBlockMaxSize = 0;
@@ -1573,11 +1574,7 @@ static void XzDecMt_FreeOutBufs(CXzDecMt *p)
static void XzDecMt_FreeSt(CXzDecMt *p)
{
- if (p->dec_created)
- {
- XzUnpacker_Free(&p->dec);
- p->dec_created = False;
- }
+ XzUnpacker_Free(&p->dec);
if (p->outBuf)
{
@@ -1968,11 +1965,11 @@ static SRes XzDecMt_Callback_Code(void *pp, unsigned coderIndex,
#define XZDECMT_STREAM_WRITE_STEP (1 << 24)
static SRes XzDecMt_Callback_Write(void *pp, unsigned coderIndex,
- Bool needWriteToStream,
+ BoolInt needWriteToStream,
const Byte *src, size_t srcSize,
// int srcFinished,
- Bool *needContinue,
- Bool *canRecode)
+ BoolInt *needContinue,
+ BoolInt *canRecode)
{
CXzDecMt *me = (CXzDecMt *)pp;
const CXzDecMtThread *coder = &me->coders[coderIndex];
@@ -2302,7 +2299,7 @@ void XzStatInfo_Clear(CXzStatInfo *p)
static SRes XzDecMt_Decode_ST(CXzDecMt *p
#ifndef _7ZIP_ST
- , Bool tMode
+ , BoolInt tMode
#endif
, CXzStatInfo *stat)
{
@@ -2358,7 +2355,7 @@ static SRes XzDecMt_Decode_ST(CXzDecMt *p
for (;;)
{
SizeT outSize;
- Bool finished;
+ BoolInt finished;
ECoderFinishMode finishMode;
SizeT inProcessed;
ECoderStatus status;
@@ -2466,7 +2463,7 @@ static SRes XzStatInfo_SetStat(const CXzUnpacker *dec,
int finishMode,
UInt64 readProcessed, UInt64 inProcessed,
SRes res, ECoderStatus status,
- Bool decodingTruncated,
+ BoolInt decodingTruncated,
CXzStatInfo *stat)
{
UInt64 extraSize;
@@ -2531,7 +2528,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
{
CXzDecMt *p = (CXzDecMt *)pp;
#ifndef _7ZIP_ST
- Bool tMode;
+ BoolInt tMode;
#endif
XzStatInfo_Clear(stat);
@@ -2564,13 +2561,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
p->codeRes = 0;
p->status = CODER_STATUS_NOT_SPECIFIED;
- if (!p->dec_created)
- {
- XzUnpacker_Construct(&p->dec, &p->alignOffsetAlloc.vt);
- p->dec_created = True;
- }
XzUnpacker_Init(&p->dec);
-
*isMT = False;
@@ -2600,6 +2591,8 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
{
IMtDecCallback vt;
+ // we just free ST buffers here
+ // but we still keep state variables, that was set in XzUnpacker_Init()
XzDecMt_FreeSt(p);
p->outProcessed_Parse = 0;
@@ -2636,7 +2629,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
vt.Write = XzDecMt_Callback_Write;
{
- Bool needContinue;
+ BoolInt needContinue;
SRes res = MtDec_Code(&p->mtc);
@@ -2665,7 +2658,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
if (!needContinue)
{
SRes codeRes;
- Bool truncated = False;
+ BoolInt truncated = False;
ECoderStatus status;
CXzUnpacker *dec;
diff --git a/C/XzEnc.c b/C/XzEnc.c
index 82e70888..acc60c67 100644
--- a/C/XzEnc.c
+++ b/C/XzEnc.c
@@ -1,5 +1,5 @@
/* XzEnc.c -- Xz Encode
-2018-04-28 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -814,7 +814,7 @@ static SRes Xz_CompressBlock(
SRes res;
Byte *outBuf = NULL;
size_t outSize = 0;
- Bool useStream = (fp || inStream);
+ BoolInt useStream = (fp || inStream);
// useStream = True;
if (!useStream)
@@ -940,7 +940,7 @@ typedef struct
#ifndef _7ZIP_ST
unsigned checkType;
ISeqOutStream *outStream;
- Bool mtCoder_WasConstructed;
+ BoolInt mtCoder_WasConstructed;
CMtCoder mtCoder;
CXzEncBlockInfo EncBlocks[MTCODER__BLOCKS_MAX];
#endif
diff --git a/C/XzIn.c b/C/XzIn.c
index 3a1b71dc..ff48e2dd 100644
--- a/C/XzIn.c
+++ b/C/XzIn.c
@@ -1,5 +1,5 @@
/* XzIn.c - Xz input
-2018-02-02 : Igor Pavlov : Public domain */
+2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h"
@@ -28,7 +28,7 @@ SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream)
{ unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; }
-SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, Bool *isIndex, UInt32 *headerSizeRes)
+SRes XzBlock_ReadHeader(CXzBlock *p, ISeqInStream *inStream, BoolInt *isIndex, UInt32 *headerSizeRes)
{
Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
unsigned headerSize;
diff --git a/CPP/7zip/Aes.mak b/CPP/7zip/Aes.mak
index fbd70aae..20f1a72f 100644
--- a/CPP/7zip/Aes.mak
+++ b/CPP/7zip/Aes.mak
@@ -1,7 +1,7 @@
C_OBJS = $(C_OBJS) \
$O\Aes.obj
-!IF "$(CPU)" != "IA64" && "$(CPU)" != "MIPS" && "$(CPU)" != "ARM" && "$(CPU)" != "ARM64"
+!IF "$(PLATFORM)" != "ia64" && "$(PLATFORM)" != "mips" && "$(PLATFORM)" != "arm" && "$(PLATFORM)" != "arm64"
ASM_OBJS = $(ASM_OBJS) \
$O\AesOpt.obj
!ENDIF
diff --git a/CPP/7zip/Archive/7z/7zHandler.cpp b/CPP/7zip/Archive/7z/7zHandler.cpp
index 988b35f7..bbb892e7 100644
--- a/CPP/7zip/Archive/7z/7zHandler.cpp
+++ b/CPP/7zip/Archive/7z/7zHandler.cpp
@@ -236,6 +236,13 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
prop = v;
break;
}
+
+ case kpidReadOnly:
+ {
+ if (!_db.CanUpdate())
+ prop = true;
+ break;
+ }
}
prop.Detach(value);
return S_OK;
diff --git a/CPP/7zip/Archive/7z/7zHandlerOut.cpp b/CPP/7zip/Archive/7z/7zHandlerOut.cpp
index 79f83bac..b6be06a8 100644
--- a/CPP/7zip/Archive/7z/7zHandlerOut.cpp
+++ b/CPP/7zip/Archive/7z/7zHandlerOut.cpp
@@ -267,6 +267,9 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
db = &_db;
#endif
+ if (db && !db->CanUpdate())
+ return E_NOTIMPL;
+
/*
CMyComPtr<IArchiveGetRawProps> getRawProps;
updateCallback->QueryInterface(IID_IArchiveGetRawProps, (void **)&getRawProps);
diff --git a/CPP/7zip/Archive/7z/7zIn.cpp b/CPP/7zip/Archive/7z/7zIn.cpp
index b7b71d13..ab5b5de4 100644
--- a/CPP/7zip/Archive/7z/7zIn.cpp
+++ b/CPP/7zip/Archive/7z/7zIn.cpp
@@ -1465,21 +1465,24 @@ void CDbEx::FillLinks()
}
if (indexInFolder != 0)
+ {
folderIndex++;
- /*
- if (indexInFolder != 0)
- ThrowIncorrect();
- */
+ // 18.06
+ ThereIsHeaderError = true;
+ // ThrowIncorrect();
+ }
for (;;)
{
if (folderIndex >= NumFolders)
return;
FolderStartFileIndex[folderIndex] = i;
- /*
if (NumUnpackStreamsVector[folderIndex] != 0)
- ThrowIncorrect();;
- */
+ {
+ // 18.06
+ ThereIsHeaderError = true;
+ // ThrowIncorrect();
+ }
folderIndex++;
}
}
diff --git a/CPP/7zip/Archive/7z/7zIn.h b/CPP/7zip/Archive/7z/7zIn.h
index 2d5fbb79..6a61d314 100644
--- a/CPP/7zip/Archive/7z/7zIn.h
+++ b/CPP/7zip/Archive/7z/7zIn.h
@@ -257,6 +257,16 @@ struct CDbEx: public CDatabase
PhySize = 0;
}
+ bool CanUpdate() const
+ {
+ if (ThereIsHeaderError
+ || UnexpectedEnd
+ || StartHeaderWasRecovered
+ || UnsupportedFeatureError)
+ return false;
+ return true;
+ }
+
void FillLinks();
UInt64 GetFolderStreamPos(CNum folderIndex, unsigned indexInFolder) const
diff --git a/CPP/7zip/Archive/7z/7zUpdate.cpp b/CPP/7zip/Archive/7z/7zUpdate.cpp
index 5450c8ba..6705fc00 100644
--- a/CPP/7zip/Archive/7z/7zUpdate.cpp
+++ b/CPP/7zip/Archive/7z/7zUpdate.cpp
@@ -124,13 +124,13 @@ static int Parse_EXE(const Byte *buf, size_t size, CFilterMode *filterMode)
#define ELF_DATA_2LSB 1
#define ELF_DATA_2MSB 2
-static UInt16 Get16(const Byte *p, Bool be) { if (be) return (UInt16)GetBe16(p); return (UInt16)GetUi16(p); }
-static UInt32 Get32(const Byte *p, Bool be) { if (be) return GetBe32(p); return GetUi32(p); }
-// static UInt64 Get64(const Byte *p, Bool be) { if (be) return GetBe64(p); return GetUi64(p); }
+static UInt16 Get16(const Byte *p, BoolInt be) { if (be) return (UInt16)GetBe16(p); return (UInt16)GetUi16(p); }
+static UInt32 Get32(const Byte *p, BoolInt be) { if (be) return GetBe32(p); return GetUi32(p); }
+// static UInt64 Get64(const Byte *p, BoolInt be) { if (be) return GetBe64(p); return GetUi64(p); }
static int Parse_ELF(const Byte *buf, size_t size, CFilterMode *filterMode)
{
- Bool /* is32, */ be;
+ BoolInt /* is32, */ be;
UInt32 filterId;
if (size < 512 || buf[6] != 1) /* ver */
@@ -200,7 +200,7 @@ static unsigned Parse_MACH(const Byte *buf, size_t size, CFilterMode *filterMode
if (size < 512)
return 0;
- Bool /* mode64, */ be;
+ BoolInt /* mode64, */ be;
switch (GetUi32(buf))
{
case MACH_SIG_BE_32: /* mode64 = False; */ be = True; break;
@@ -239,7 +239,7 @@ static unsigned Parse_MACH(const Byte *buf, size_t size, CFilterMode *filterMode
#define RIFF_SIG 0x46464952
-static Bool Parse_WAV(const Byte *buf, size_t size, CFilterMode *filterMode)
+static BoolInt Parse_WAV(const Byte *buf, size_t size, CFilterMode *filterMode)
{
UInt32 subChunkSize, pos;
if (size < 0x2C)
@@ -285,7 +285,7 @@ static Bool Parse_WAV(const Byte *buf, size_t size, CFilterMode *filterMode)
return False;
}
-static Bool ParseFile(const Byte *buf, size_t size, CFilterMode *filterMode)
+static BoolInt ParseFile(const Byte *buf, size_t size, CFilterMode *filterMode)
{
filterMode->Id = 0;
filterMode->Delta = 0;
@@ -894,7 +894,7 @@ HRESULT CAnalysis::GetFilterGroup(UInt32 index, const CUpdateItem &ui, CFilterMo
// RINOK(Callback->SetOperationResult2(index, NUpdate::NOperationResult::kOK));
if (result == S_OK)
{
- Bool parseRes = ParseFile(Buffer, size, &filterModeTemp);
+ BoolInt parseRes = ParseFile(Buffer, size, &filterModeTemp);
if (parseRes && filterModeTemp.Delta == 0)
{
filterModeTemp.SetDelta();
@@ -1648,6 +1648,9 @@ HRESULT Update(
for (CNum fi = db->FolderStartFileIndex[i]; indexInFolder < numUnpackStreams; fi++)
{
+ if (fi >= db->Files.Size())
+ return E_FAIL;
+
const CFileItem &file = db->Files[fi];
if (file.HasStream)
{
diff --git a/CPP/7zip/Archive/ArHandler.cpp b/CPP/7zip/Archive/ArHandler.cpp
index 816a84e4..09a62201 100644
--- a/CPP/7zip/Archive/ArHandler.cpp
+++ b/CPP/7zip/Archive/ArHandler.cpp
@@ -170,8 +170,8 @@ static bool OctalToNumber32(const char *s, unsigned size, UInt32 &res)
res = 0;
char sz[32];
size = RemoveTailSpaces(sz, s, size);
- if (size == 0)
- return true; // some items doesn't contaion any numbers
+ if (size == 0 || strcmp(sz, "-1") == 0)
+ return true; // some items don't contain any numbers
const char *end;
UInt64 res64 = ConvertOctStringToUInt64(sz, &end);
if ((unsigned)(end - sz) != size)
@@ -185,8 +185,8 @@ static bool DecimalToNumber(const char *s, unsigned size, UInt64 &res)
res = 0;
char sz[32];
size = RemoveTailSpaces(sz, s, size);
- if (size == 0)
- return true; // some items doesn't contaion any numbers
+ if (size == 0 || strcmp(sz, "-1") == 0)
+ return true; // some items don't contain any numbers
const char *end;
res = ConvertStringToUInt64(sz, &end);
return ((unsigned)(end - sz) == size);
diff --git a/CPP/7zip/Archive/Bz2Handler.cpp b/CPP/7zip/Archive/Bz2Handler.cpp
index 98428430..b0c2f750 100644
--- a/CPP/7zip/Archive/Bz2Handler.cpp
+++ b/CPP/7zip/Archive/Bz2Handler.cpp
@@ -366,7 +366,13 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
return E_INVALIDARG;
size = prop.uhVal.QuadPart;
}
- return UpdateArchive(size, outStream, _props, updateCallback);
+
+ CMethodProps props2 = _props;
+ #ifndef _7ZIP_ST
+ props2.AddProp_NumThreads(_props._numThreads);
+ #endif
+
+ return UpdateArchive(size, outStream, props2, updateCallback);
}
if (indexInArchive != 0)
diff --git a/CPP/7zip/Archive/Common/CoderMixer2.cpp b/CPP/7zip/Archive/Common/CoderMixer2.cpp
index 7834c605..c7002121 100644
--- a/CPP/7zip/Archive/Common/CoderMixer2.cpp
+++ b/CPP/7zip/Archive/Common/CoderMixer2.cpp
@@ -91,6 +91,7 @@ HRESULT CCoder::CheckDataAfterEnd(bool &dataAfterEnd_Error /* , bool &InternalPa
{
CMyComPtr<ICompressGetInStreamProcessedSize2> getInStreamProcessedSize2;
Coder2.QueryInterface(IID_ICompressGetInStreamProcessedSize2, (void **)&getInStreamProcessedSize2);
+ if (getInStreamProcessedSize2)
FOR_VECTOR (i, PackSizePointers)
{
if (!PackSizePointers[i])
diff --git a/CPP/7zip/Archive/DmgHandler.cpp b/CPP/7zip/Archive/DmgHandler.cpp
index 5fe372dd..d9fe6016 100644
--- a/CPP/7zip/Archive/DmgHandler.cpp
+++ b/CPP/7zip/Archive/DmgHandler.cpp
@@ -788,9 +788,21 @@ HRESULT CHandler::Open2(IInStream *stream)
if (headSize != RSRC_HEAD_SIZE
|| footerOffset >= rsrcPair.Len
|| mainDataSize >= rsrcPair.Len
- || footerOffset + footerSize != rsrcPair.Len
+ || footerOffset < mainDataSize
|| footerOffset != headSize + mainDataSize)
return S_FALSE;
+
+ const UInt32 footerEnd = footerOffset + footerSize;
+ if (footerEnd != rsrcPair.Len)
+ {
+ // there is rare case dmg example, where there are 4 additional bytes
+ UInt64 rem = rsrcPair.Len - footerOffset;
+ if (rem < footerSize
+ || rem - footerSize != 4
+ || Get32(p + footerEnd) != 0)
+ return S_FALSE;
+ }
+
if (footerSize < 16)
return S_FALSE;
if (memcmp(p, p + footerOffset, 16) != 0)
diff --git a/CPP/7zip/Archive/ExtHandler.cpp b/CPP/7zip/Archive/ExtHandler.cpp
index d8417fe5..db65fbea 100644
--- a/CPP/7zip/Archive/ExtHandler.cpp
+++ b/CPP/7zip/Archive/ExtHandler.cpp
@@ -1596,6 +1596,17 @@ STDMETHODIMP CHandler::Close()
}
+static void ChangeSeparatorsInName(char *s, unsigned num)
+{
+ for (unsigned i = 0; i < num; i++)
+ {
+ char c = s[i];
+ if (c == CHAR_PATH_SEPARATOR || c == '/')
+ s[i] = '_';
+ }
+}
+
+
void CHandler::GetPath(unsigned index, AString &s) const
{
s.Empty();
@@ -1612,6 +1623,8 @@ void CHandler::GetPath(unsigned index, AString &s) const
if (!s.IsEmpty())
s.InsertAtFront(CHAR_PATH_SEPARATOR);
s.Insert(0, item.Name);
+ // 18.06
+ ChangeSeparatorsInName(s.GetBuf(), item.Name.Len());
if (item.ParentNode == k_INODE_ROOT)
return;
diff --git a/CPP/7zip/Archive/FatHandler.cpp b/CPP/7zip/Archive/FatHandler.cpp
index 9c37c062..d6623cd6 100644
--- a/CPP/7zip/Archive/FatHandler.cpp
+++ b/CPP/7zip/Archive/FatHandler.cpp
@@ -161,7 +161,8 @@ bool CHeader::Parse(const Byte *p)
return false;
// we also support images that contain 0 in offset field.
- bool isOkOffset = (codeOffset == 0 || (p[0] == 0xEB && p[1] == 0));
+ bool isOkOffset = (codeOffset == 0)
+ || (codeOffset == (p[0] == 0xEB ? 2 : 3));
UInt16 numRootDirEntries = Get16(p + 17);
if (numRootDirEntries == 0)
diff --git a/CPP/7zip/Archive/HfsHandler.cpp b/CPP/7zip/Archive/HfsHandler.cpp
index 3ff2e86e..ca1d7bda 100644
--- a/CPP/7zip/Archive/HfsHandler.cpp
+++ b/CPP/7zip/Archive/HfsHandler.cpp
@@ -419,7 +419,13 @@ void CDatabase::GetItemPath(unsigned index, NWindows::NCOM::CPropVariant &path)
const wchar_t *src = (const wchar_t *)*s;
wchar_t *dest = p + len;
for (unsigned j = 0; j < curLen; j++)
- dest[j] = src[j];
+ {
+ wchar_t c = src[j];
+ // 18.06
+ if (c == CHAR_PATH_SEPARATOR || c == '/')
+ c = '_';
+ dest[j] = c;
+ }
if (len == 0)
break;
diff --git a/CPP/7zip/Archive/LzmaHandler.cpp b/CPP/7zip/Archive/LzmaHandler.cpp
index afdc2bfa..9eac3ca1 100644
--- a/CPP/7zip/Archive/LzmaHandler.cpp
+++ b/CPP/7zip/Archive/LzmaHandler.cpp
@@ -131,13 +131,7 @@ HRESULT CDecoder::Code(const CHeader &header, ISequentialOutStream *outStream,
if (header.FilterID > 1)
return E_NOTIMPL;
- {
- CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
- _lzmaDecoder.QueryInterface(IID_ICompressSetDecoderProperties2, &setDecoderProperties);
- if (!setDecoderProperties)
- return E_NOTIMPL;
- RINOK(setDecoderProperties->SetDecoderProperties2(header.LzmaProps, 5));
- }
+ RINOK(_lzmaDecoderSpec->SetDecoderProperties2(header.LzmaProps, 5));
bool filteredMode = (header.FilterID == 1);
@@ -357,24 +351,54 @@ API_FUNC_static_IsArc IsArc_Lzma86(const Byte *p, size_t size)
}
}
+
+
STDMETHODIMP CHandler::Open(IInStream *inStream, const UInt64 *, IArchiveOpenCallback *)
{
Close();
- const UInt32 kBufSize = 1 + 5 + 8 + 2;
+ const unsigned headerSize = GetHeaderSize();
+ const UInt32 kBufSize = 1 << 7;
Byte buf[kBufSize];
-
- RINOK(ReadStream_FALSE(inStream, buf, kBufSize));
-
+ size_t processedSize = kBufSize;
+ RINOK(ReadStream(inStream, buf, &processedSize));
+ if (processedSize < headerSize + 2)
+ return S_FALSE;
if (!_header.Parse(buf, _lzma86))
return S_FALSE;
- const Byte *start = buf + GetHeaderSize();
+ const Byte *start = buf + headerSize;
if (start[0] != 0 /* || (start[1] & 0x80) != 0 */ ) // empty stream with EOS is not 0x80
return S_FALSE;
-
+
RINOK(inStream->Seek(0, STREAM_SEEK_END, &_packSize));
- if (_packSize >= 24 && _header.Size == 0 && _header.FilterID == 0 && _header.LzmaProps[0] == 0)
+
+ SizeT srcLen = processedSize - headerSize;
+
+ if (srcLen > 10
+ && _header.Size == 0
+ // && _header.FilterID == 0
+ && _header.LzmaProps[0] == 0
+ )
return S_FALSE;
+
+ CDecoder state;
+ const UInt32 outLimit = 1 << 11;
+ Byte outBuf[outLimit];
+
+ SizeT outSize = outLimit;
+ if (outSize > _header.Size)
+ outSize = (SizeT)_header.Size;
+ SizeT destLen = outSize;
+ ELzmaStatus status;
+
+ SRes res = LzmaDecode(outBuf, &destLen, start, &srcLen,
+ _header.LzmaProps, 5, LZMA_FINISH_ANY,
+ &status, &g_Alloc);
+
+ if (res != SZ_OK)
+ if (res != SZ_ERROR_INPUT_EOF)
+ return S_FALSE;
+
_isArc = true;
_stream = inStream;
_seqStream = inStream;
diff --git a/CPP/7zip/Archive/Nsis/NsisIn.cpp b/CPP/7zip/Archive/Nsis/NsisIn.cpp
index bbdab45a..f4f9ab04 100644
--- a/CPP/7zip/Archive/Nsis/NsisIn.cpp
+++ b/CPP/7zip/Archive/Nsis/NsisIn.cpp
@@ -2445,23 +2445,24 @@ void CInArchive::DetectNsisType(const CBlockHeader &bh, const Byte *p)
bool strongPark = false;
bool strongNsis = false;
+ if (NumStringChars > 2)
{
const Byte *strData = _data + _stringsPos;
if (IsUnicode)
{
- UInt32 num = NumStringChars;
+ UInt32 num = NumStringChars - 2;
for (UInt32 i = 0; i < num; i++)
{
if (Get16(strData + i * 2) == 0)
{
unsigned c2 = Get16(strData + 2 + i * 2);
+ // it can be TXT/RTF with marker char (1 or 2). so we must check next char
// if (c2 <= NS_3_CODE_SKIP && c2 != NS_3_CODE_SHELL)
if (c2 == NS_3_CODE_VAR)
{
- // it can be TXT/RTF string with marker char (1 or 2). so we must next char
- // const wchar_t *p2 = (const wchar_t *)(strData + i * 2 + 2);
- // p2 = p2;
- if ((Get16(strData + 3 + i * 2) & 0x8000) != 0)
+ // 18.06: fixed: is it correct ?
+ // if ((Get16(strData + 3 + i * 2) & 0x8000) != 0)
+ if ((Get16(strData + 4 + i * 2) & 0x8080) == 0x8080)
{
NsisType = k_NsisType_Nsis3;
strongNsis = true;
@@ -2478,7 +2479,7 @@ void CInArchive::DetectNsisType(const CBlockHeader &bh, const Byte *p)
}
else
{
- UInt32 num = NumStringChars;
+ UInt32 num = NumStringChars - 2;
for (UInt32 i = 0; i < num; i++)
{
if (strData[i] == 0)
diff --git a/CPP/7zip/Archive/NtfsHandler.cpp b/CPP/7zip/Archive/NtfsHandler.cpp
index 0eebf005..21372033 100644
--- a/CPP/7zip/Archive/NtfsHandler.cpp
+++ b/CPP/7zip/Archive/NtfsHandler.cpp
@@ -1475,6 +1475,21 @@ void CDatabase::ClearAndClose()
InStream.Release();
}
+
+static void CopyName(wchar_t *dest, const wchar_t *src)
+{
+ for (;;)
+ {
+ wchar_t c = *src++;
+ // 18.06
+ if (c == '\\' || c == '/')
+ c = '_';
+ *dest++ = c;
+ if (c == 0)
+ return;
+ }
+}
+
void CDatabase::GetItemPath(unsigned index, NCOM::CPropVariant &path) const
{
const CItem *item = &Items[index];
@@ -1492,7 +1507,7 @@ void CDatabase::GetItemPath(unsigned index, NCOM::CPropVariant &path) const
wchar_t *s = path.AllocBstr(data.Name.Len() + 1);
s[0] = L':';
if (!data.Name.IsEmpty())
- MyStringCopy(s + 1, data.Name.GetRawPtr());
+ CopyName(s + 1, data.Name.GetRawPtr());
return;
}
@@ -1541,7 +1556,7 @@ void CDatabase::GetItemPath(unsigned index, NCOM::CPropVariant &path) const
if (!name.IsEmpty())
{
size -= name.Len();
- MyStringCopy(s + size, name.GetRawPtr());
+ CopyName(s + size, name.GetRawPtr());
}
s[--size] = ':';
needColon = true;
@@ -1551,7 +1566,7 @@ void CDatabase::GetItemPath(unsigned index, NCOM::CPropVariant &path) const
const UString2 &name = rec.FileNames[item->NameIndex].Name;
unsigned len = name.Len();
if (len != 0)
- MyStringCopy(s + size - len, name.GetRawPtr());
+ CopyName(s + size - len, name.GetRawPtr());
if (needColon)
s[size] = ':';
size -= len;
@@ -1575,7 +1590,7 @@ void CDatabase::GetItemPath(unsigned index, NCOM::CPropVariant &path) const
if (len != 0)
{
size -= len;
- MyStringCopy(s + size, name.GetRawPtr());
+ CopyName(s + size, name.GetRawPtr());
}
s[size + len] = WCHAR_PATH_SEPARATOR;
continue;
diff --git a/CPP/7zip/Archive/Rar/Rar5Handler.cpp b/CPP/7zip/Archive/Rar/Rar5Handler.cpp
index 17fcccc3..8b99201f 100644
--- a/CPP/7zip/Archive/Rar/Rar5Handler.cpp
+++ b/CPP/7zip/Archive/Rar/Rar5Handler.cpp
@@ -1000,7 +1000,7 @@ bool CInArchive::ReadFileHeader(const CHeader &header, CItem &item)
struct CLinkFile
{
unsigned Index;
- unsigned NumLinks;
+ unsigned NumLinks; // the number of links to Data
CByteBuffer Data;
HRESULT Res;
bool crcOK;
@@ -1015,7 +1015,7 @@ struct CUnpacker
CMyComPtr<ICompressCoder> copyCoder;
CMyComPtr<ICompressCoder> LzCoders[2];
- bool NeedClearSolid[2];
+ bool SolidAllowed;
CFilterCoder *filterStreamSpec;
CMyComPtr<ISequentialInStream> filterStream;
@@ -1032,7 +1032,7 @@ struct CUnpacker
CLinkFile *linkFile;
- CUnpacker(): linkFile(NULL) { NeedClearSolid[0] = NeedClearSolid[1] = true; }
+ CUnpacker(): linkFile(NULL) { SolidAllowed = false; }
HRESULT Create(DECL_EXTERNAL_CODECS_LOC_VARS const CItem &item, bool isSolid, bool &wrongPassword);
@@ -1142,7 +1142,9 @@ HRESULT CUnpacker::Code(const CItem &item, const CItem &lastItem, UInt64 packSiz
if (method > kLzMethodMax)
return E_NOTIMPL;
- if (linkFile && !lastItem.Is_UnknownSize())
+ bool needBuf = (linkFile && linkFile->NumLinks != 0);
+
+ if (needBuf && !lastItem.Is_UnknownSize())
{
size_t dataSize = (size_t)lastItem.Size;
if (dataSize != lastItem.Size)
@@ -1167,15 +1169,15 @@ HRESULT CUnpacker::Code(const CItem &item, const CItem &lastItem, UInt64 packSiz
ICompressCoder *commonCoder = (method == 0) ? copyCoder : LzCoders[item.IsService() ? 1 : 0];
outStreamSpec->SetStream(realOutStream);
- outStreamSpec->Init(lastItem, (linkFile ? (Byte *)linkFile->Data : NULL));
-
- NeedClearSolid[item.IsService() ? 1 : 0] = false;
+ outStreamSpec->Init(lastItem, (needBuf ? (Byte *)linkFile->Data : NULL));
HRESULT res = S_OK;
if (packSize != 0 || lastItem.Is_UnknownSize() || lastItem.Size != 0)
{
res = commonCoder->Code(inStream, outStream, &packSize,
lastItem.Is_UnknownSize() ? NULL : &lastItem.Size, progress);
+ if (!item.IsService())
+ SolidAllowed = true;
}
else
{
@@ -1210,7 +1212,9 @@ HRESULT CUnpacker::Code(const CItem &item, const CItem &lastItem, UInt64 packSiz
{
linkFile->Res = res;
linkFile->crcOK = isCrcOK;
- if (!lastItem.Is_UnknownSize() && processedSize != lastItem.Size)
+ if (needBuf
+ && !lastItem.Is_UnknownSize()
+ && processedSize != lastItem.Size)
linkFile->Data.ChangeSize_KeepData((size_t)processedSize, (size_t)processedSize);
}
@@ -2578,6 +2582,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
const Byte kStatus_Skip = 1 << 1;
const Byte kStatus_Link = 1 << 2;
+ /*
+ In original RAR:
+ 1) service streams are not allowed to be solid,
+ and solid flag must be ignored for service streams.
+ 2) If RAR creates new solid block and first file in solid block is Link file,
+ then it can clear solid flag for Link file and
+ clear solid flag for first non-Link file after Link file.
+ */
+
CObjectVector<CLinkFile> linkFiles;
{
@@ -2603,13 +2616,15 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (ref.Link >= 0)
{
- if (!testMode)
+ // 18.06 fixed: we use links for Test mode too
+ // if (!testMode)
{
if ((unsigned)ref.Link < index)
{
const CRefItem &linkRef = _refs[(unsigned)ref.Link];
const CItem &linkItem = _items[linkRef.Item];
- if (linkItem.IsSolid() && linkItem.Size <= k_CopyLinkFile_MaxSize)
+ if (linkItem.IsSolid())
+ if (testMode || linkItem.Size <= k_CopyLinkFile_MaxSize)
{
if (extractStatuses[(unsigned)ref.Link] == 0)
{
@@ -2664,19 +2679,25 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
{
unsigned solidLimit = 0;
- FOR_VECTOR(i, _refs)
+ FOR_VECTOR (i, _refs)
{
if ((extractStatuses[i] & kStatus_Link) == 0)
continue;
+
+ // We use CLinkFile for testMode too.
+ // So we can show errors for copy files.
+ // if (!testMode)
+ {
+ CLinkFile &linkFile = linkFiles.AddNew();
+ linkFile.Index = i;
+ }
+
const CItem &item = _items[_refs[i].Item];
/*
if (item.IsService())
continue;
*/
- CLinkFile &linkFile = linkFiles.AddNew();
- linkFile.Index = i;
-
if (item.IsSolid())
{
unsigned j = i;
@@ -2707,6 +2728,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
solidLimit = i + 1;
}
+ if (!testMode)
for (UInt32 t = 0; t < numItems; t++)
{
unsigned index = allFilesMode ? t : indices[t];
@@ -2748,7 +2770,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
// bool needClearSolid = true;
- FOR_VECTOR(i, _refs)
+ FOR_VECTOR (i, _refs)
{
if (extractStatuses[i] == 0)
continue;
@@ -2761,15 +2783,19 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
CMyComPtr<ISequentialOutStream> realOutStream;
+ // isExtract means that we don't skip that item. So we need read data.
+
+ bool isExtract = ((extractStatuses[i] & kStatus_Extract) != 0);
Int32 askMode =
- ((extractStatuses[i] & kStatus_Extract) != 0) ? (testMode ?
+ isExtract ? (testMode ?
NExtract::NAskMode::kTest :
NExtract::NAskMode::kExtract) :
NExtract::NAskMode::kSkip;
unpacker.linkFile = NULL;
- if (((extractStatuses[i] & kStatus_Link) != 0))
+ // if (!testMode)
+ if ((extractStatuses[i] & kStatus_Link) != 0)
{
int bufIndex = FindLinkBuf(linkFiles, i);
if (bufIndex < 0)
@@ -2791,13 +2817,12 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
- bool isSolid;
+ bool isSolid = false;
+ if (!item->IsService())
{
- bool &needClearSolid = unpacker.NeedClearSolid[item->IsService() ? 1 : 0];
- isSolid = (item->IsSolid() && !needClearSolid);
- if (item->IsService())
- isSolid = false;
- needClearSolid = !item->IsSolid();
+ if (item->IsSolid())
+ isSolid = unpacker.SolidAllowed;
+ unpacker.SolidAllowed = isSolid;
}
if (item->IsDir())
@@ -2826,18 +2851,30 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
curUnpackSize = 0;
curPackSize = GetPackSize(index2);
}
- else if ((unsigned)index2 < index)
- bufIndex = FindLinkBuf(linkFiles, index2);
+ else
+ {
+ if ((unsigned)index2 < index)
+ bufIndex = FindLinkBuf(linkFiles, index2);
+ }
}
+ bool needCallback = true;
+
if (!realOutStream)
{
if (testMode)
{
if (item->NeedUse_as_CopyLink_or_HardLink())
{
+ Int32 opRes = NExtract::NOperationResult::kOK;
+ if (bufIndex >= 0)
+ {
+ const CLinkFile &linkFile = linkFiles[bufIndex];
+ opRes = DecoderRes_to_OpRes(linkFile.Res, linkFile.crcOK);
+ }
+
RINOK(extractCallback->PrepareOperation(askMode));
- RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
+ RINOK(extractCallback->SetOperationResult(opRes));
continue;
}
}
@@ -2846,10 +2883,10 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (item->IsService())
continue;
- if (item->NeedUse_as_HardLink())
- continue;
+ needCallback = false;
- bool needDecode = false;
+ if (!item->NeedUse_as_HardLink())
+ if (index2 < 0)
for (unsigned n = i + 1; n < _refs.Size(); n++)
{
@@ -2860,41 +2897,56 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
break;
if (extractStatuses[i] != 0)
{
- needDecode = true;
+ needCallback = true;
break;
}
}
- if (!needDecode)
- continue;
-
askMode = NExtract::NAskMode::kSkip;
}
}
- RINOK(extractCallback->PrepareOperation(askMode));
+ if (needCallback)
+ {
+ RINOK(extractCallback->PrepareOperation(askMode));
+ }
if (bufIndex >= 0)
{
CLinkFile &linkFile = linkFiles[bufIndex];
- if (linkFile.NumLinks == 0)
- return E_FAIL;
- if (realOutStream)
+
+ if (isExtract)
{
- RINOK(CopyData_with_Progress(linkFile.Data, linkFile.Data.Size(), realOutStream, progress));
+ if (linkFile.NumLinks == 0)
+ return E_FAIL;
+
+ if (needCallback)
+ if (realOutStream)
+ {
+ RINOK(CopyData_with_Progress(linkFile.Data, linkFile.Data.Size(), realOutStream, progress));
+ }
+
+ if (--linkFile.NumLinks == 0)
+ linkFile.Data.Free();
+ }
+
+ if (needCallback)
+ {
+ RINOK(extractCallback->SetOperationResult(DecoderRes_to_OpRes(linkFile.Res, linkFile.crcOK)));
}
- if (--linkFile.NumLinks == 0)
- linkFile.Data.Free();
- RINOK(extractCallback->SetOperationResult(DecoderRes_to_OpRes(linkFile.Res, linkFile.crcOK)));
continue;
}
+ if (!needCallback)
+ continue;
+
if (item->NeedUse_as_CopyLink())
{
- RINOK(extractCallback->SetOperationResult(
- realOutStream ?
- NExtract::NOperationResult::kUnsupportedMethod:
- NExtract::NOperationResult::kOK));
+ int opRes = realOutStream ?
+ NExtract::NOperationResult::kUnsupportedMethod:
+ NExtract::NOperationResult::kOK;
+ realOutStream.Release();
+ RINOK(extractCallback->SetOperationResult(opRes));
continue;
}
@@ -2941,7 +2993,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems,
}
{
- FOR_VECTOR(i, linkFiles)
+ FOR_VECTOR (i, linkFiles)
if (linkFiles[i].NumLinks != 0)
return E_FAIL;
}
diff --git a/CPP/7zip/Archive/Rar/RarHandler.cpp b/CPP/7zip/Archive/Rar/RarHandler.cpp
index 4b54e071..ce1df22e 100644
--- a/CPP/7zip/Archive/Rar/RarHandler.cpp
+++ b/CPP/7zip/Archive/Rar/RarHandler.cpp
@@ -415,6 +415,8 @@ bool CInArchive::ReadHeaderReal(const Byte *p, unsigned size, CItem &item)
if (size < 8)
return false;
item.PackSize |= ((UInt64)Get32(p) << 32);
+ if (item.PackSize >= ((UInt64)1 << 63))
+ return false;
item.Size |= ((UInt64)Get32(p + 4) << 32);
p += 8;
size -= 8;
@@ -667,7 +669,8 @@ HRESULT CInArchive::GetNextItem(CItem &item, ICryptoGetTextPassword *getTextPass
{
if (processed < offset + 2)
error = k_ErrorType_Corrupted;
- ArcInfo.VolNumber = (UInt32)Get16(m_FileHeaderData + offset);
+ else
+ ArcInfo.VolNumber = (UInt32)Get16(m_FileHeaderData + offset);
}
ArcInfo.EndOfArchive_was_Read = true;
diff --git a/CPP/7zip/Archive/SquashfsHandler.cpp b/CPP/7zip/Archive/SquashfsHandler.cpp
index 5c024328..89de660f 100644
--- a/CPP/7zip/Archive/SquashfsHandler.cpp
+++ b/CPP/7zip/Archive/SquashfsHandler.cpp
@@ -4,6 +4,7 @@
#include "../../../C/Alloc.h"
#include "../../../C/CpuArch.h"
+#include "../../../C/LzmaDec.h"
#include "../../../C/Xz.h"
#include "../../Common/ComTry.h"
@@ -24,7 +25,7 @@
#include "../Compress/CopyCoder.h"
#include "../Compress/ZlibDecoder.h"
-#include "../Compress/LzmaDecoder.h"
+// #include "../Compress/LzmaDecoder.h"
namespace NArchive {
namespace NSquashfs {
@@ -866,8 +867,8 @@ class CHandler:
CBufPtrSeqOutStream *_outStreamSpec;
CMyComPtr<ISequentialOutStream> _outStream;
- NCompress::NLzma::CDecoder *_lzmaDecoderSpec;
- CMyComPtr<ICompressCoder> _lzmaDecoder;
+ // NCompress::NLzma::CDecoder *_lzmaDecoderSpec;
+ // CMyComPtr<ICompressCoder> _lzmaDecoder;
NCompress::NZlib::CDecoder *_zlibDecoderSpec;
CMyComPtr<ICompressCoder> _zlibDecoder;
@@ -1155,12 +1156,13 @@ HRESULT CHandler::Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool
if (inSize != _zlibDecoderSpec->GetInputProcessedSize())
return S_FALSE;
}
+ /*
else if (method == kMethod_LZMA)
{
if (!_lzmaDecoder)
{
_lzmaDecoderSpec = new NCompress::NLzma::CDecoder();
- _lzmaDecoderSpec->FinishStream = true;
+ // _lzmaDecoderSpec->FinishStream = true;
_lzmaDecoder = _lzmaDecoderSpec;
}
const UInt32 kPropsSize = LZMA_PROPS_SIZE + 8;
@@ -1187,6 +1189,7 @@ HRESULT CHandler::Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool
if (inSize != propsSize + _lzmaDecoderSpec->GetInputProcessedSize())
return S_FALSE;
}
+ */
else
{
if (_inputBuffer.Size() < inSize)
@@ -1200,11 +1203,49 @@ HRESULT CHandler::Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool
if (!dest)
return E_OUTOFMEMORY;
}
+
SizeT destLen = outSizeMax, srcLen = inSize;
+
if (method == kMethod_LZO)
{
RINOK(LzoDecode(dest, &destLen, _inputBuffer, &srcLen));
}
+ else if (method == kMethod_LZMA)
+ {
+ Byte props[5];
+ const Byte *src = _inputBuffer;
+
+ if (_noPropsLZMA)
+ {
+ props[0] = 0x5D;
+ SetUi32(&props[1], _h.BlockSize);
+ }
+ else
+ {
+ const UInt32 kPropsSize = LZMA_PROPS_SIZE + 8;
+ if (inSize < kPropsSize)
+ return S_FALSE;
+ memcpy(props, src, LZMA_PROPS_SIZE);
+ UInt64 outSize = GetUi64(src + LZMA_PROPS_SIZE);
+ if (outSize > outSizeMax)
+ return S_FALSE;
+ destLen = (SizeT)outSize;
+ src += kPropsSize;
+ inSize -= kPropsSize;
+ srcLen = inSize;
+ }
+
+ ELzmaStatus status;
+ SRes res = LzmaDecode(dest, &destLen,
+ src, &srcLen,
+ props, LZMA_PROPS_SIZE,
+ LZMA_FINISH_END,
+ &status, &g_Alloc);
+ if (res != 0)
+ return SResToHRESULT(res);
+ if (status != LZMA_STATUS_FINISHED_WITH_MARK)
+ return S_FALSE;
+ }
else
{
ECoderStatus status;
@@ -1217,6 +1258,7 @@ HRESULT CHandler::Decompress(ISequentialOutStream *outStream, Byte *outBuf, bool
if (status != CODER_STATUS_NEEDS_MORE_INPUT || !XzUnpacker_IsStreamWasFinished(&_xz))
return S_FALSE;
}
+
if (inSize != srcLen)
return S_FALSE;
if (outBuf)
diff --git a/CPP/7zip/Archive/SwfHandler.cpp b/CPP/7zip/Archive/SwfHandler.cpp
index 16a6e6f9..ebb6acfd 100644
--- a/CPP/7zip/Archive/SwfHandler.cpp
+++ b/CPP/7zip/Archive/SwfHandler.cpp
@@ -46,7 +46,7 @@ static const Byte SWF_COMPRESSED_LZMA = 'Z';
static const Byte SWF_MIN_COMPRESSED_ZLIB_VER = 6;
static const Byte SWF_MIN_COMPRESSED_LZMA_VER = 13;
-static const Byte kVerLim = 20;
+static const Byte kVerLim = 64;
API_FUNC_static_IsArc IsArc_Swf(const Byte *p, size_t size)
{
diff --git a/CPP/7zip/Archive/Tar/TarIn.cpp b/CPP/7zip/Archive/Tar/TarIn.cpp
index d432c318..32761658 100644
--- a/CPP/7zip/Archive/Tar/TarIn.cpp
+++ b/CPP/7zip/Archive/Tar/TarIn.cpp
@@ -443,14 +443,14 @@ HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item, EErro
case 'X':
{
// pax Extended Header
- if (item.Name.IsPrefixedBy("PaxHeader/"))
+ if (item.Name.IsPrefixedBy("PaxHeader/")
+ || item.Name.Find("PaxHeaders.4467/") >= 0)
{
RINOK(ReadDataToString(stream, item, pax, error));
if (error != k_ErrorType_OK)
return S_OK;
continue;
}
-
break;
}
case NFileHeader::NLinkFlag::kDumpDir:
@@ -488,7 +488,11 @@ HRESULT ReadItem(ISequentialInStream *stream, bool &filled, CItemEx &item, EErro
if (ParsePaxLongName(pax, name))
item.Name = name;
else
- error = k_ErrorType_Warning;
+ {
+ // no "path" property is allowed in pax4467
+ // error = k_ErrorType_Warning;
+ }
+ pax.Empty();
}
return S_OK;
diff --git a/CPP/7zip/Archive/Wim/WimIn.cpp b/CPP/7zip/Archive/Wim/WimIn.cpp
index b934478e..3c712084 100644
--- a/CPP/7zip/Archive/Wim/WimIn.cpp
+++ b/CPP/7zip/Archive/Wim/WimIn.cpp
@@ -111,7 +111,9 @@ HRESULT CUnpacker::UnpackChunk(
}
else if (method == NMethod::kLZX)
{
- lzxDecoderSpec->SetExternalWindow(unpackBuf.Data, chunkSizeBits);
+ res = lzxDecoderSpec->SetExternalWindow(unpackBuf.Data, chunkSizeBits);
+ if (res != S_OK)
+ return E_NOTIMPL;
lzxDecoderSpec->KeepHistoryForNext = false;
lzxDecoderSpec->SetKeepHistory(false);
res = lzxDecoderSpec->Code(packBuf.Data, inSize, (UInt32)outSize);
@@ -563,7 +565,13 @@ void CDatabase::GetItemPath(unsigned index1, bool showImageNumber, NWindows::NCO
wchar_t *dest = s + size;
meta += 2;
for (unsigned i = 0; i < len; i++)
- dest[i] = Get16(meta + i * 2);
+ {
+ wchar_t c = Get16(meta + i * 2);
+ // 18.06
+ if (c == CHAR_PATH_SEPARATOR || c == '/')
+ c = '_';
+ dest[i] = c;
+ }
}
if (index < 0)
return;
@@ -866,7 +874,11 @@ HRESULT CDatabase::ParseImageDirs(CByteBuffer &buf, int parent)
if (DirProcessed == DirSize - 8 && Get64(p + DirSize - 8) != 0)
return S_OK;
- return S_FALSE;
+ // 18.06: we support cases, when some old dism can capture images
+ // where DirProcessed much smaller than DirSize
+ HeadersError = true;
+ return S_OK;
+ // return S_FALSE;
}
diff --git a/CPP/7zip/Archive/Wim/WimIn.h b/CPP/7zip/Archive/Wim/WimIn.h
index 6a387212..9e835b01 100644
--- a/CPP/7zip/Archive/Wim/WimIn.h
+++ b/CPP/7zip/Archive/Wim/WimIn.h
@@ -468,7 +468,7 @@ public:
int ExludedItem; // -1 : if there are no exclude items
CUIntVector VirtualRoots; // we use them for old 1.10 WIM archives
- bool ThereIsError() const { return RefCountError; }
+ bool ThereIsError() const { return RefCountError || HeadersError; }
unsigned GetNumUserItemsInImage(unsigned imageIndex) const
{
@@ -544,7 +544,10 @@ public:
HeadersError = false;
}
- CDatabase(): RefCountError(false) {}
+ CDatabase():
+ RefCountError(false),
+ HeadersError(false)
+ {}
void GetShortName(unsigned index, NWindows::NCOM::CPropVariant &res) const;
void GetItemName(unsigned index1, NWindows::NCOM::CPropVariant &res) const;
diff --git a/CPP/7zip/Archive/XzHandler.cpp b/CPP/7zip/Archive/XzHandler.cpp
index ddaddcd5..801619fb 100644
--- a/CPP/7zip/Archive/XzHandler.cpp
+++ b/CPP/7zip/Archive/XzHandler.cpp
@@ -488,7 +488,7 @@ HRESULT CHandler::Open2(IInStream *inStream, /* UInt32 flags, */ IArchiveOpenCal
{
CXzBlock block;
- Bool isIndex;
+ BoolInt isIndex;
UInt32 headerSizeRes;
SRes res2 = XzBlock_ReadHeader(&block, &inStreamWrap.vt, &isIndex, &headerSizeRes);
if (res2 == SZ_OK && !isIndex)
@@ -820,7 +820,7 @@ static HRESULT DecodeBlock(CXzUnpackerCPP2 &xzu,
packRem -= inLen;
- Bool blockFinished = XzUnpacker_IsBlockFinished(&xzu.p);
+ BoolInt blockFinished = XzUnpacker_IsBlockFinished(&xzu.p);
if ((inLen == 0 && outLen == 0) || blockFinished)
{
diff --git a/CPP/7zip/Archive/Zip/ZipHandler.cpp b/CPP/7zip/Archive/Zip/ZipHandler.cpp
index 494b9d70..a4794f51 100644
--- a/CPP/7zip/Archive/Zip/ZipHandler.cpp
+++ b/CPP/7zip/Archive/Zip/ZipHandler.cpp
@@ -599,8 +599,12 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
case kpidHostOS:
{
- const Byte hostOS = item.GetHostOS();
- TYPE_TO_PROP(kHostOS, hostOS, prop);
+ if (item.FromCentral)
+ {
+ // 18.06: now we use HostOS only from Central::MadeByVersion
+ const Byte hostOS = item.MadeByVersion.HostOS;
+ TYPE_TO_PROP(kHostOS, hostOS, prop);
+ }
break;
}
diff --git a/CPP/7zip/Archive/Zip/ZipIn.cpp b/CPP/7zip/Archive/Zip/ZipIn.cpp
index aa7184af..509753c2 100644
--- a/CPP/7zip/Archive/Zip/ZipIn.cpp
+++ b/CPP/7zip/Archive/Zip/ZipIn.cpp
@@ -155,6 +155,7 @@ void CInArchive::Close()
HeadersError = false;
HeadersWarning = false;
ExtraMinorError = false;
+
UnexpectedEnd = false;
LocalsWereRead = false;
LocalsCenterMerged = false;
@@ -1729,6 +1730,9 @@ HRESULT CInArchive::FindCd(bool checkOffsetMode)
HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, const CCdInfo &cdInfo, UInt64 cdOffset, UInt64 cdSize)
{
items.Clear();
+
+ // _startLocalFromCd_Disk = (UInt32)(Int32)-1;
+ // _startLocalFromCd_Offset = (UInt64)(Int64)-1;
RINOK(SeekToVol(IsMultiVol ? cdInfo.CdDisk : -1, cdOffset));
@@ -1752,6 +1756,17 @@ HRESULT CInArchive::TryReadCd(CObjectVector<CItemEx> &items, const CCdInfo &cdIn
{
CItemEx cdItem;
RINOK(ReadCdItem(cdItem));
+
+ /*
+ if (cdItem.Disk < _startLocalFromCd_Disk ||
+ cdItem.Disk == _startLocalFromCd_Disk &&
+ cdItem.LocalHeaderPos < _startLocalFromCd_Offset)
+ {
+ _startLocalFromCd_Disk = cdItem.Disk;
+ _startLocalFromCd_Offset = cdItem.LocalHeaderPos;
+ }
+ */
+
items.Add(cdItem);
}
if (Callback && (items.Size() & 0xFFF) == 0)
@@ -2509,6 +2524,8 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items)
{
ArcInfo.CdWasRead = true;
ArcInfo.FirstItemRelatOffset = items[0].LocalHeaderPos;
+
+ // ArcInfo.FirstItemRelatOffset = _startLocalFromCd_Offset;
}
}
}
@@ -2535,6 +2552,10 @@ HRESULT CInArchive::ReadHeaders(CObjectVector<CItemEx> &items)
items.Clear();
localsWereRead = true;
+ HeadersError = false;
+ HeadersWarning = false;
+ ExtraMinorError = false;
+
// we can use any mode: with buffer and without buffer
// without buffer : skips packed data : fast for big files : slow for small files
// with buffer : reads packed data : slow for big files : fast for small files
diff --git a/CPP/7zip/Archive/Zip/ZipIn.h b/CPP/7zip/Archive/Zip/ZipIn.h
index 88f29569..f46f1f07 100644
--- a/CPP/7zip/Archive/Zip/ZipIn.h
+++ b/CPP/7zip/Archive/Zip/ZipIn.h
@@ -250,6 +250,9 @@ class CInArchive
UInt64 _streamPos;
UInt64 _cnt;
+ // UInt32 _startLocalFromCd_Disk;
+ // UInt64 _startLocalFromCd_Offset;
+
size_t GetAvail() const { return _bufCached - _bufPos; }
void InitBuf() { _bufPos = 0; _bufCached = 0; }
@@ -383,6 +386,9 @@ public:
UInt64 GetEmbeddedStubSize() const
{
+ // it's possible that first item in CD doesn refers to first local item
+ // so FirstItemRelatOffset is not first local item
+
if (ArcInfo.CdWasRead)
return ArcInfo.FirstItemRelatOffset;
if (IsMultiVol)
diff --git a/CPP/7zip/Archive/Zip/ZipItem.h b/CPP/7zip/Archive/Zip/ZipItem.h
index 78e3e01c..e5769711 100644
--- a/CPP/7zip/Archive/Zip/ZipItem.h
+++ b/CPP/7zip/Archive/Zip/ZipItem.h
@@ -214,6 +214,12 @@ class CLocalItem
public:
UInt16 Flags;
UInt16 Method;
+
+ /*
+ Zip specification doesn't mention that ExtractVersion field uses HostOS subfield.
+ 18.06: 7-Zip now doesn't use ExtractVersion::HostOS to detect codePage
+ */
+
CVersion ExtractVersion;
UInt64 Size;
@@ -309,7 +315,8 @@ public:
UInt32 GetWinAttrib() const;
bool GetPosixAttrib(UInt32 &attrib) const;
- Byte GetHostOS() const { return FromCentral ? MadeByVersion.HostOS : ExtractVersion.HostOS; }
+ // 18.06: 0 instead of ExtractVersion.HostOS for local item
+ Byte GetHostOS() const { return FromCentral ? MadeByVersion.HostOS : (Byte)0; }
void GetUnicodeString(UString &res, const AString &s, bool isComment, bool useSpecifiedCodePage, UINT codePage) const;
@@ -326,7 +333,10 @@ public:
UINT GetCodePage() const
{
- Byte hostOS = GetHostOS();
+ // 18.06: now we use HostOS only from Central::MadeByVersion
+ if (!FromCentral)
+ return CP_OEMCP;
+ Byte hostOS = MadeByVersion.HostOS;
return (UINT)((
hostOS == NFileHeader::NHostOS::kFAT
|| hostOS == NFileHeader::NHostOS::kNTFS
diff --git a/CPP/7zip/Archive/Zip/ZipUpdate.cpp b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
index 2289203b..e65c2b8b 100644
--- a/CPP/7zip/Archive/Zip/ZipUpdate.cpp
+++ b/CPP/7zip/Archive/Zip/ZipUpdate.cpp
@@ -40,7 +40,10 @@ static const Byte kHostOS =
#endif
static const Byte kMadeByHostOS = kHostOS;
-static const Byte kExtractHostOS = kHostOS;
+
+// 18.06: now we always write zero to high byte of ExtractVersion field.
+// Previous versions of p7zip wrote (NFileHeader::NHostOS::kUnix) there, that is not correct
+static const Byte kExtractHostOS = 0;
static const Byte kMethodForDirectory = NFileHeader::NCompressionMethod::kStore;
diff --git a/CPP/7zip/Bundles/LzmaCon/makefile b/CPP/7zip/Bundles/LzmaCon/makefile
index 54919f73..74e5463a 100644
--- a/CPP/7zip/Bundles/LzmaCon/makefile
+++ b/CPP/7zip/Bundles/LzmaCon/makefile
@@ -55,5 +55,6 @@ C_OBJS = \
$O\Threads.obj \
!include "../../Crc.mak"
+!include "../../LzmaDec.mak"
!include "../../7zip.mak"
diff --git a/CPP/7zip/Compress/DeflateDecoder.cpp b/CPP/7zip/Compress/DeflateDecoder.cpp
index 88ab1f91..fceef857 100644
--- a/CPP/7zip/Compress/DeflateDecoder.cpp
+++ b/CPP/7zip/Compress/DeflateDecoder.cpp
@@ -446,6 +446,14 @@ void CCoder::SetOutStreamSizeResume(const UInt64 *outSize)
STDMETHODIMP CCoder::SetOutStreamSize(const UInt64 *outSize)
{
+ /*
+ 18.06:
+ We want to support GetInputProcessedSize() before CCoder::Read()
+ So we call m_InBitStream.Init() even before buffer allocations
+ m_InBitStream.Init() just sets variables to default values
+ But later we will call m_InBitStream.Init() again with real buffer pointers
+ */
+ m_InBitStream.Init();
_needInitInStream = true;
SetOutStreamSizeResume(outSize);
return S_OK;
diff --git a/CPP/7zip/Compress/LzmsDecoder.cpp b/CPP/7zip/Compress/LzmsDecoder.cpp
index 02a7f5dc..5189ce16 100644
--- a/CPP/7zip/Compress/LzmsDecoder.cpp
+++ b/CPP/7zip/Compress/LzmsDecoder.cpp
@@ -517,9 +517,9 @@ HRESULT CDecoder::CodeReal(const Byte *in, size_t inSize, Byte *_win, size_t out
if (len > outSize - _pos)
return S_FALSE;
- if (dist > _pos)
- return S_FALSE;
size_t span = (size_t)1 << power;
+ if ((UInt64)dist + span > _pos)
+ return S_FALSE;
Byte *dest = _win + _pos - span;
const Byte *src = dest - dist;
_pos += len;
diff --git a/CPP/7zip/Compress/Rar3Decoder.cpp b/CPP/7zip/Compress/Rar3Decoder.cpp
index 10e8bff6..4456ba63 100644
--- a/CPP/7zip/Compress/Rar3Decoder.cpp
+++ b/CPP/7zip/Compress/Rar3Decoder.cpp
@@ -148,7 +148,8 @@ void CDecoder::ExecuteFilter(unsigned tempFilterIndex, NVm::CBlockRef &outBlockR
if (!_vm.Execute(filter, tempFilter, outBlockRef, filter->GlobalData))
_unsupportedFilter = true;
delete tempFilter;
- _tempFilters[tempFilterIndex] = 0;
+ _tempFilters[tempFilterIndex] = NULL;
+ _numEmptyTempFilters++;
}
HRESULT CDecoder::WriteBuf()
@@ -225,6 +226,7 @@ HRESULT CDecoder::WriteBuf()
void CDecoder::InitFilters()
{
_lastFilter = 0;
+ _numEmptyTempFilters = 0;
unsigned i;
for (i = 0; i < _tempFilters.Size(); i++)
delete _tempFilters[i];
@@ -274,24 +276,27 @@ bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize)
filter->ExecCount++;
}
- unsigned numEmptyItems = 0;
+ if (_numEmptyTempFilters != 0)
{
- FOR_VECTOR (i, _tempFilters)
+ unsigned num = _tempFilters.Size();
+ CTempFilter **tempFilters = &_tempFilters.Front();
+
+ unsigned w = 0;
+ for (unsigned i = 0; i < num; i++)
{
- _tempFilters[i - numEmptyItems] = _tempFilters[i];
- if (!_tempFilters[i])
- numEmptyItems++;
- if (numEmptyItems != 0)
- _tempFilters[i] = NULL;
+ CTempFilter *tf = tempFilters[i];
+ if (tf)
+ tempFilters[w++] = tf;
}
+
+ _tempFilters.DeleteFrom(w);
+ _numEmptyTempFilters = 0;
}
- if (numEmptyItems == 0)
- {
- _tempFilters.Add(NULL);
- numEmptyItems = 1;
- }
+
+ if (_tempFilters.Size() > MAX_UNPACK_FILTERS)
+ return false;
CTempFilter *tempFilter = new CTempFilter;
- _tempFilters[_tempFilters.Size() - numEmptyItems] = tempFilter;
+ _tempFilters.Add(tempFilter);
tempFilter->FilterIndex = filterIndex;
UInt32 blockStart = inp.ReadEncodedUInt32();
diff --git a/CPP/7zip/Compress/Rar3Decoder.h b/CPP/7zip/Compress/Rar3Decoder.h
index fbc5ac2e..3d319ded 100644
--- a/CPP/7zip/Compress/Rar3Decoder.h
+++ b/CPP/7zip/Compress/Rar3Decoder.h
@@ -189,6 +189,7 @@ class CDecoder:
NVm::CVm _vm;
CRecordVector<CFilter *> _filters;
CRecordVector<CTempFilter *> _tempFilters;
+ unsigned _numEmptyTempFilters;
UInt32 _lastFilter;
bool _isSolid;
diff --git a/CPP/7zip/Compress/XpressDecoder.cpp b/CPP/7zip/Compress/XpressDecoder.cpp
index a38d9418..864c6f8f 100644
--- a/CPP/7zip/Compress/XpressDecoder.cpp
+++ b/CPP/7zip/Compress/XpressDecoder.cpp
@@ -33,10 +33,11 @@ struct CBitStream
bs.Value = (bs.Value << 16) | GetUi16(in); \
in += 2; bs.BitPos += 16; }
-const unsigned kNumHuffBits = 15;
-const unsigned kNumLenSlots = 16;
-const unsigned kNumPosSlots = 16;
-const unsigned kNumSyms = 256 + kNumPosSlots * kNumLenSlots;
+static const unsigned kNumHuffBits = 15;
+static const unsigned kNumLenBits = 4;
+static const unsigned kLenMask = (1 << kNumLenBits) - 1;
+static const unsigned kNumPosSlots = 16;
+static const unsigned kNumSyms = 256 + (kNumPosSlots << kNumLenBits);
HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
{
@@ -83,10 +84,10 @@ HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
else
{
sym -= 256;
- UInt32 dist = sym / kNumLenSlots;
- UInt32 len = sym & (kNumLenSlots - 1);
+ UInt32 dist = sym >> kNumLenBits;
+ UInt32 len = sym & kLenMask;
- if (len == kNumLenSlots - 1)
+ if (len == kLenMask)
{
if (in > lim)
return S_FALSE;
@@ -99,7 +100,7 @@ HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
in += 2;
}
else
- len += kNumLenSlots - 1;
+ len += kLenMask;
}
bs.BitPos -= dist;
@@ -108,7 +109,7 @@ HRESULT Decode(const Byte *in, size_t inSize, Byte *out, size_t outSize)
BIT_STREAM_NORMALIZE
- if (len > outSize - pos)
+ if (len + 3 > outSize - pos)
return S_FALSE;
if (dist > pos)
return S_FALSE;
diff --git a/CPP/7zip/Crc.mak b/CPP/7zip/Crc.mak
index 2e0b92ef..815142db 100644
--- a/CPP/7zip/Crc.mak
+++ b/CPP/7zip/Crc.mak
@@ -1,6 +1,6 @@
C_OBJS = $(C_OBJS) \
$O\7zCrc.obj
-!IF "$(CPU)" == "IA64" || "$(CPU)" == "MIPS" || "$(CPU)" == "ARM" || "$(CPU)" == "ARM64"
+!IF "$(PLATFORM)" == "ia64" || "$(PLATFORM)" == "mips" || "$(PLATFORM)" == "arm" || "$(PLATFORM)" == "arm64"
C_OBJS = $(C_OBJS) \
!ELSE
ASM_OBJS = $(ASM_OBJS) \
diff --git a/CPP/7zip/Crc64.mak b/CPP/7zip/Crc64.mak
index 1228a014..d58a4832 100644
--- a/CPP/7zip/Crc64.mak
+++ b/CPP/7zip/Crc64.mak
@@ -1,6 +1,6 @@
C_OBJS = $(C_OBJS) \
$O\XzCrc64.obj
-!IF "$(CPU)" == "IA64" || "$(CPU)" == "MIPS" || "$(CPU)" == "ARM" || "$(CPU)" == "ARM64"
+!IF "$(PLATFORM)" == "ia64" || "$(PLATFORM)" == "mips" || "$(PLATFORM)" == "arm" || "$(PLATFORM)" == "arm64"
C_OBJS = $(C_OBJS) \
!ELSE
ASM_OBJS = $(ASM_OBJS) \
diff --git a/CPP/7zip/LzmaDec.mak b/CPP/7zip/LzmaDec.mak
index 02e449d4..8d7f6f98 100644
--- a/CPP/7zip/LzmaDec.mak
+++ b/CPP/7zip/LzmaDec.mak
@@ -1,4 +1,4 @@
-!IF "$(CPU)" == "AMD64"
+!IF "$(PLATFORM)" == "x64"
CFLAGS_C_SPEC = -D_LZMA_DEC_OPT
ASM_OBJS = $(ASM_OBJS) \
$O\LzmaDecOpt.obj
diff --git a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
index c0a7bcd0..0e2a4700 100644
--- a/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
+++ b/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
@@ -23,6 +23,7 @@
#include "../../../Common/StringConvert.h"
#include "../../../Common/StringToInt.h"
+#include "../../../Windows/ErrorMsg.h"
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
#ifdef _WIN32
@@ -39,7 +40,9 @@
extern bool g_CaseSensitive;
extern bool g_PathTrailReplaceMode;
+#ifdef _7ZIP_LARGE_PAGES
bool g_LargePagesMode = false;
+#endif
#ifdef UNDER_CE
@@ -410,8 +413,19 @@ static void AddToCensorFromListFile(
UStringVector names;
if (!NFind::DoesFileExist(us2fs(fileName)))
throw CArcCmdLineException(kCannotFindListFile, fileName);
- if (!ReadNamesFromListFile(us2fs(fileName), names, codePage))
+ DWORD lastError = 0;
+ if (!ReadNamesFromListFile2(us2fs(fileName), names, codePage, lastError))
+ {
+ if (lastError != 0)
+ {
+ UString m;
+ m = "The file operation error for listfile";
+ m.Add_LF();
+ m += NError::MyFormatMessage(lastError);
+ throw CArcCmdLineException(m, fileName);
+ }
throw CArcCmdLineException(kIncorrectListFile, fileName);
+ }
if (renamePairs)
{
if ((names.Size() & 1) != 0)
diff --git a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
index 083e7c84..de2f2e00 100644
--- a/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
+++ b/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
@@ -1182,7 +1182,9 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
bool needDelete = true;
if (needDelete)
{
+ if (NFind::DoesFileExist(fullProcessedPath))
if (!DeleteFileAlways(fullProcessedPath))
+ if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
RINOK(SendMessageError_with_LastError(kCantDeleteOutputFile, fullProcessedPath));
return S_OK;
@@ -1368,13 +1370,35 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
// UInt64 ticks = GetCpuTicks();
bool res = _outFileStreamSpec->File.SetLength(_curSize);
_fileLengthWasSet = res;
- _outFileStreamSpec->File.SeekToBegin();
+
// ticks = GetCpuTicks() - ticks;
// printf("\nticks = %10d\n", (unsigned)ticks);
if (!res)
{
RINOK(SendMessageError_with_LastError(kCantSetFileLen, fullProcessedPath));
}
+
+ /*
+ _outFileStreamSpec->File.Close();
+ ticks = GetCpuTicks() - ticks;
+ printf("\nticks = %10d\n", (unsigned)ticks);
+ return S_FALSE;
+ */
+
+ /*
+ File.SetLength() on FAT (xp64): is fast, but then File.Close() can be slow,
+ if we don't write any data.
+ File.SetLength() for remote share file (exFAT) can be slow in some cases,
+ and the Windows can return "network error" after 1 minute,
+ while remote file still can grow.
+ We need some way to detect such bad cases and disable PreAllocateOutFile mode.
+ */
+
+ res = _outFileStreamSpec->File.SeekToBegin();
+ if (!res)
+ {
+ RINOK(SendMessageError_with_LastError("Can not seek to begin of file", fullProcessedPath));
+ }
}
#ifdef SUPPORT_ALT_STREAMS
diff --git a/CPP/7zip/UI/Common/ArchiveName.cpp b/CPP/7zip/UI/Common/ArchiveName.cpp
index a3a44ce2..78dcaea3 100644
--- a/CPP/7zip/UI/Common/ArchiveName.cpp
+++ b/CPP/7zip/UI/Common/ArchiveName.cpp
@@ -2,6 +2,8 @@
#include "StdAfx.h"
+#include "../../../Common/Wildcard.h"
+
#include "../../../Windows/FileDir.h"
#include "../../../Windows/FileName.h"
@@ -11,7 +13,7 @@
using namespace NWindows;
using namespace NFile;
-UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
+static UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
{
FString resultName = fi.Name;
if (!fi.IsDir() && !keepName)
@@ -72,7 +74,75 @@ static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepN
return resultName;
}
-UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName)
+
+UString CreateArchiveName(const UStringVector &paths, const NFind::CFileInfo *fi)
{
- return Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(path), fromPrev, keepName)));
+ bool keepName = false;
+ /*
+ if (paths.Size() == 1)
+ {
+ const UString &name = paths[0];
+ if (name.Len() > 4)
+ if (CompareFileNames(name.RightPtr(4), L".tar") == 0)
+ keepName = true;
+ }
+ */
+
+ UString name;
+ if (fi)
+ name = CreateArchiveName(*fi, keepName);
+ else
+ {
+ if (paths.IsEmpty())
+ return L"archive";
+ bool fromPrev = (paths.Size() > 1);
+ name = Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(paths.Front()), fromPrev, keepName)));
+ }
+
+ UString postfix;
+ UInt32 index = 1;
+
+ for (;;)
+ {
+ // we don't want cases when we include archive to itself.
+ // so we find first available name for archive
+ const UString name2 = name + postfix;
+ const UString name2_zip = name2 + L".zip";
+ const UString name2_7z = name2 + L".7z";
+ const UString name2_tar = name2 + L".tar";
+ const UString name2_wim = name2 + L".wim";
+
+ unsigned i = 0;
+
+ for (i = 0; i < paths.Size(); i++)
+ {
+ const UString &fn = paths[i];
+ NFind::CFileInfo fi2;
+
+ const NFind::CFileInfo *fp;
+ if (fi && paths.Size() == 1)
+ fp = fi;
+ else
+ {
+ if (!fi2.Find(us2fs(fn)))
+ continue;
+ fp = &fi2;
+ }
+ const UString fname = fs2us(fp->Name);
+ if ( 0 == CompareFileNames(fname, name2_zip)
+ || 0 == CompareFileNames(fname, name2_7z)
+ || 0 == CompareFileNames(fname, name2_tar)
+ || 0 == CompareFileNames(fname, name2_wim))
+ break;
+ }
+
+ if (i == paths.Size())
+ break;
+ index++;
+ postfix = "_";
+ postfix.Add_UInt32(index);
+ }
+
+ name += postfix;
+ return name;
}
diff --git a/CPP/7zip/UI/Common/ArchiveName.h b/CPP/7zip/UI/Common/ArchiveName.h
index ec2f1e8d..0d32645f 100644
--- a/CPP/7zip/UI/Common/ArchiveName.h
+++ b/CPP/7zip/UI/Common/ArchiveName.h
@@ -3,11 +3,8 @@
#ifndef __ARCHIVE_NAME_H
#define __ARCHIVE_NAME_H
-#include "../../../Common/MyString.h"
-
#include "../../../Windows/FileFind.h"
-UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName);
-UString CreateArchiveName(const NWindows::NFile::NFind::CFileInfo &fileInfo, bool keepName);
+UString CreateArchiveName(const UStringVector &paths, const NWindows::NFile::NFind::CFileInfo *fi = NULL);
#endif
diff --git a/CPP/7zip/UI/Common/Bench.cpp b/CPP/7zip/UI/Common/Bench.cpp
index e86db15d..c5854d39 100644
--- a/CPP/7zip/UI/Common/Bench.cpp
+++ b/CPP/7zip/UI/Common/Bench.cpp
@@ -522,10 +522,9 @@ class CBenchProgressInfo:
{
public:
CBenchProgressStatus *Status;
- HRESULT Res;
IBenchCallback *Callback;
- CBenchProgressInfo(): Callback(0) {}
+ CBenchProgressInfo(): Callback(NULL) {}
MY_UNKNOWN_IMP
STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
};
@@ -758,7 +757,7 @@ struct CEncoderInfo
fileData(NULL),
CheckCrc_Enc(true),
CheckCrc_Dec(true),
- outStreamSpec(0), callback(0), printCallback(0), propStreamSpec(0) {}
+ outStreamSpec(NULL), callback(NULL), printCallback(NULL), propStreamSpec(NULL) {}
#ifndef _7ZIP_ST
@@ -1144,7 +1143,7 @@ static const UInt32 kNumThreadsMax = (1 << 12);
struct CBenchEncoders
{
CEncoderInfo *encoders;
- CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }
+ CBenchEncoders(UInt32 num): encoders(NULL) { encoders = new CEncoderInfo[num]; }
~CBenchEncoders() { delete []encoders; }
};
@@ -1545,7 +1544,7 @@ struct CFreqThreads
CFreqInfo *Items;
UInt32 NumThreads;
- CFreqThreads(): Items(0), NumThreads(0) {}
+ CFreqThreads(): Items(NULL), NumThreads(0) {}
void WaitAll()
{
for (UInt32 i = 0; i < NumThreads; i++)
@@ -1603,7 +1602,7 @@ struct CCrcThreads
CCrcInfo *Items;
UInt32 NumThreads;
- CCrcThreads(): Items(0), NumThreads(0) {}
+ CCrcThreads(): Items(NULL), NumThreads(0) {}
void WaitAll()
{
for (UInt32 i = 0; i < NumThreads; i++)
@@ -1885,8 +1884,51 @@ AString GetProcessThreadsInfo(const NSystem::CProcessAffinity &ti)
}
+static void PrintSize(AString &s, UInt64 v)
+{
+ char c = 0;
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'K';
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'M';
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'G';
+ if ((v & 0x3FF) == 0) { v >>= 10; c = 'T';
+ }}}}
+ else
+ {
+ PrintHex(s, v);
+ return;
+ }
+ char temp[32];
+ ConvertUInt64ToString(v, temp);
+ s += temp;
+ if (c)
+ s += c;
+}
+
+
+#ifdef _7ZIP_LARGE_PAGES
+
extern bool g_LargePagesMode;
+extern "C"
+{
+ extern SIZE_T g_LargePageSize;
+}
+
+void Add_LargePages_String(AString &s)
+{
+ if (g_LargePagesMode || g_LargePageSize != 0)
+ {
+ s += " (LP-";
+ PrintSize(s, g_LargePageSize);
+ if (!g_LargePagesMode)
+ s += "-NA";
+ s += ")";
+ }
+}
+
+#endif
+
+
static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
bool size_Defined, UInt64 size, const char *threadsString, UInt32 numThreads)
@@ -1898,8 +1940,15 @@ static void PrintRequirements(IBenchPrintCallback &f, const char *sizeString,
else
f.Print(" ?");
f.Print(" MB");
- if (g_LargePagesMode)
- f.Print(" LP");
+
+ #ifdef _7ZIP_LARGE_PAGES
+ {
+ AString s;
+ Add_LargePages_String(s);
+ f.Print(s);
+ }
+ #endif
+
f.Print(", # ");
f.Print(threadsString);
PrintNumber(f, numThreads, 3);
@@ -2539,26 +2588,7 @@ static const char * const k_PF[] =
#endif
-static void PrintSize(AString &s, UInt64 v)
-{
- char c = 0;
- if ((v & 0x3FF) == 0) { v >>= 10; c = 'K';
- if ((v & 0x3FF) == 0) { v >>= 10; c = 'M';
- if ((v & 0x3FF) == 0) { v >>= 10; c = 'G';
- if ((v & 0x3FF) == 0) { v >>= 10; c = 'T';
- }}}}
- else
- {
- PrintHex(s, v);
- return;
- }
- char temp[32];
- ConvertUInt64ToString(v, temp);
- s += temp;
- if (c)
- s += c;
-}
-
+
static void PrintPage(AString &s, UInt32 v)
{
@@ -2707,8 +2737,9 @@ void GetCpuName(AString &s)
#endif
- if (g_LargePagesMode)
- s += " (LP)";
+ #ifdef _7ZIP_LARGE_PAGES
+ Add_LargePages_String(s);
+ #endif
}
@@ -2968,6 +2999,9 @@ HRESULT Bench(
UInt64 start = ::GetTimeCount();
UInt32 sum = (UInt32)start;
sum = CountCpuFreq(sum, (UInt32)(numMilCommands * 1000000 / kNumFreqCommands), g_BenchCpuFreqTemp);
+ if (sum == 0xF1541213)
+ if (printCallback)
+ printCallback->Print("");
const UInt64 realDelta = ::GetTimeCount() - start;
start = realDelta;
if (start == 0)
@@ -2984,7 +3018,7 @@ HRESULT Bench(
else
{
// PrintNumber(*printCallback, start, 0);
- PrintNumber(*printCallback, mipsVal, 5 + ((sum == 0xF1541213) ? 1 : 0));
+ PrintNumber(*printCallback, mipsVal, 5);
}
}
/*
diff --git a/CPP/7zip/UI/Common/Bench.h b/CPP/7zip/UI/Common/Bench.h
index ec51faee..18a40a84 100644
--- a/CPP/7zip/UI/Common/Bench.h
+++ b/CPP/7zip/UI/Common/Bench.h
@@ -68,5 +68,10 @@ void GetSysInfo(AString &s1, AString &s2);
void GetCpuName(AString &s);
void GetCpuFeatures(AString &s);
+#ifdef _7ZIP_LARGE_PAGES
+void Add_LargePages_String(AString &s);
+#else
+// #define Add_LargePages_String
+#endif
#endif
diff --git a/CPP/7zip/UI/Common/EnumDirItems.cpp b/CPP/7zip/UI/Common/EnumDirItems.cpp
index 0828dfbc..088f0777 100644
--- a/CPP/7zip/UI/Common/EnumDirItems.cpp
+++ b/CPP/7zip/UI/Common/EnumDirItems.cpp
@@ -1084,3 +1084,13 @@ CMessagePathException::CMessagePathException(const char *a, const wchar_t *u)
(*this) += u;
}
}
+
+CMessagePathException::CMessagePathException(const wchar_t *a, const wchar_t *u)
+{
+ (*this) += a;
+ if (u)
+ {
+ Add_LF();
+ (*this) += u;
+ }
+}
diff --git a/CPP/7zip/UI/Common/EnumDirItems.h b/CPP/7zip/UI/Common/EnumDirItems.h
index 37ebed4c..6490bd50 100644
--- a/CPP/7zip/UI/Common/EnumDirItems.h
+++ b/CPP/7zip/UI/Common/EnumDirItems.h
@@ -22,6 +22,7 @@ HRESULT EnumerateItems(
struct CMessagePathException: public UString
{
CMessagePathException(const char *a, const wchar_t *u = NULL);
+ CMessagePathException(const wchar_t *a, const wchar_t *u = NULL);
};
diff --git a/CPP/7zip/UI/Common/HashCalc.cpp b/CPP/7zip/UI/Common/HashCalc.cpp
index 46a69de1..c340ac7f 100644
--- a/CPP/7zip/UI/Common/HashCalc.cpp
+++ b/CPP/7zip/UI/Common/HashCalc.cpp
@@ -230,7 +230,7 @@ HRESULT HashCalc(
unsigned i;
CHashBundle hb;
RINOK(hb.SetMethods(EXTERNAL_CODECS_LOC_VARS options.Methods));
- hb.Init();
+ // hb.Init();
hb.NumErrors = dirItems.Stat.NumErrors;
diff --git a/CPP/7zip/UI/Common/HashCalc.h b/CPP/7zip/UI/Common/HashCalc.h
index 3b4ec30d..db5b39aa 100644
--- a/CPP/7zip/UI/Common/HashCalc.h
+++ b/CPP/7zip/UI/Common/HashCalc.h
@@ -51,9 +51,13 @@ struct CHashBundle: public IHashCalc
UInt64 CurSize;
+ UString MainName;
+ UString FirstFileName;
+
HRESULT SetMethods(DECL_EXTERNAL_CODECS_LOC_VARS const UStringVector &methods);
- void Init()
+ // void Init() {}
+ CHashBundle()
{
NumDirs = NumFiles = NumAltStreams = FilesSize = AltStreamsSize = NumErrors = 0;
}
@@ -76,7 +80,7 @@ struct CHashBundle: public IHashCalc
virtual HRESULT GetStream(const wchar_t *name, bool isFolder) x; \
virtual HRESULT OpenFileError(const FString &path, DWORD systemError) x; \
virtual HRESULT SetOperationResult(UInt64 fileSize, const CHashBundle &hb, bool showHash) x; \
- virtual HRESULT AfterLastFile(const CHashBundle &hb) x; \
+ virtual HRESULT AfterLastFile(CHashBundle &hb) x; \
struct IHashCallbackUI: public IDirItemsCallback
{
diff --git a/CPP/7zip/UI/Common/OpenArchive.cpp b/CPP/7zip/UI/Common/OpenArchive.cpp
index 11d512ae..419c29ee 100644
--- a/CPP/7zip/UI/Common/OpenArchive.cpp
+++ b/CPP/7zip/UI/Common/OpenArchive.cpp
@@ -563,6 +563,8 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
UInt32 parentType = 0;
RINOK(GetRawProps->GetParent(curIndex, &curParent, &parentType));
+ // 18.06: fixed : we don't want to split name to parts
+ /*
if (parentType != NParentType::kAltStream)
{
for (;;)
@@ -576,6 +578,7 @@ HRESULT CArc::GetItemPathToParent(UInt32 index, UInt32 parent, UStringVector &pa
s.DeleteFrom(pos);
}
}
+ */
parts.Insert(0, s);
@@ -2013,7 +2016,7 @@ HRESULT CArc::OpenStream2(const COpenOptions &op)
}
else
{
- const CArcInfoEx &ai = op.codecs->Formats[formatIndex];
+ const CArcInfoEx &ai = op.codecs->Formats[(unsigned)formatIndex];
if (ai.FindExtension(extension) >= 0)
{
if (ai.Flags_FindSignature() && searchMarkerInHandler)
diff --git a/CPP/7zip/UI/Common/Update.cpp b/CPP/7zip/UI/Common/Update.cpp
index 081d38eb..8c7ae45f 100644
--- a/CPP/7zip/UI/Common/Update.cpp
+++ b/CPP/7zip/UI/Common/Update.cpp
@@ -288,29 +288,27 @@ void CArchivePath::ParseFromPath(const UString &path, EArcNameMode mode)
if (mode == k_ArcNameMode_Add)
return;
- if (mode == k_ArcNameMode_Exact)
- {
- BaseExtension.Empty();
- return;
- }
- int dotPos = Name.ReverseFind_Dot();
- if (dotPos < 0)
- return;
- if ((unsigned)dotPos == Name.Len() - 1)
+ if (mode != k_ArcNameMode_Exact)
{
- Name.DeleteBack();
- BaseExtension.Empty();
- return;
- }
- const UString ext = Name.Ptr(dotPos + 1);
- if (BaseExtension.IsEqualTo_NoCase(ext))
- {
- BaseExtension = ext;
- Name.DeleteFrom(dotPos);
+ int dotPos = Name.ReverseFind_Dot();
+ if (dotPos < 0)
+ return;
+ if ((unsigned)dotPos == Name.Len() - 1)
+ Name.DeleteBack();
+ else
+ {
+ const UString ext = Name.Ptr(dotPos + 1);
+ if (BaseExtension.IsEqualTo_NoCase(ext))
+ {
+ BaseExtension = ext;
+ Name.DeleteFrom(dotPos);
+ return;
+ }
+ }
}
- else
- BaseExtension.Empty();
+
+ BaseExtension.Empty();
}
UString CArchivePath::GetFinalPath() const
@@ -327,6 +325,7 @@ UString CArchivePath::GetFinalPath() const
UString CArchivePath::GetFinalVolPath() const
{
UString path = GetPathWithoutExt();
+ // if BaseExtension is empty, we must ignore VolExtension also.
if (!BaseExtension.IsEmpty())
{
path += '.';
@@ -1166,7 +1165,7 @@ HRESULT UpdateArchive(
{
errorInfo.SystemError = ERROR_ACCESS_DENIED;
errorInfo.Message = "The file is read-only";
- errorInfo.FileNames.Add(arcPath);
+ errorInfo.FileNames.Add(us2fs(arcPath));
return errorInfo.Get_HRESULT_Error();
}
@@ -1377,6 +1376,31 @@ HRESULT UpdateArchive(
unsigned ci;
+
+ // self including protection
+ if (options.DeleteAfterCompressing)
+ {
+ for (ci = 0; ci < options.Commands.Size(); ci++)
+ {
+ CArchivePath &ap = options.Commands[ci].ArchivePath;
+ const FString path = us2fs(ap.GetFinalPath());
+ // maybe we must compare absolute paths path here
+ FOR_VECTOR (i, dirItems.Items)
+ {
+ const FString phyPath = dirItems.GetPhyPath(i);
+ if (phyPath == path)
+ {
+ UString s;
+ s = "It is not allowed to include archive to itself";
+ s.Add_LF();
+ s += path;
+ throw s;
+ }
+ }
+ }
+ }
+
+
for (ci = 0; ci < options.Commands.Size(); ci++)
{
CArchivePath &ap = options.Commands[ci].ArchivePath;
@@ -1562,26 +1586,39 @@ HRESULT UpdateArchive(
}
CCurrentDirRestorer curDirRestorer;
+
+ AStringVector paths;
+ AStringVector names;
for (i = 0; i < fullPaths.Size(); i++)
{
const UString arcPath2 = fs2us(fullPaths[i]);
const UString fileName = ExtractFileNameFromPath(arcPath2);
- const AString path (GetAnsiString(arcPath2));
- const AString name (GetAnsiString(fileName));
+ paths.Add(GetAnsiString(arcPath2));
+ names.Add(GetAnsiString(fileName));
+ // const AString path (GetAnsiString(arcPath2));
+ // const AString name (GetAnsiString(fileName));
// Warning!!! MAPISendDocuments function changes Current directory
// fnSend(0, ";", (LPSTR)(LPCSTR)path, (LPSTR)(LPCSTR)name, 0);
+ }
- MapiFileDesc f;
+ CRecordVector<MapiFileDesc> files;
+ files.ClearAndSetSize(paths.Size());
+
+ for (i = 0; i < paths.Size(); i++)
+ {
+ MapiFileDesc &f = files[i];
memset(&f, 0, sizeof(f));
f.nPosition = 0xFFFFFFFF;
- f.lpszPathName = (char *)(const char *)path;
- f.lpszFileName = (char *)(const char *)name;
-
+ f.lpszPathName = (char *)(const char *)paths[i];
+ f.lpszFileName = (char *)(const char *)names[i];
+ }
+
+ {
MapiMessage m;
memset(&m, 0, sizeof(m));
- m.nFileCount = 1;
- m.lpFiles = &f;
+ m.nFileCount = files.Size();
+ m.lpFiles = &files.Front();
const AString addr (GetAnsiString(options.EMailAddress));
MapiRecipDesc rec;
diff --git a/CPP/7zip/UI/Console/HashCon.cpp b/CPP/7zip/UI/Console/HashCon.cpp
index ab80ce37..762b21bb 100644
--- a/CPP/7zip/UI/Console/HashCon.cpp
+++ b/CPP/7zip/UI/Console/HashCon.cpp
@@ -332,7 +332,7 @@ void CHashCallbackConsole::PrintProperty(const char *name, UInt64 value)
*_so << name << s << endl;
}
-HRESULT CHashCallbackConsole::AfterLastFile(const CHashBundle &hb)
+HRESULT CHashCallbackConsole::AfterLastFile(CHashBundle &hb)
{
ClosePercents2();
diff --git a/CPP/7zip/UI/Console/List.cpp b/CPP/7zip/UI/Console/List.cpp
index 38e23e21..416ef2c9 100644
--- a/CPP/7zip/UI/Console/List.cpp
+++ b/CPP/7zip/UI/Console/List.cpp
@@ -1072,18 +1072,24 @@ HRESULT ListArchives(CCodecs *codecs,
errorCode = ERROR_FILE_NOT_FOUND;
lastError = HRESULT_FROM_WIN32(lastError);;
g_StdOut.Flush();
- *g_ErrStream << endl << kError << NError::MyFormatMessage(errorCode) << endl;
- g_ErrStream->NormalizePrint_UString(arcPath);
- *g_ErrStream << endl << endl;
+ if (g_ErrStream)
+ {
+ *g_ErrStream << endl << kError << NError::MyFormatMessage(errorCode) << endl;
+ g_ErrStream->NormalizePrint_UString(arcPath);
+ *g_ErrStream << endl << endl;
+ }
numErrors++;
continue;
}
if (fi.IsDir())
{
g_StdOut.Flush();
- *g_ErrStream << endl << kError;
- g_ErrStream->NormalizePrint_UString(arcPath);
- *g_ErrStream << " is not a file" << endl << endl;
+ if (g_ErrStream)
+ {
+ *g_ErrStream << endl << kError;
+ g_ErrStream->NormalizePrint_UString(arcPath);
+ *g_ErrStream << " is not a file" << endl << endl;
+ }
numErrors++;
continue;
}
@@ -1133,24 +1139,28 @@ HRESULT ListArchives(CCodecs *codecs,
{
if (result == E_ABORT)
return result;
+ if (result != S_FALSE)
+ lastError = result;
g_StdOut.Flush();
- *g_ErrStream << endl << kError;
- g_ErrStream->NormalizePrint_UString(arcPath);
- *g_ErrStream << " : ";
- if (result == S_FALSE)
+ if (g_ErrStream)
{
- Print_OpenArchive_Error(*g_ErrStream, codecs, arcLink);
- }
- else
- {
- lastError = result;
- *g_ErrStream << "opening : ";
- if (result == E_OUTOFMEMORY)
- *g_ErrStream << "Can't allocate required memory";
+ *g_ErrStream << endl << kError;
+ g_ErrStream->NormalizePrint_UString(arcPath);
+ *g_ErrStream << " : ";
+ if (result == S_FALSE)
+ {
+ Print_OpenArchive_Error(*g_ErrStream, codecs, arcLink);
+ }
else
- *g_ErrStream << NError::MyFormatMessage(result);
+ {
+ *g_ErrStream << "opening : ";
+ if (result == E_OUTOFMEMORY)
+ *g_ErrStream << "Can't allocate required memory";
+ else
+ *g_ErrStream << NError::MyFormatMessage(result);
+ }
+ *g_ErrStream << endl;
}
- *g_ErrStream << endl;
numErrors++;
continue;
}
diff --git a/CPP/7zip/UI/Console/Main.cpp b/CPP/7zip/UI/Console/Main.cpp
index a632c1b4..f300c3d4 100644
--- a/CPP/7zip/UI/Console/Main.cpp
+++ b/CPP/7zip/UI/Console/Main.cpp
@@ -24,6 +24,7 @@
#include "../../../Windows/TimeUtils.h"
#include "../Common/ArchiveCommandLine.h"
+#include "../Common/Bench.h"
#include "../Common/ExitCode.h"
#include "../Common/Extract.h"
@@ -56,8 +57,6 @@ using namespace NCommandLineParser;
HINSTANCE g_hInstance = 0;
#endif
-extern bool g_LargePagesMode;
-
extern CStdOutStream *g_StdStream;
extern CStdOutStream *g_ErrStream;
@@ -236,7 +235,7 @@ static void PrintWarningsPaths(const CErrorPathCodes &pc, CStdOutStream &so)
{
FOR_VECTOR(i, pc.Paths)
{
- so.NormalizePrint_UString(pc.Paths[i]);
+ so.NormalizePrint_UString(fs2us(pc.Paths[i]));
so << " : ";
so << NError::MyFormatMessage(pc.Codes[i]) << endl;
}
@@ -376,8 +375,13 @@ static void PrintMemUsage(const char *s, UInt64 val)
*g_StdStream << " " << s << " Memory =";
PrintNum(SHIFT_SIZE_VALUE(val, 20), 7);
*g_StdStream << " MB";
- if (g_LargePagesMode)
- *g_StdStream << " (LP)";
+
+ #ifdef _7ZIP_LARGE_PAGES
+ AString lp;
+ Add_LargePages_String(lp);
+ if (!lp.IsEmpty())
+ *g_StdStream << lp;
+ #endif
}
EXTERN_C_BEGIN
@@ -911,7 +915,7 @@ int Main2(
{
hashCalc = &hb;
ThrowException_if_Error(hb.SetMethods(EXTERNAL_CODECS_VARS_L options.HashMethods));
- hb.Init();
+ // hb.Init();
}
hresultMain = Extract(
diff --git a/CPP/7zip/UI/Explorer/ContextMenu.cpp b/CPP/7zip/UI/Explorer/ContextMenu.cpp
index 21de12a5..fff6fa25 100644
--- a/CPP/7zip/UI/Explorer/ContextMenu.cpp
+++ b/CPP/7zip/UI/Explorer/ContextMenu.cpp
@@ -582,7 +582,7 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
}
}
- const UString &fileName = _fileNames.Front();
+ // const UString &fileName = _fileNames.Front();
if (needExtract)
{
@@ -639,12 +639,8 @@ STDMETHODIMP CZipContextMenu::QueryContextMenu(HMENU hMenu, UINT indexMenu,
}
}
- UString arcName;
- if (_fileNames.Size() == 1)
- arcName = CreateArchiveName(fi0, false);
- else
- arcName = CreateArchiveName(fileName, _fileNames.Size() > 1, false);
-
+ const UString arcName = CreateArchiveName(_fileNames, _fileNames.Size() == 1 ? &fi0 : NULL);
+
UString arcName7z = arcName;
arcName7z += ".7z";
UString arcNameZip = arcName;
diff --git a/CPP/7zip/UI/Far/Far.cpp b/CPP/7zip/UI/Far/Far.cpp
index cec4af52..5d92bc40 100644
--- a/CPP/7zip/UI/Far/Far.cpp
+++ b/CPP/7zip/UI/Far/Far.cpp
@@ -327,7 +327,7 @@ HRESULT OpenArchive(const CSysString &fileName,
}
*/
-static HANDLE MyOpenFilePluginW(const wchar_t *name)
+static HANDLE MyOpenFilePluginW(const wchar_t *name, bool isAbortCodeSupported)
{
FString normalizedName = us2fs(name);
normalizedName.Trim();
@@ -373,7 +373,12 @@ static HANDLE MyOpenFilePluginW(const wchar_t *name)
archiverInfoResult, defaultName, openArchiveCallback);
*/
if (result == E_ABORT)
- return (HANDLE)-2;
+ {
+ // fixed 18.06:
+ // OpenFilePlugin() is allowed to return (HANDLE)-2 as abort code
+ // OpenPlugin() is not allowed to return (HANDLE)-2.
+ return isAbortCodeSupported ? (HANDLE)-2 : INVALID_HANDLE_VALUE;
+ }
UString errorMessage = agent->GetErrorMessage();
if (!errorMessage.IsEmpty())
@@ -403,7 +408,7 @@ static HANDLE MyOpenFilePluginW(const wchar_t *name)
return (HANDLE)(plugin);
}
-static HANDLE MyOpenFilePlugin(const char *name)
+static HANDLE MyOpenFilePlugin(const char *name, bool isAbortCodeSupported)
{
UINT codePage =
#ifdef UNDER_CE
@@ -411,7 +416,7 @@ static HANDLE MyOpenFilePlugin(const char *name)
#else
::AreFileApisANSI() ? CP_ACP : CP_OEMCP;
#endif
- return MyOpenFilePluginW(GetUnicodeString(name, codePage));
+ return MyOpenFilePluginW(GetUnicodeString(name, codePage), isAbortCodeSupported);
}
EXTERN_C HANDLE WINAPI OpenFilePlugin(char *name, const unsigned char * /* data */, int /* dataSize */)
@@ -423,7 +428,7 @@ EXTERN_C HANDLE WINAPI OpenFilePlugin(char *name, const unsigned char * /* data
// if (!Opt.ProcessShiftF1)
return(INVALID_HANDLE_VALUE);
}
- return MyOpenFilePlugin(name);
+ return MyOpenFilePlugin(name, true); // isAbortCodeSupported
MY_TRY_END2("OpenFilePlugin", INVALID_HANDLE_VALUE);
}
@@ -458,7 +463,7 @@ EXTERN_C HANDLE WINAPI OpenPlugin(int openFrom, INT_PTR item)
fileName.DeleteBack();
fileName.DeleteFrontal(1);
}
- return MyOpenFilePlugin(fileName);
+ return MyOpenFilePlugin(fileName, false); // isAbortCodeSupported
}
if (openFrom == OPEN_PLUGINSMENU)
@@ -470,7 +475,7 @@ EXTERN_C HANDLE WINAPI OpenPlugin(int openFrom, INT_PTR item)
PluginPanelItem pluginPanelItem;
if (!g_StartupInfo.ControlGetActivePanelCurrentItemInfo(pluginPanelItem))
throw 142134;
- return MyOpenFilePlugin(pluginPanelItem.FindData.cFileName);
+ return MyOpenFilePlugin(pluginPanelItem.FindData.cFileName, false); // isAbortCodeSupported
}
case 1:
diff --git a/CPP/7zip/UI/FileManager/AltStreamsFolder.cpp b/CPP/7zip/UI/FileManager/AltStreamsFolder.cpp
index b7fbb235..7069e1aa 100644
--- a/CPP/7zip/UI/FileManager/AltStreamsFolder.cpp
+++ b/CPP/7zip/UI/FileManager/AltStreamsFolder.cpp
@@ -468,7 +468,7 @@ static HRESULT UpdateFile(NFsFolder::CCopyStateIO &state, CFSTR inPath, CFSTR ou
{
if (NFind::DoesFileOrDirExist(outPath))
{
- RINOK(SendMessageError(callback, NError::MyFormatMessage(ERROR_ALREADY_EXISTS), outPath));
+ RINOK(SendMessageError(callback, NError::MyFormatMessage(ERROR_ALREADY_EXISTS), FString(outPath)));
CFileInfo fi;
if (fi.Find(inPath))
{
diff --git a/CPP/7zip/UI/FileManager/ExtractCallback.cpp b/CPP/7zip/UI/FileManager/ExtractCallback.cpp
index a5317e26..1bc96ae3 100644
--- a/CPP/7zip/UI/FileManager/ExtractCallback.cpp
+++ b/CPP/7zip/UI/FileManager/ExtractCallback.cpp
@@ -759,11 +759,15 @@ STDMETHODIMP CExtractCallbackImp::AskWrite(
destPathResultTemp = fs2us(destPathSys);
}
else
+ {
+ if (NFind::DoesFileExist(destPathSys))
if (!NDir::DeleteFileAlways(destPathSys))
+ if (GetLastError() != ERROR_FILE_NOT_FOUND)
{
RINOK(MessageError("can not delete output file", destPathSys));
return E_ABORT;
}
+ }
}
*writeAnswer = BoolToInt(true);
return StringToBstr(destPathResultTemp, destPathResult);
diff --git a/CPP/7zip/UI/FileManager/ListViewDialog.cpp b/CPP/7zip/UI/FileManager/ListViewDialog.cpp
index 9ad7bcc5..a42e790b 100644
--- a/CPP/7zip/UI/FileManager/ListViewDialog.cpp
+++ b/CPP/7zip/UI/FileManager/ListViewDialog.cpp
@@ -213,6 +213,12 @@ void CListViewDialog::ShowItemInfo()
if (index < Values.Size())
dlg.Text = Values[index];
}
+
+ #ifdef _WIN32
+ if (dlg.Text.Find(L'\r') < 0)
+ dlg.Text.Replace(L"\n", L"\r\n");
+ #endif
+
dlg.Create(*this);
}
diff --git a/CPP/7zip/UI/FileManager/Panel.cpp b/CPP/7zip/UI/FileManager/Panel.cpp
index 973e64dd..afb5649a 100644
--- a/CPP/7zip/UI/FileManager/Panel.cpp
+++ b/CPP/7zip/UI/FileManager/Panel.cpp
@@ -879,8 +879,9 @@ void CPanel::AddToArchive()
FOR_VECTOR (i, indices)
names.Add(curPrefix + GetItemRelPath2(indices[i]));
- bool fromPrev = (names.Size() > 1);
- const UString arcName = CreateArchiveName(names.Front(), fromPrev, false);
+
+ const UString arcName = CreateArchiveName(names);
+
HRESULT res = CompressFiles(destCurDirPrefix, arcName, L"",
true, // addExtension
names, false, true, false);
diff --git a/CPP/7zip/UI/FileManager/PanelCopy.cpp b/CPP/7zip/UI/FileManager/PanelCopy.cpp
index 5715d9de..c3416cc7 100644
--- a/CPP/7zip/UI/FileManager/PanelCopy.cpp
+++ b/CPP/7zip/UI/FileManager/PanelCopy.cpp
@@ -29,7 +29,7 @@ public:
CMyComPtr<IFolderOperationsExtractCallback> ExtractCallback;
CHashBundle Hash;
- UString FirstFilePath;
+ // UString FirstFilePath;
HRESULT Result;
@@ -48,7 +48,7 @@ void CPanelCopyThread::ShowFinalResults(HWND hwnd)
if (!ResultsWereShown)
{
ResultsWereShown = true;
- ShowHashResults(Hash, fs2us(FirstFilePath), hwnd);
+ ShowHashResults(Hash, hwnd);
}
}
@@ -100,7 +100,7 @@ HRESULT CPanelCopyThread::ProcessVirt()
else if (options->testMode)
{
CProgressMessageBoxPair &pair = GetMessagePair(false); // GetMessagePair(ExtractCallbackSpec->Hash.NumErrors != 0);
- AddHashBundleRes(pair.Message, Hash, FirstFilePath);
+ AddHashBundleRes(pair.Message, Hash);
}
}
@@ -158,7 +158,10 @@ HRESULT CPanel::CopyTo(CCopyToOptions &options, const CRecordVector<UInt32> &ind
if (indices.Size() == 1)
- extracter.FirstFilePath = GetItemRelPath(indices[0]);
+ {
+ extracter.Hash.FirstFileName = GetItemRelPath(indices[0]);
+ extracter.Hash.MainName = extracter.Hash.FirstFileName;
+ }
if (options.VirtFileSystem)
{
@@ -186,7 +189,7 @@ HRESULT CPanel::CopyTo(CCopyToOptions &options, const CRecordVector<UInt32> &ind
extracter.ExtractCallbackSpec->SetHashCalc(&extracter.Hash);
}
- extracter.Hash.Init();
+ // extracter.Hash.Init();
UString title;
{
diff --git a/CPP/7zip/UI/FileManager/PanelCrc.cpp b/CPP/7zip/UI/FileManager/PanelCrc.cpp
index 7b918a02..1cfbfe5d 100644
--- a/CPP/7zip/UI/FileManager/PanelCrc.cpp
+++ b/CPP/7zip/UI/FileManager/PanelCrc.cpp
@@ -147,7 +147,7 @@ class CThreadCrc: public CProgressThreadVirt
public:
CDirEnumerator Enumerator;
CHashBundle Hash;
- FString FirstFilePath;
+ // FString FirstFilePath;
void SetStatus(const UString &s);
void AddErrorMessage(DWORD systemError, const FChar *name);
@@ -165,7 +165,7 @@ void CThreadCrc::ShowFinalResults(HWND hwnd)
if (!ResultsWereShown)
{
ResultsWereShown = true;
- ShowHashResults(Hash, fs2us(FirstFilePath), hwnd);
+ ShowHashResults(Hash, hwnd);
}
}
@@ -193,7 +193,7 @@ void CThreadCrc::SetStatus(const UString &s2)
HRESULT CThreadCrc::ProcessVirt()
{
- Hash.Init();
+ // Hash.Init();
CMyBuffer buf;
if (!buf.Allocate(kBufSize))
@@ -289,7 +289,7 @@ HRESULT CThreadCrc::ProcessVirt()
}
if (isFirstFile)
{
- FirstFilePath = path;
+ Hash.FirstFileName = path;
isFirstFile = false;
}
sync.Set_FilePath(fs2us(path));
@@ -370,9 +370,13 @@ HRESULT CApp::CalculateCrc2(const UString &methodName)
methods.Add(methodName);
RINOK(t.Hash.SetMethods(EXTERNAL_CODECS_VARS_G methods));
}
+
FOR_VECTOR (i, indices)
t.Enumerator.FilePaths.Add(us2fs(srcPanel.GetItemRelPath(indices[i])));
+ if (t.Enumerator.FilePaths.Size() == 1)
+ t.Hash.MainName = t.Enumerator.FilePaths[0];
+
UString basePrefix = srcPanel.GetFsPath();
UString basePrefix2 = basePrefix;
if (basePrefix2.Back() == ':')
diff --git a/CPP/7zip/UI/FileManager/PanelDrag.cpp b/CPP/7zip/UI/FileManager/PanelDrag.cpp
index 9f64c2c8..6a781e22 100644
--- a/CPP/7zip/UI/FileManager/PanelDrag.cpp
+++ b/CPP/7zip/UI/FileManager/PanelDrag.cpp
@@ -940,8 +940,10 @@ void CPanel::CompressDropFiles(const UStringVector &fileNames, const UString &fo
if (IsFolderInTemp(folderPath2F))
folderPath2 = ROOT_FS_FOLDER;
}
- const UString archiveName = CreateArchiveName(fileNames.Front(), (fileNames.Size() > 1), false);
- CompressFiles(folderPath2, archiveName, L"",
+
+ const UString arcName = CreateArchiveName(fileNames);
+
+ CompressFiles(folderPath2, arcName, L"",
true, // addExtension
fileNames,
false, // email
diff --git a/CPP/7zip/UI/GUI/BenchmarkDialog.cpp b/CPP/7zip/UI/GUI/BenchmarkDialog.cpp
index 59dc78b3..e6dc57ba 100644
--- a/CPP/7zip/UI/GUI/BenchmarkDialog.cpp
+++ b/CPP/7zip/UI/GUI/BenchmarkDialog.cpp
@@ -324,7 +324,6 @@ static void PrintSize_MB(UString &s, UInt64 size)
s += kMB;
}
-extern bool g_LargePagesMode;
UInt32 CBenchmarkDialog::OnChangeDictionary()
{
@@ -338,8 +337,14 @@ UInt32 CBenchmarkDialog::OnChangeDictionary()
s += " / ";
PrintSize_MB(s, ramSize);
}
- if (g_LargePagesMode)
- s += " LP";
+
+ #ifdef _7ZIP_LARGE_PAGES
+ {
+ AString s2;
+ Add_LargePages_String(s2);
+ s += s2;
+ }
+ #endif
SetItemText(IDT_BENCH_MEMORY_VAL, s);
diff --git a/CPP/7zip/UI/GUI/ExtractGUI.cpp b/CPP/7zip/UI/GUI/ExtractGUI.cpp
index 814415f6..1e37efb8 100644
--- a/CPP/7zip/UI/GUI/ExtractGUI.cpp
+++ b/CPP/7zip/UI/GUI/ExtractGUI.cpp
@@ -99,8 +99,10 @@ HRESULT CThreadExtracting::ProcessVirt()
CDecompressStat Stat;
#ifndef _SFX
+ /*
if (HashBundle)
HashBundle->Init();
+ */
#endif
HRESULT res = Extract(codecs,
@@ -119,7 +121,7 @@ HRESULT CThreadExtracting::ProcessVirt()
{
AddValuePair(Pairs, IDS_ARCHIVES_COLON, Stat.NumArchives);
AddSizeValuePair(Pairs, IDS_PROP_PACKED_SIZE, Stat.PackSize);
- AddHashBundleRes(Pairs, *HashBundle, UString());
+ AddHashBundleRes(Pairs, *HashBundle);
}
else if (Options->TestMode)
{
diff --git a/CPP/7zip/UI/GUI/HashGUI.cpp b/CPP/7zip/UI/GUI/HashGUI.cpp
index 7cb00973..37cd65e9 100644
--- a/CPP/7zip/UI/GUI/HashGUI.cpp
+++ b/CPP/7zip/UI/GUI/HashGUI.cpp
@@ -27,6 +27,7 @@ class CHashCallbackGUI: public CProgressThreadVirt, public IHashCallbackUI
UInt64 NumFiles;
bool _curIsFolder;
UString FirstFileName;
+ // UString MainPath;
CPropNameValPairs PropNameValPairs;
@@ -71,9 +72,9 @@ void AddSizeValue(UString &s, UInt64 value)
if (value >= (1 << 10))
{
char c;
- if (value >= ((UInt64)10 << 30)) { value >>= 30; c = 'G'; }
- if (value >= (10 << 20)) { value >>= 20; c = 'M'; }
- else { value >>= 10; c = 'K'; }
+ if (value >= ((UInt64)10 << 30)) { value >>= 30; c = 'G'; }
+ else if (value >= (10 << 20)) { value >>= 20; c = 'M'; }
+ else { value >>= 10; c = 'K'; }
char sz[32];
ConvertUInt64ToString(value, sz);
s += " (";
@@ -192,19 +193,25 @@ static void AddHashResString(CPropNameValPairs &s, const CHasherState &h, unsign
}
-void AddHashBundleRes(CPropNameValPairs &s, const CHashBundle &hb, const UString &firstFileName)
+void AddHashBundleRes(CPropNameValPairs &s, const CHashBundle &hb)
{
if (hb.NumErrors != 0)
AddValuePair(s, IDS_PROP_NUM_ERRORS, hb.NumErrors);
-
- if (hb.NumFiles == 1 && hb.NumDirs == 0 && !firstFileName.IsEmpty())
+
+ if (hb.NumFiles == 1 && hb.NumDirs == 0 && !hb.FirstFileName.IsEmpty())
{
CProperty &pair = s.AddNew();
LangString(IDS_PROP_NAME, pair.Name);
- pair.Value = firstFileName;
+ pair.Value = hb.FirstFileName;
}
else
{
+ if (!hb.MainName.IsEmpty())
+ {
+ CProperty &pair = s.AddNew();
+ LangString(IDS_PROP_NAME, pair.Name);
+ pair.Value = hb.MainName;
+ }
if (hb.NumDirs != 0)
AddValuePair(s, IDS_PROP_FOLDERS, hb.NumDirs);
AddValuePair(s, IDS_PROP_FILES, hb.NumFiles);
@@ -240,10 +247,10 @@ void AddHashBundleRes(CPropNameValPairs &s, const CHashBundle &hb, const UString
}
-void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFileName)
+void AddHashBundleRes(UString &s, const CHashBundle &hb)
{
CPropNameValPairs pairs;
- AddHashBundleRes(pairs, hb, firstFileName);
+ AddHashBundleRes(pairs, hb);
FOR_VECTOR (i, pairs)
{
@@ -263,9 +270,11 @@ void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFil
}
-HRESULT CHashCallbackGUI::AfterLastFile(const CHashBundle &hb)
+HRESULT CHashCallbackGUI::AfterLastFile(CHashBundle &hb)
{
- AddHashBundleRes(PropNameValPairs, hb, FirstFileName);
+ hb.FirstFileName = FirstFileName;
+ // MainPath
+ AddHashBundleRes(PropNameValPairs, hb);
CProgressSync &sync = Sync;
sync.Set_NumFilesCur(hb.NumFiles);
@@ -335,10 +344,10 @@ void ShowHashResults(const CPropNameValPairs &propPairs, HWND hwnd)
}
-void ShowHashResults(const CHashBundle &hb, const UString &firstFileName, HWND hwnd)
+void ShowHashResults(const CHashBundle &hb, HWND hwnd)
{
CPropNameValPairs propPairs;
- AddHashBundleRes(propPairs, hb, firstFileName);
+ AddHashBundleRes(propPairs, hb);
ShowHashResults(propPairs, hwnd);
}
diff --git a/CPP/7zip/UI/GUI/HashGUI.h b/CPP/7zip/UI/GUI/HashGUI.h
index 4035abf1..82644535 100644
--- a/CPP/7zip/UI/GUI/HashGUI.h
+++ b/CPP/7zip/UI/GUI/HashGUI.h
@@ -18,10 +18,10 @@ void AddValuePair(CPropNameValPairs &pairs, UINT resourceID, UInt64 value);
void AddSizeValue(UString &s, UInt64 value);
void AddSizeValuePair(CPropNameValPairs &pairs, UINT resourceID, UInt64 value);
-void AddHashBundleRes(CPropNameValPairs &s, const CHashBundle &hb, const UString &firstFileName);
-void AddHashBundleRes(UString &s, const CHashBundle &hb, const UString &firstFileName);
+void AddHashBundleRes(CPropNameValPairs &s, const CHashBundle &hb);
+void AddHashBundleRes(UString &s, const CHashBundle &hb);
void ShowHashResults(const CPropNameValPairs &propPairs, HWND hwnd);
-void ShowHashResults(const CHashBundle &hb, const UString &firstFileName, HWND hwnd);
+void ShowHashResults(const CHashBundle &hb, HWND hwnd);
#endif
diff --git a/CPP/Build.mak b/CPP/Build.mak
index 5a11d066..4186a60b 100644
--- a/CPP/Build.mak
+++ b/CPP/Build.mak
@@ -4,19 +4,20 @@ LIBS = $(LIBS) oleaut32.lib ole32.lib
CFLAGS = $(CFLAGS) -DUNICODE -D_UNICODE
!ENDIF
-# CFLAGS = $(CFLAGS) -FAsc -Fa$O/Asm/
-
!IFNDEF O
-!IFDEF CPU
-O=$(CPU)
+!IFDEF PLATFORM
+O=$(PLATFORM)
!ELSE
-O=O
+O=o
!ENDIF
!ENDIF
-!IF "$(CPU)" == "AMD64"
+# CFLAGS = $(CFLAGS) -FAsc -Fa$O/asm/
+
+
+!IF "$(PLATFORM)" == "x64"
MY_ML = ml64 -Dx64 -WX
-!ELSEIF "$(CPU)" == "ARM"
+!ELSEIF "$(PLATFORM)" == "arm"
MY_ML = armasm -WX
!ELSE
MY_ML = ml -WX
@@ -29,16 +30,16 @@ RFLAGS = $(RFLAGS) -dUNDER_CE
LFLAGS = $(LFLAGS) /ENTRY:mainACRTStartup
!ENDIF
!ELSE
-!IFNDEF NEW_COMPILER
+!IFDEF OLD_COMPILER
LFLAGS = $(LFLAGS) -OPT:NOWIN98
!ENDIF
-!IF "$(CPU)" != "ARM" && "$(CPU)" != "ARM64"
+!IF "$(PLATFORM)" != "arm" && "$(PLATFORM)" != "arm64"
CFLAGS = $(CFLAGS) -Gr
!ENDIF
LIBS = $(LIBS) user32.lib advapi32.lib shell32.lib
!ENDIF
-!IF "$(CPU)" == "ARM"
+!IF "$(PLATFORM)" == "arm"
COMPL_ASM = $(MY_ML) $** $O/$(*B).obj
!ELSE
COMPL_ASM = $(MY_ML) -c -Fo$O/ $**
@@ -46,19 +47,19 @@ COMPL_ASM = $(MY_ML) -c -Fo$O/ $**
CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -W4 -WX -EHsc -Gy -GR- -GF
-!IFDEF MY_STATIC_LINK
+!IFDEF MY_DYNAMIC_LINK
+CFLAGS = $(CFLAGS) -MD
+!ELSE
!IFNDEF MY_SINGLE_THREAD
CFLAGS = $(CFLAGS) -MT
!ENDIF
-!ELSE
-CFLAGS = $(CFLAGS) -MD
!ENDIF
-!IFDEF NEW_COMPILER
+!IFNDEF OLD_COMPILER
CFLAGS = $(CFLAGS) -GS- -Zc:forScope -Zc:wchar_t
!IFNDEF UNDER_CE
CFLAGS = $(CFLAGS) -MP2
-!IFNDEF CPU
+!IFNDEF PLATFORM
# CFLAGS = $(CFLAGS) -arch:IA32
!ENDIF
!ENDIF
@@ -66,7 +67,13 @@ CFLAGS = $(CFLAGS) -MP2
CFLAGS = $(CFLAGS)
!ENDIF
-!IF "$(CPU)" == "AMD64"
+!IFNDEF UNDER_CE
+!IF "$(PLATFORM)" == "arm"
+CFLAGS = $(CFLAGS) -D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE
+!ENDIF
+!ENDIF
+
+!IF "$(PLATFORM)" == "x64"
CFLAGS_O1 = $(CFLAGS) -O1
!ELSE
CFLAGS_O1 = $(CFLAGS) -O1
@@ -82,7 +89,7 @@ LFLAGS = $(LFLAGS) /LARGEADDRESSAWARE
!IFDEF DEF_FILE
LFLAGS = $(LFLAGS) -DLL -DEF:$(DEF_FILE)
!ELSE
-!IF defined(MY_FIXED) && "$(CPU)" != "ARM" && "$(CPU)" != "ARM64"
+!IF defined(MY_FIXED) && "$(PLATFORM)" != "arm" && "$(PLATFORM)" != "arm64"
LFLAGS = $(LFLAGS) /FIXED
!ELSE
LFLAGS = $(LFLAGS) /FIXED:NO
@@ -91,7 +98,7 @@ LFLAGS = $(LFLAGS) /FIXED:NO
!ENDIF
-# !IF "$(CPU)" == "AMD64"
+# !IF "$(PLATFORM)" == "x64"
!IFDEF SUB_SYS_VER
@@ -131,10 +138,10 @@ clean:
$O:
if not exist "$O" mkdir "$O"
-$O/Asm:
- if not exist "$O/Asm" mkdir "$O/Asm"
+$O/asm:
+ if not exist "$O/asm" mkdir "$O/asm"
-$(PROGPATH): $O $O/Asm $(OBJS) $(DEF_FILE)
+$(PROGPATH): $O $O/asm $(OBJS) $(DEF_FILE)
link $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)
!IFNDEF NO_DEFAULT_RES
diff --git a/CPP/Common/ListFileUtils.cpp b/CPP/Common/ListFileUtils.cpp
index 9112003b..ca345e87 100644
--- a/CPP/Common/ListFileUtils.cpp
+++ b/CPP/Common/ListFileUtils.cpp
@@ -25,14 +25,21 @@ static void AddName(UStringVector &strings, UString &s)
strings.Add(s);
}
-bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage)
+bool ReadNamesFromListFile2(CFSTR fileName, UStringVector &strings, UINT codePage, DWORD &lastError)
{
+ lastError = 0;
NWindows::NFile::NIO::CInFile file;
if (!file.Open(fileName))
+ {
+ lastError = ::GetLastError();
return false;
+ }
UInt64 fileSize;
if (!file.GetLength(fileSize))
+ {
+ lastError = ::GetLastError();
return false;
+ }
if (fileSize >= ((UInt32)1 << 31) - 32)
return false;
UString u;
@@ -43,7 +50,10 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
CByteArr buf((size_t)fileSize);
UInt32 processed;
if (!file.Read(buf, (UInt32)fileSize, processed))
+ {
+ lastError = ::GetLastError();
return false;
+ }
if (processed != fileSize)
return false;
file.Close();
@@ -74,7 +84,10 @@ bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage
char *p = s.GetBuf((unsigned)fileSize);
UInt32 processed;
if (!file.Read(p, (UInt32)fileSize, processed))
+ {
+ lastError = ::GetLastError();
return false;
+ }
if (processed != fileSize)
return false;
file.Close();
diff --git a/CPP/Common/ListFileUtils.h b/CPP/Common/ListFileUtils.h
index e8d833fd..a91e4b11 100644
--- a/CPP/Common/ListFileUtils.h
+++ b/CPP/Common/ListFileUtils.h
@@ -9,6 +9,10 @@
#define MY__CP_UTF16 1200
#define MY__CP_UTF16BE 1201
-bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
+// bool ReadNamesFromListFile(CFSTR fileName, UStringVector &strings, UINT codePage = CP_OEMCP);
+
+ // = CP_OEMCP
+bool ReadNamesFromListFile2(CFSTR fileName, UStringVector &strings, UINT codePage,
+ DWORD &lastError);
#endif
diff --git a/CPP/Common/MyString.h b/CPP/Common/MyString.h
index abdc8cf8..40de52cd 100644
--- a/CPP/Common/MyString.h
+++ b/CPP/Common/MyString.h
@@ -307,6 +307,7 @@ public:
void ReplaceOneCharAtPos(unsigned pos, char c) { _chars[pos] = c; }
+ char *GetBuf() { return _chars; }
/* GetBuf(minLen): provides the buffer that can store
at least (minLen) characters and additional null terminator.
9.35: GetBuf doesn't preserve old characters and terminator */
diff --git a/DOC/7zFormat.txt b/DOC/7zFormat.txt
index 55b52b1b..74cdfa41 100644
--- a/DOC/7zFormat.txt
+++ b/DOC/7zFormat.txt
@@ -1,4 +1,4 @@
-7z Format description (4.59)
+7z Format description (18.06)
----------------------------
This file contains description of 7z archive format.
@@ -175,7 +175,7 @@ SignatureHeader
ArchiveVersion
{
BYTE Major; // now = 0
- BYTE Minor; // now = 2
+ BYTE Minor; // now = 4
};
UINT32 StartHeaderCRC;
@@ -399,7 +399,7 @@ FilesInfo
UINT64 DataIndex
[]
for(Definded Items)
- UINT64 Time
+ REAL_UINT64 Time
[]
kNames: (0x11)
diff --git a/DOC/7zip.inf b/DOC/7zip.inf
index 6fc1e064..ca5cd7dd 100644
--- a/DOC/7zip.inf
+++ b/DOC/7zip.inf
@@ -10,8 +10,8 @@ AppName = "7-Zip"
InstallDir = %CE1%\%AppName%
[Strings]
-AppVer = "18.05"
-AppDate = "2018-04-30"
+AppVer = "18.06"
+AppDate = "2018-12-30"
[CEDevice]
; ProcessorType = 2577 ; ARM
diff --git a/DOC/7zip.nsi b/DOC/7zip.nsi
index fcb8952e..67743682 100644
--- a/DOC/7zip.nsi
+++ b/DOC/7zip.nsi
@@ -2,7 +2,7 @@
;Defines
!define VERSION_MAJOR 18
-!define VERSION_MINOR 05
+!define VERSION_MINOR 06
!define VERSION_POSTFIX_FULL ""
!ifdef WIN64
!ifdef IA64
diff --git a/DOC/7zip.wxs b/DOC/7zip.wxs
index 04eb2605..f243bf86 100644
--- a/DOC/7zip.wxs
+++ b/DOC/7zip.wxs
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<?define VerMajor = "18" ?>
-<?define VerMinor = "05" ?>
+<?define VerMinor = "06" ?>
<?define VerBuild = "00" ?>
<?define MmVer = "$(var.VerMajor).$(var.VerMinor)" ?>
<?define MmHex = "$(var.VerMajor)$(var.VerMinor)" ?>
diff --git a/DOC/Methods.txt b/DOC/Methods.txt
index fe38c78c..d4a1b1dd 100644
--- a/DOC/Methods.txt
+++ b/DOC/Methods.txt
@@ -1,8 +1,8 @@
7-Zip method IDs for 7z and xz archives
---------------------------------------
-Version: 17.01
-Date: 2017-05-27
+Version: 18.06
+Date: 2018-06-30
Each compression or crypto method in 7z is associated with unique binary value (ID).
The length of ID in bytes is arbitrary but it can not exceed 63 bits (8 bytes).
@@ -132,6 +132,12 @@ List of defined IDs
04 - LZ4
05 - LZ5
06 - LIZARD
+
+ 12 xx - reserverd (Denis Anisimov)
+
+ 01 - WavPack2
+ FE - eSplitter
+ FF - RawSplitter
06.. - Crypto
diff --git a/DOC/readme.txt b/DOC/readme.txt
index 4cba88e6..06bb06b8 100644
--- a/DOC/readme.txt
+++ b/DOC/readme.txt
@@ -1,4 +1,4 @@
-7-Zip 18.05 Sources
+7-Zip 18.06 Sources
-------------------
7-Zip is a file archiver for Windows.
@@ -44,28 +44,50 @@ LZMA SDK is written and placed in the public domain by Igor Pavlov.
How to compile
--------------
-To compile sources you need Visual C++ 6.0.
-For compiling some files you also need
-new Platform SDK from Microsoft' Site:
-http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm
-or
-http://www.microsoft.com/msdownload/platformsdk/sdkupdate/XPSP2FULLInstall.htm
-or
-http://www.microsoft.com/msdownload/platformsdk/sdkupdate/
-
-If you use MSVC6, specify SDK directories at top of directories lists:
+
+To compile the sources to Windows binaries you need Visual Studio compiler and/or Windows SDK.
+You can use latest Windows Studio 2017 to compile binaries for x86, x64 and arm64 platforms.
+Also you can use old compilers for some platforms:
+ x86 : Visual C++ 6.0 with Platform SDK
+ x64 : Windows Server 2003 R2 Platform SDK
+ arm64 : Windows Studio 2017
+ arm : Windows Studio 2017
+ ia64 (itanium) : Windows Server 2003 R2 Platform SDK
+ arm for Windows CE : Standard SDK for Windows CE 5.0
+
+If you use MSVC6, specify also Platform SDK directories at top of directories lists:
Tools / Options / Directories
- Include files
- Library files
-
-To compile 7-Zip for AMD64 and IA64 you need:
- Windows Server 2003 SP1 Platform SDK from microsoft.com
-
Also you need Microsoft Macro Assembler:
- ml.exe for x86
- - ml64.exe for AMD64
-You can use ml.exe from Windows SDK for Windows Vista or some other version.
+ - ml64.exe for x64
+You can use ml.exe from Windows SDK for Windows Vista or some later versions.
+
+There are two ways to compile 7-Zip binaries:
+1) via makefile in command line.
+2) via dsp file in Visual Studio.
+
+The dsp file compiling can be used for development and debug purposes.
+The final 7-Zip binaries are compiled via makefiles, that provide best
+optimization options.
+
+How to compile with makefile
+----------------------------
+
+Some macronames can be defined for compiling with makefile:
+
+PLATFORM
+ with possible values: x64, x86, arm64, arm, ia64
+
+OLD_COMPILER
+ for old VC compiler, like MSCV 6.0.
+
+MY_DYNAMIC_LINK
+ for dynamic linking to the run-time library (msvcrt.dll).
+ The default makefile option is static linking to the run-time library.
+
Compiling under Unix/Linux
diff --git a/DOC/src-history.txt b/DOC/src-history.txt
index d2bdd77f..7d918255 100644
--- a/DOC/src-history.txt
+++ b/DOC/src-history.txt
@@ -1,6 +1,21 @@
HISTORY of the 7-Zip source code
--------------------------------
+18.06 2018-12-30
+-------------------------
+- The speed for LZMA/LZMA2 compressing was increased by 3-10%,
+ and there are minor changes in compression ratio.
+- Some bugs were fixed.
+- The bug in 7-Zip 18.02-18.05 was fixed:
+ There was memory leak in multithreading xz decoder - XzDecMt_Decode(),
+ if xz stream contains only one block.
+- 7-Zip 18.02-18.05 used only one CPU thread for bz2 archive creation.
+- The changes for MSVS compiler makefiles:
+ - the makefiles now use "PLATFORM" macroname with values (x64, x86, arm64)
+ instead of "CPU" macroname with values (AMD64, ARM64).
+ - the makefiles by default now use static version of the run-time library.
+
+
18.05 2018-04-30
-------------------------
- The speed for LZMA/LZMA2 compressing was increased