update lzma-sdk from 18.05 to 19.00

pull/2112/head
Gabriele Gristina 5 years ago
parent d1f473d6ba
commit 903722c415

@ -1,5 +1,5 @@
/* 7zArcIn.c -- 7z Input functions /* 7zArcIn.c -- 7z Input functions
2017-04-03 : Igor Pavlov : Public domain */ 2018-12-31 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -19,7 +19,7 @@
{ MY_ALLOC(Byte, to, size, alloc); memcpy(to, from, size); } { MY_ALLOC(Byte, to, size, alloc); memcpy(to, from, size); }
#define MY_ALLOC_ZE_AND_CPY(to, size, from, alloc) \ #define MY_ALLOC_ZE_AND_CPY(to, size, from, alloc) \
{ if ((size) == 0) p = NULL; else { MY_ALLOC_AND_CPY(to, size, from, alloc) } } { if ((size) == 0) to = NULL; else { MY_ALLOC_AND_CPY(to, size, from, alloc) } }
#define k7zMajorVersion 0 #define k7zMajorVersion 0
@ -666,7 +666,7 @@ static SRes ReadUnpackInfo(CSzAr *p,
MY_ALLOC(size_t, p->FoCodersOffsets, (size_t)numFolders + 1, alloc); MY_ALLOC(size_t, p->FoCodersOffsets, (size_t)numFolders + 1, alloc);
MY_ALLOC(UInt32, p->FoStartPackStreamIndex, (size_t)numFolders + 1, alloc); MY_ALLOC(UInt32, p->FoStartPackStreamIndex, (size_t)numFolders + 1, alloc);
MY_ALLOC(UInt32, p->FoToCoderUnpackSizes, (size_t)numFolders + 1, alloc); MY_ALLOC(UInt32, p->FoToCoderUnpackSizes, (size_t)numFolders + 1, alloc);
MY_ALLOC(Byte, p->FoToMainUnpackSizeIndex, (size_t)numFolders, alloc); MY_ALLOC_ZE(Byte, p->FoToMainUnpackSizeIndex, (size_t)numFolders, alloc);
startBufPtr = sd.Data; startBufPtr = sd.Data;
@ -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) UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest)
{ {
Bool needSlash; BoolInt needSlash;
if (!p->FileNameOffsets) if (!p->FileNameOffsets)
{ {
*(--dest) = 0; *(--dest) = 0;

@ -1,5 +1,5 @@
/* 7zDec.c -- Decoding from 7z folder /* 7zDec.c -- Decoding from 7z folder
2017-04-03 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -44,7 +44,7 @@ typedef struct
const Byte *end; const Byte *end;
const Byte *begin; const Byte *begin;
UInt64 processed; UInt64 processed;
Bool extra; BoolInt extra;
SRes res; SRes res;
const ILookInStream *inStream; const ILookInStream *inStream;
} CByteInToLook; } CByteInToLook;
@ -156,7 +156,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
{ {
SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos; SizeT inProcessed = (SizeT)lookahead, dicPos = state.dicPos;
ELzmaStatus status; ELzmaStatus status;
res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status); res = LzmaDec_DecodeToDic(&state, outSize, (const Byte *)inBuf, &inProcessed, LZMA_FINISH_END, &status);
lookahead -= inProcessed; lookahead -= inProcessed;
inSize -= inProcessed; inSize -= inProcessed;
if (res != SZ_OK) if (res != SZ_OK)
@ -218,7 +218,7 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
{ {
SizeT inProcessed = (SizeT)lookahead, dicPos = state.decoder.dicPos; SizeT inProcessed = (SizeT)lookahead, dicPos = state.decoder.dicPos;
ELzmaStatus status; ELzmaStatus status;
res = Lzma2Dec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status); res = Lzma2Dec_DecodeToDic(&state, outSize, (const Byte *)inBuf, &inProcessed, LZMA_FINISH_END, &status);
lookahead -= inProcessed; lookahead -= inProcessed;
inSize -= inProcessed; inSize -= inProcessed;
if (res != SZ_OK) if (res != SZ_OK)
@ -269,7 +269,7 @@ static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer
return SZ_OK; return SZ_OK;
} }
static Bool IS_MAIN_METHOD(UInt32 m) static BoolInt IS_MAIN_METHOD(UInt32 m)
{ {
switch (m) switch (m)
{ {
@ -286,7 +286,7 @@ static Bool IS_MAIN_METHOD(UInt32 m)
return False; return False;
} }
static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c) static BoolInt IS_SUPPORTED_CODER(const CSzCoderInfo *c)
{ {
return return
c->NumStreams == 1 c->NumStreams == 1

@ -1,5 +1,5 @@
/* 7zTypes.h -- Basic types /* 7zTypes.h -- Basic types
2017-07-17 : Igor Pavlov : Public domain */ 2018-08-04 : Igor Pavlov : Public domain */
#ifndef __7Z_TYPES_H #ifndef __7Z_TYPES_H
#define __7Z_TYPES_H #define __7Z_TYPES_H
@ -103,7 +103,8 @@ typedef UInt32 SizeT;
typedef size_t SizeT; typedef size_t SizeT;
#endif #endif
typedef int Bool; typedef int BoolInt;
/* typedef BoolInt Bool; */
#define True 1 #define True 1
#define False 0 #define False 0

@ -1,7 +1,7 @@
#define MY_VER_MAJOR 18 #define MY_VER_MAJOR 19
#define MY_VER_MINOR 05 #define MY_VER_MINOR 00
#define MY_VER_BUILD 0 #define MY_VER_BUILD 0
#define MY_VERSION_NUMBERS "18.05" #define MY_VERSION_NUMBERS "19.00"
#define MY_VERSION MY_VERSION_NUMBERS #define MY_VERSION MY_VERSION_NUMBERS
#ifdef MY_CPU_NAME #ifdef MY_CPU_NAME
@ -10,7 +10,7 @@
#define MY_VERSION_CPU MY_VERSION #define MY_VERSION_CPU MY_VERSION
#endif #endif
#define MY_DATE "2018-04-30" #define MY_DATE "2019-02-21"
#undef MY_COPYRIGHT #undef MY_COPYRIGHT
#undef MY_VERSION_COPYRIGHT_DATE #undef MY_VERSION_COPYRIGHT_DATE
#define MY_AUTHOR_NAME "Igor Pavlov" #define MY_AUTHOR_NAME "Igor Pavlov"

@ -1,5 +1,5 @@
/* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code) /* Bcj2Enc.c -- BCJ2 Encoder (Converter for x86 code)
2017-04-28 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -52,7 +52,7 @@ void Bcj2Enc_Init(CBcj2Enc *p)
p->probs[i] = kBitModelTotal >> 1; 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) 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]); Byte context = (Byte)(num == 0 ? p->prevByte : src[-1]);
Bool needConvert; BoolInt needConvert;
p->bufs[BCJ2_STREAM_MAIN] = dest + 1; p->bufs[BCJ2_STREAM_MAIN] = dest + 1;
p->ip += (UInt32)num + 1; p->ip += (UInt32)num + 1;
@ -253,7 +253,7 @@ void Bcj2Enc_Encode(CBcj2Enc *p)
{ {
const Byte *src = p->src; const Byte *src = p->src;
const Byte *srcLim = p->srcLim; const Byte *srcLim = p->srcLim;
unsigned finishMode = p->finishMode; EBcj2Enc_FinishMode finishMode = p->finishMode;
p->src = p->temp; p->src = p->temp;
p->srcLim = p->temp + p->tempPos; p->srcLim = p->temp + p->tempPos;

@ -1,5 +1,5 @@
/* CpuArch.c -- CPU specific code /* CpuArch.c -- CPU specific code
2016-02-25: Igor Pavlov : Public domain */ 2018-02-18: Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -115,7 +115,7 @@ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
#endif #endif
} }
Bool x86cpuid_CheckAndRead(Cx86cpuid *p) BoolInt x86cpuid_CheckAndRead(Cx86cpuid *p)
{ {
CHECK_CPUID_IS_SUPPORTED CHECK_CPUID_IS_SUPPORTED
MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]); 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; return -1;
} }
Bool CPU_Is_InOrder() BoolInt CPU_Is_InOrder()
{ {
Cx86cpuid p; Cx86cpuid p;
int firm; int firm;
@ -175,7 +175,7 @@ Bool CPU_Is_InOrder()
#if !defined(MY_CPU_AMD64) && defined(_WIN32) #if !defined(MY_CPU_AMD64) && defined(_WIN32)
#include <windows.h> #include <windows.h>
static Bool CPU_Sys_Is_SSE_Supported() static BoolInt CPU_Sys_Is_SSE_Supported()
{ {
OSVERSIONINFO vi; OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi); vi.dwOSVersionInfoSize = sizeof(vi);
@ -188,7 +188,7 @@ static Bool CPU_Sys_Is_SSE_Supported()
#define CHECK_SYS_SSE_SUPPORT #define CHECK_SYS_SSE_SUPPORT
#endif #endif
Bool CPU_Is_Aes_Supported() BoolInt CPU_Is_Aes_Supported()
{ {
Cx86cpuid p; Cx86cpuid p;
CHECK_SYS_SSE_SUPPORT CHECK_SYS_SSE_SUPPORT
@ -197,4 +197,22 @@ Bool CPU_Is_Aes_Supported()
return (p.c >> 25) & 1; return (p.c >> 25) & 1;
} }
BoolInt CPU_IsSupported_PageGB()
{
Cx86cpuid cpuid;
if (!x86cpuid_CheckAndRead(&cpuid))
return False;
{
UInt32 d[4] = { 0 };
MyCPUID(0x80000000, &d[0], &d[1], &d[2], &d[3]);
if (d[0] < 0x80000001)
return False;
}
{
UInt32 d[4] = { 0 };
MyCPUID(0x80000001, &d[0], &d[1], &d[2], &d[3]);
return (d[3] >> 26) & 1;
}
}
#endif #endif

@ -1,5 +1,5 @@
/* CpuArch.h -- CPU specific code /* CpuArch.h -- CPU specific code
2017-09-04 : Igor Pavlov : Public domain */ 2018-02-18 : Igor Pavlov : Public domain */
#ifndef __CPU_ARCH_H #ifndef __CPU_ARCH_H
#define __CPU_ARCH_H #define __CPU_ARCH_H
@ -318,15 +318,16 @@ enum
void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d); 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); int x86cpuid_GetFirm(const Cx86cpuid *p);
#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF)) #define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
#define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF)) #define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF))
#define x86cpuid_GetStepping(ver) (ver & 0xF) #define x86cpuid_GetStepping(ver) (ver & 0xF)
Bool CPU_Is_InOrder(); BoolInt CPU_Is_InOrder();
Bool CPU_Is_Aes_Supported(); BoolInt CPU_Is_Aes_Supported();
BoolInt CPU_IsSupported_PageGB();
#endif #endif

@ -1,5 +1,5 @@
/* DllSecur.c -- DLL loading security /* DllSecur.c -- DLL loading security
2016-10-04 : Igor Pavlov : Public domain */ 2018-02-21 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -28,10 +28,31 @@ static const char * const g_Dlls =
"CRYPTBASE\0" "CRYPTBASE\0"
"OLEACC\0" "OLEACC\0"
"CLBCATQ\0" "CLBCATQ\0"
"VERSION\0"
; ;
#endif #endif
void My_SetDefaultDllDirectories()
{
#ifndef UNDER_CE
OSVERSIONINFO vi;
vi.dwOSVersionInfoSize = sizeof(vi);
GetVersionEx(&vi);
if (!GetVersionEx(&vi) || vi.dwMajorVersion != 6 || vi.dwMinorVersion != 0)
{
Func_SetDefaultDllDirectories setDllDirs = (Func_SetDefaultDllDirectories)
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "SetDefaultDllDirectories");
if (setDllDirs)
if (setDllDirs(MY_LOAD_LIBRARY_SEARCH_SYSTEM32 | MY_LOAD_LIBRARY_SEARCH_USER_DIRS))
return;
}
#endif
}
void LoadSecurityDlls() void LoadSecurityDlls()
{ {
#ifndef UNDER_CE #ifndef UNDER_CE
@ -70,7 +91,7 @@ void LoadSecurityDlls()
for (;;) for (;;)
{ {
char c = *dll++; char c = *dll++;
buf[pos + k] = c; buf[pos + k] = (Byte)c;
k++; k++;
if (c == 0) if (c == 0)
break; break;

@ -1,5 +1,5 @@
/* DllSecur.h -- DLL loading for security /* DllSecur.h -- DLL loading for security
2016-06-08 : Igor Pavlov : Public domain */ 2018-02-19 : Igor Pavlov : Public domain */
#ifndef __DLL_SECUR_H #ifndef __DLL_SECUR_H
#define __DLL_SECUR_H #define __DLL_SECUR_H
@ -10,6 +10,7 @@ EXTERN_C_BEGIN
#ifdef _WIN32 #ifdef _WIN32
void My_SetDefaultDllDirectories();
void LoadSecurityDlls(); void LoadSecurityDlls();
#endif #endif

@ -1,5 +1,5 @@
/* LzFind.c -- Match finder for LZ algorithms /* LzFind.c -- Match finder for LZ algorithms
2017-06-10 : Igor Pavlov : Public domain */ 2018-07-08 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -138,7 +138,7 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
void MatchFinder_Construct(CMatchFinder *p) void MatchFinder_Construct(CMatchFinder *p)
{ {
UInt32 i; unsigned i;
p->bufferBase = NULL; p->bufferBase = NULL;
p->directInput = 0; p->directInput = 0;
p->hash = NULL; p->hash = NULL;
@ -147,7 +147,7 @@ void MatchFinder_Construct(CMatchFinder *p)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
UInt32 r = i; UInt32 r = (UInt32)i;
unsigned j; unsigned j;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1))); r = (r >> 1) ^ (kCrcPoly & ((UInt32)0 - (r & 1)));
@ -368,6 +368,8 @@ static void MatchFinder_Normalize(CMatchFinder *p)
MatchFinder_ReduceOffsets(p, subValue); MatchFinder_ReduceOffsets(p, subValue);
} }
MY_NO_INLINE
static void MatchFinder_CheckLimits(CMatchFinder *p) static void MatchFinder_CheckLimits(CMatchFinder *p)
{ {
if (p->pos == kMaxValForNormalize) if (p->pos == kMaxValForNormalize)
@ -379,10 +381,16 @@ static void MatchFinder_CheckLimits(CMatchFinder *p)
MatchFinder_SetLimits(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 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
UInt32 *distances, UInt32 maxLen) UInt32 *distances, unsigned maxLen)
{ {
/*
son[_cyclicBufferPos] = curMatch; son[_cyclicBufferPos] = curMatch;
for (;;) for (;;)
{ {
@ -400,7 +408,8 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos,
break; break;
if (maxLen < len) if (maxLen < len)
{ {
*distances++ = maxLen = len; maxLen = len;
*distances++ = len;
*distances++ = delta - 1; *distances++ = delta - 1;
if (len == lenLimit) if (len == lenLimit)
return distances; 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 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
UInt32 *distances, UInt32 maxLen) UInt32 *distances, UInt32 maxLen)
{ {
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1); CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
UInt32 len0 = 0, len1 = 0; unsigned len0 = 0, len1 = 0;
for (;;) for (;;)
{ {
UInt32 delta = pos - curMatch; UInt32 delta = pos - curMatch;
@ -426,9 +478,10 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
return distances; 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; 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 (pb[len] == cur[len])
{ {
if (++len != lenLimit && 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; break;
if (maxLen < len) if (maxLen < len)
{ {
*distances++ = maxLen = len; maxLen = (UInt32)len;
*distances++ = (UInt32)len;
*distances++ = delta - 1; *distances++ = delta - 1;
if (len == lenLimit) if (len == lenLimit)
{ {
*ptr1 = pair[0]; *ptr1 = pair0;
*ptr0 = pair[1]; *ptr0 = pair[1];
return distances; 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, static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue) UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
{ {
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1); CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
UInt32 len0 = 0, len1 = 0; unsigned len0 = 0, len1 = 0;
for (;;) for (;;)
{ {
UInt32 delta = pos - curMatch; UInt32 delta = pos - curMatch;
@ -480,9 +534,9 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
return; 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; const Byte *pb = cur - delta;
UInt32 len = (len0 < len1 ? len0 : len1); unsigned len = (len0 < len1 ? len0 : len1);
if (pb[len] == cur[len]) if (pb[len] == cur[len])
{ {
while (++len != lenLimit) while (++len != lenLimit)
@ -520,13 +574,13 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
p->buffer++; \ p->buffer++; \
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p); 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; } static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
#define GET_MATCHES_HEADER2(minLen, ret_op) \ #define GET_MATCHES_HEADER2(minLen, ret_op) \
UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \ unsigned lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \
lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ lenLimit = (unsigned)p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
cur = p->buffer; cur = p->buffer;
#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0) #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 MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
#define GET_MATCHES_FOOTER(offset, maxLen) \ #define GET_MATCHES_FOOTER(offset, maxLen) \
offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ offset = (unsigned)(GetMatchesSpec1((UInt32)lenLimit, curMatch, MF_PARAMS(p), \
distances + offset, maxLen) - distances); MOVE_POS_RET; distances + offset, (UInt32)maxLen) - distances); MOVE_POS_RET;
#define SKIP_FOOTER \ #define SKIP_FOOTER \
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
#define UPDATE_maxLen { \ #define UPDATE_maxLen { \
ptrdiff_t diff = (ptrdiff_t)0 - d2; \ ptrdiff_t diff = (ptrdiff_t)0 - d2; \
const Byte *c = cur + maxLen; \ const Byte *c = cur + maxLen; \
const Byte *lim = cur + lenLimit; \ const Byte *lim = cur + lenLimit; \
for (; c != lim; c++) if (*(c + diff) != *c) break; \ 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) static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{ {
UInt32 offset; unsigned offset;
GET_MATCHES_HEADER(2) GET_MATCHES_HEADER(2)
HASH2_CALC; HASH2_CALC;
curMatch = p->hash[hv]; 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 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{ {
UInt32 offset; unsigned offset;
GET_MATCHES_HEADER(3) GET_MATCHES_HEADER(3)
HASH_ZIP_CALC; HASH_ZIP_CALC;
curMatch = p->hash[hv]; 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) static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{ {
UInt32 h2, d2, maxLen, offset, pos; UInt32 h2, d2, pos;
unsigned maxLen, offset;
UInt32 *hash; UInt32 *hash;
GET_MATCHES_HEADER(3) GET_MATCHES_HEADER(3)
@ -594,12 +649,12 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[0] = maxLen; distances[0] = (UInt32)maxLen;
distances[1] = d2 - 1; distances[1] = d2 - 1;
offset = 2; offset = 2;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
MOVE_POS_RET; 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) 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; UInt32 *hash;
GET_MATCHES_HEADER(4) GET_MATCHES_HEADER(4)
@ -618,12 +674,12 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash; hash = p->hash;
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3]; d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = (hash + kFix4HashSize)[hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = pos; hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos; (hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[hv] = 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) if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
{ {
distances[0] = maxLen = 2; maxLen = 2;
distances[0] = 2;
distances[1] = d2 - 1; distances[1] = d2 - 1;
offset = 2; offset = 2;
} }
@ -648,10 +705,10 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0) if (offset != 0)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[(size_t)offset - 2] = maxLen; distances[(size_t)offset - 2] = (UInt32)maxLen;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); SkipMatchesSpec((UInt32)lenLimit, curMatch, MF_PARAMS(p));
MOVE_POS_RET; MOVE_POS_RET;
} }
} }
@ -674,13 +731,13 @@ static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash; hash = p->hash;
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3]; d3 = pos - (hash + kFix3HashSize)[h3];
d4 = pos - (hash + kFix4HashSize)[h4]; d4 = pos - (hash + kFix4HashSize)[h4];
curMatch = (hash + kFix5HashSize)[hv]; curMatch = (hash + kFix5HashSize)[hv];
hash[ h2] = pos; hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos; (hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[h4] = pos; (hash + kFix4HashSize)[h4] = pos;
(hash + kFix5HashSize)[hv] = 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) 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; UInt32 *hash;
GET_MATCHES_HEADER(4) GET_MATCHES_HEADER(4)
@ -750,12 +808,11 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash; hash = p->hash;
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3]; d3 = pos - (hash + kFix3HashSize)[h3];
curMatch = (hash + kFix4HashSize)[hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = pos; hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos; (hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[hv] = 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) if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
{ {
distances[0] = maxLen = 2; maxLen = 2;
distances[0] = 2;
distances[1] = d2 - 1; distances[1] = d2 - 1;
offset = 2; offset = 2;
} }
@ -780,7 +838,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (offset != 0) if (offset != 0)
{ {
UPDATE_maxLen UPDATE_maxLen
distances[(size_t)offset - 2] = maxLen; distances[(size_t)offset - 2] = (UInt32)maxLen;
if (maxLen == lenLimit) if (maxLen == lenLimit)
{ {
p->son[p->cyclicBufferPos] = curMatch; p->son[p->cyclicBufferPos] = curMatch;
@ -791,7 +849,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (maxLen < 3) if (maxLen < 3)
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)); distances + offset, maxLen) - (distances));
MOVE_POS_RET MOVE_POS_RET
} }
@ -808,13 +866,13 @@ static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
hash = p->hash; hash = p->hash;
pos = p->pos; pos = p->pos;
d2 = pos - hash[ h2]; d2 = pos - hash [h2];
d3 = pos - (hash + kFix3HashSize)[h3]; d3 = pos - (hash + kFix3HashSize)[h3];
d4 = pos - (hash + kFix4HashSize)[h4]; d4 = pos - (hash + kFix4HashSize)[h4];
curMatch = (hash + kFix5HashSize)[hv]; curMatch = (hash + kFix5HashSize)[hv];
hash[ h2] = pos; hash [h2] = pos;
(hash + kFix3HashSize)[h3] = pos; (hash + kFix3HashSize)[h3] = pos;
(hash + kFix4HashSize)[h4] = pos; (hash + kFix4HashSize)[h4] = pos;
(hash + kFix5HashSize)[hv] = 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 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{ {
UInt32 offset; unsigned offset;
GET_MATCHES_HEADER(3) GET_MATCHES_HEADER(3)
HASH_ZIP_CALC; HASH_ZIP_CALC;
curMatch = p->hash[hv]; curMatch = p->hash[hv];
p->hash[hv] = p->pos; 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)); distances, 2) - (distances));
MOVE_POS_RET MOVE_POS_RET
} }
@ -940,7 +998,7 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH4_CALC; HASH4_CALC;
hash = p->hash; hash = p->hash;
curMatch = (hash + kFix4HashSize)[hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = hash [h2] =
(hash + kFix3HashSize)[h3] = (hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[hv] = p->pos; (hash + kFix4HashSize)[hv] = p->pos;
SKIP_FOOTER SKIP_FOOTER
@ -959,7 +1017,7 @@ static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH5_CALC; HASH5_CALC;
hash = p->hash; hash = p->hash;
curMatch = (hash + kFix5HashSize)[hv]; curMatch = (hash + kFix5HashSize)[hv];
hash[ h2] = hash [h2] =
(hash + kFix3HashSize)[h3] = (hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[h4] = (hash + kFix4HashSize)[h4] =
(hash + kFix5HashSize)[hv] = p->pos; (hash + kFix5HashSize)[hv] = p->pos;
@ -979,7 +1037,7 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH4_CALC; HASH4_CALC;
hash = p->hash; hash = p->hash;
curMatch = (hash + kFix4HashSize)[hv]; curMatch = (hash + kFix4HashSize)[hv];
hash[ h2] = hash [h2] =
(hash + kFix3HashSize)[h3] = (hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[hv] = p->pos; (hash + kFix4HashSize)[hv] = p->pos;
p->son[p->cyclicBufferPos] = curMatch; p->son[p->cyclicBufferPos] = curMatch;
@ -999,7 +1057,7 @@ static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
HASH5_CALC; HASH5_CALC;
hash = p->hash; hash = p->hash;
curMatch = hash + kFix5HashSize)[hv]; curMatch = hash + kFix5HashSize)[hv];
hash[ h2] = hash [h2] =
(hash + kFix3HashSize)[h3] = (hash + kFix3HashSize)[h3] =
(hash + kFix4HashSize)[h4] = (hash + kFix4HashSize)[h4] =
(hash + kFix5HashSize)[hv] = p->pos; (hash + kFix5HashSize)[hv] = p->pos;

@ -1,5 +1,5 @@
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms /* 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" #include "Precomp.h"
@ -232,38 +232,57 @@ static void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
#define kEmptyHashValue 0 #define kEmptyHashValue 0
/* #define MFMT_GM_INLINE */ #define MFMT_GM_INLINE
#ifdef 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, MY_NO_INLINE
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, static UInt32 *GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes) size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
UInt32 *distances, UInt32 _maxLen, const UInt32 *hash, const UInt32 *limit, UInt32 size, UInt32 *posRes)
{ {
do do
{ {
UInt32 *distances = _distances + 1; UInt32 *_distances = ++distances;
UInt32 curMatch = pos - *hash++; UInt32 delta = *hash++;
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr0 = son + ((size_t)_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1); CLzRef *ptr1 = son + ((size_t)_cyclicBufferPos << 1);
UInt32 len0 = 0, len1 = 0; unsigned len0 = 0, len1 = 0;
UInt32 cutValue = _cutValue; UInt32 cutValue = _cutValue;
UInt32 maxLen = _maxLen; unsigned maxLen = (unsigned)_maxLen;
for (;;)
/*
if (size > 1)
{ {
UInt32 delta = pos - curMatch; UInt32 delta = *hash;
if (cutValue-- == 0 || delta >= _cyclicBufferSize) if (delta < _cyclicBufferSize)
{ {
*ptr0 = *ptr1 = kEmptyHashValue; UInt32 cyc1 = _cyclicBufferPos + 1;
break; 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; 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 (pb[len] == cur[len])
{ {
if (++len != lenLimit && 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; break;
if (maxLen < len) if (maxLen < len)
{ {
*distances++ = maxLen = len; maxLen = len;
*distances++ = (UInt32)len;
*distances++ = delta - 1; *distances++ = delta - 1;
if (len == lenLimit) if (len == lenLimit)
{ {
*ptr1 = pair[0]; UInt32 pair1 = pair[1];
*ptr0 = pair[1]; *ptr1 = pair0;
*ptr0 = pair1;
break; break;
} }
} }
} }
if (pb[len] < cur[len])
{
*ptr1 = curMatch;
ptr1 = pair + 1;
curMatch = *ptr1;
len1 = len;
}
else
{ {
*ptr0 = curMatch; UInt32 curMatch = pos - delta;
ptr0 = pair; // delta = pos - *pair;
curMatch = *ptr0; // delta = pos - pair[((UInt32)pb[len] - (UInt32)cur[len]) >> 31];
len0 = len; 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++; pos++;
_cyclicBufferPos++; _cyclicBufferPos++;
cur++; cur++;
{ {
UInt32 num = (UInt32)(distances - _distances); UInt32 num = (UInt32)(distances - _distances);
*_distances = num - 1; _distances[-1] = num;
_distances += num;
limit -= num;
} }
} }
while (limit > 0 && --size != 0); while (distances < limit && --size != 0);
*posRes = pos; *posRes = pos;
return limit; return distances;
} }
#endif #endif
static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances) static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
{ {
UInt32 numProcessed = 0; UInt32 numProcessed = 0;
UInt32 curPos = 2; UInt32 curPos = 2;
UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); UInt32 limit = kMtBtBlockSize - (p->matchMaxLen * 2); // * 2
distances[1] = p->hashNumAvail; distances[1] = p->hashNumAvail;
@ -369,8 +400,10 @@ static void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
#else #else
{ {
UInt32 posRes; UInt32 posRes;
curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue, curPos = (UInt32)(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); distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos,
distances + limit,
size, &posRes) - distances);
p->hashBufPos += posRes - pos; p->hashBufPos += posRes - pos;
cyclicBufferPos += posRes - pos; cyclicBufferPos += posRes - pos;
p->buffer += posRes - pos; p->buffer += posRes - pos;

@ -1,5 +1,5 @@
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms /* 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 #ifndef __LZ_FIND_MT_H
#define __LZ_FIND_MT_H #define __LZ_FIND_MT_H
@ -19,10 +19,10 @@ EXTERN_C_BEGIN
typedef struct _CMtSync typedef struct _CMtSync
{ {
Bool wasCreated; BoolInt wasCreated;
Bool needStart; BoolInt needStart;
Bool exit; BoolInt exit;
Bool stopWriting; BoolInt stopWriting;
CThread thread; CThread thread;
CAutoResetEvent canStart; CAutoResetEvent canStart;
@ -30,8 +30,8 @@ typedef struct _CMtSync
CAutoResetEvent wasStopped; CAutoResetEvent wasStopped;
CSemaphore freeSemaphore; CSemaphore freeSemaphore;
CSemaphore filledSemaphore; CSemaphore filledSemaphore;
Bool csWasInitialized; BoolInt csWasInitialized;
Bool csWasEntered; BoolInt csWasEntered;
CCriticalSection cs; CCriticalSection cs;
UInt32 numProcessedBlocks; UInt32 numProcessedBlocks;
} CMtSync; } CMtSync;

@ -1,5 +1,5 @@
/* Lzma2Dec.c -- LZMA2 Decoder /* Lzma2Dec.c -- LZMA2 Decoder
2018-02-19 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
/* #define SHOW_DEBUG_INFO */ /* #define SHOW_DEBUG_INFO */
@ -169,7 +169,7 @@ static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT s
p->processedPos += (UInt32)size; 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, SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
@ -232,7 +232,7 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
if (p->state == LZMA2_STATE_DATA) 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); LzmaDec_InitDicAndState(&p->decoder, initDic, False);
} }
@ -254,8 +254,8 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
if (p->state == LZMA2_STATE_DATA) if (p->state == LZMA2_STATE_DATA)
{ {
Bool initDic = (p->control >= 0xE0); BoolInt initDic = (p->control >= 0xE0);
Bool initState = (p->control >= 0xA0); BoolInt initState = (p->control >= 0xA0);
LzmaDec_InitDicAndState(&p->decoder, initDic, initState); LzmaDec_InitDicAndState(&p->decoder, initDic, initState);
p->state = LZMA2_STATE_DATA_CONT; p->state = LZMA2_STATE_DATA_CONT;
} }
@ -314,15 +314,15 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
while (p->state != LZMA2_STATE_ERROR) while (p->state != LZMA2_STATE_ERROR)
{ {
if (p->state == LZMA2_STATE_FINISHED) if (p->state == LZMA2_STATE_FINISHED)
return LZMA_STATUS_FINISHED_WITH_MARK; return (ELzma2ParseStatus)LZMA_STATUS_FINISHED_WITH_MARK;
if (outSize == 0 && !checkFinishBlock) if (outSize == 0 && !checkFinishBlock)
return LZMA_STATUS_NOT_FINISHED; return (ELzma2ParseStatus)LZMA_STATUS_NOT_FINISHED;
if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT) if (p->state != LZMA2_STATE_DATA && p->state != LZMA2_STATE_DATA_CONT)
{ {
if (*srcLen == inSize) if (*srcLen == inSize)
return LZMA_STATUS_NEEDS_MORE_INPUT; return (ELzma2ParseStatus)LZMA_STATUS_NEEDS_MORE_INPUT;
(*srcLen)++; (*srcLen)++;
p->state = Lzma2Dec_UpdateState(p, *src++); p->state = Lzma2Dec_UpdateState(p, *src++);
@ -344,7 +344,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
// checkFinishBlock is true. So we expect that block must be finished, // checkFinishBlock is true. So we expect that block must be finished,
// We can return LZMA_STATUS_NOT_SPECIFIED or LZMA_STATUS_NOT_FINISHED here // We can return LZMA_STATUS_NOT_SPECIFIED or LZMA_STATUS_NOT_FINISHED here
// break; // break;
return LZMA_STATUS_NOT_FINISHED; return (ELzma2ParseStatus)LZMA_STATUS_NOT_FINISHED;
} }
if (p->state == LZMA2_STATE_DATA) if (p->state == LZMA2_STATE_DATA)
@ -354,7 +354,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
} }
if (outSize == 0) if (outSize == 0)
return LZMA_STATUS_NOT_FINISHED; return (ELzma2ParseStatus)LZMA_STATUS_NOT_FINISHED;
{ {
SizeT inCur = inSize - *srcLen; SizeT inCur = inSize - *srcLen;
@ -362,7 +362,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
if (LZMA2_IS_UNCOMPRESSED_STATE(p)) if (LZMA2_IS_UNCOMPRESSED_STATE(p))
{ {
if (inCur == 0) if (inCur == 0)
return LZMA_STATUS_NEEDS_MORE_INPUT; return (ELzma2ParseStatus)LZMA_STATUS_NEEDS_MORE_INPUT;
if (inCur > p->unpackSize) if (inCur > p->unpackSize)
inCur = p->unpackSize; inCur = p->unpackSize;
if (inCur > outSize) if (inCur > outSize)
@ -381,7 +381,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
if (inCur == 0) if (inCur == 0)
{ {
if (p->packSize != 0) if (p->packSize != 0)
return LZMA_STATUS_NEEDS_MORE_INPUT; return (ELzma2ParseStatus)LZMA_STATUS_NEEDS_MORE_INPUT;
} }
else if (p->state == LZMA2_STATE_DATA) else if (p->state == LZMA2_STATE_DATA)
{ {
@ -418,7 +418,7 @@ ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,
} }
p->state = LZMA2_STATE_ERROR; p->state = LZMA2_STATE_ERROR;
return LZMA_STATUS_NOT_SPECIFIED; return (ELzma2ParseStatus)LZMA_STATUS_NOT_SPECIFIED;
} }

@ -1,5 +1,5 @@
/* Lzma2DecMt.c -- LZMA2 Decoder Multi-thread /* Lzma2DecMt.c -- LZMA2 Decoder Multi-thread
2018-03-02 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -94,13 +94,13 @@ typedef struct
ISeqOutStream *outStream; ISeqOutStream *outStream;
ICompressProgress *progress; ICompressProgress *progress;
Bool finishMode; BoolInt finishMode;
Bool outSize_Defined; BoolInt outSize_Defined;
UInt64 outSize; UInt64 outSize;
UInt64 outProcessed; UInt64 outProcessed;
UInt64 inProcessed; UInt64 inProcessed;
Bool readWasFinished; BoolInt readWasFinished;
SRes readRes; SRes readRes;
Byte *inBuf; Byte *inBuf;
@ -113,7 +113,7 @@ typedef struct
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
UInt64 outProcessed_Parse; UInt64 outProcessed_Parse;
Bool mtc_WasConstructed; BoolInt mtc_WasConstructed;
CMtDec mtc; CMtDec mtc;
CLzma2DecMtThread coders[MTDEC__THREADS_MAX]; CLzma2DecMtThread coders[MTDEC__THREADS_MAX];
#endif #endif
@ -265,7 +265,7 @@ static void Lzma2DecMt_MtCallback_Parse(void *obj, unsigned coderIndex, CMtDecCa
t->outPreSize = 0; t->outPreSize = 0;
// t->blockWasFinished = False; // t->blockWasFinished = False;
// t->finishedWithMark = False; // t->finishedWithMark = False;
t->parseStatus = LZMA_STATUS_NOT_SPECIFIED; t->parseStatus = (ELzma2ParseStatus)LZMA_STATUS_NOT_SPECIFIED;
t->state = MTDEC_PARSE_CONTINUE; t->state = MTDEC_PARSE_CONTINUE;
t->inCodeSize = 0; t->inCodeSize = 0;
@ -277,7 +277,7 @@ static void Lzma2DecMt_MtCallback_Parse(void *obj, unsigned coderIndex, CMtDecCa
{ {
ELzma2ParseStatus status; ELzma2ParseStatus status;
Bool overflow; BoolInt overflow;
UInt32 unpackRem = 0; UInt32 unpackRem = 0;
int checkFinishBlock = True; int checkFinishBlock = True;
@ -477,7 +477,7 @@ static SRes Lzma2DecMt_MtCallback_Code(void *pp, unsigned coderIndex,
{ {
ELzmaStatus status; ELzmaStatus status;
size_t srcProcessed = srcSize; size_t srcProcessed = srcSize;
Bool blockWasFinished = BoolInt blockWasFinished =
((int)t->parseStatus == LZMA_STATUS_FINISHED_WITH_MARK ((int)t->parseStatus == LZMA_STATUS_FINISHED_WITH_MARK
|| t->parseStatus == LZMA2_PARSE_STATUS_NEW_BLOCK); || 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) #define LZMA2DECMT_STREAM_WRITE_STEP (1 << 24)
static SRes Lzma2DecMt_MtCallback_Write(void *pp, unsigned coderIndex, static SRes Lzma2DecMt_MtCallback_Write(void *pp, unsigned coderIndex,
Bool needWriteToStream, BoolInt needWriteToStream,
const Byte *src, size_t srcSize, const Byte *src, size_t srcSize,
Bool *needContinue, Bool *canRecode) BoolInt *needContinue, BoolInt *canRecode)
{ {
CLzma2DecMt *me = (CLzma2DecMt *)pp; CLzma2DecMt *me = (CLzma2DecMt *)pp;
const CLzma2DecMtThread *t = &me->coders[coderIndex]; const CLzma2DecMtThread *t = &me->coders[coderIndex];
size_t size = t->outCodeSize; size_t size = t->outCodeSize;
const Byte *data = t->outBuf; const Byte *data = t->outBuf;
Bool needContinue2 = True; BoolInt needContinue2 = True;
PRF_STR_INT_2("Write", coderIndex, srcSize); 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 static SRes Lzma2Dec_Decode_ST(CLzma2DecMt *p
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
, Bool tMode , BoolInt tMode
#endif #endif
) )
{ {
@ -674,8 +674,8 @@ static SRes Lzma2Dec_Decode_ST(CLzma2DecMt *p
SRes res; SRes res;
SizeT outProcessed; SizeT outProcessed;
Bool outFinished; BoolInt outFinished;
Bool needStop; BoolInt needStop;
if (inPos == inLim) if (inPos == inLim)
{ {
@ -810,7 +810,7 @@ SRes Lzma2DecMt_Decode(CLzma2DecMtHandle pp,
{ {
CLzma2DecMt *p = (CLzma2DecMt *)pp; CLzma2DecMt *p = (CLzma2DecMt *)pp;
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
Bool tMode; BoolInt tMode;
#endif #endif
*inProcessed = 0; *inProcessed = 0;
@ -903,7 +903,7 @@ SRes Lzma2DecMt_Decode(CLzma2DecMtHandle pp,
vt.Write = Lzma2DecMt_MtCallback_Write; vt.Write = Lzma2DecMt_MtCallback_Write;
{ {
Bool needContinue = False; BoolInt needContinue = False;
SRes res = MtDec_Code(&p->mtc); SRes res = MtDec_Code(&p->mtc);

@ -1,5 +1,5 @@
/* Lzma2Enc.c -- LZMA2 Encoder /* Lzma2Enc.c -- LZMA2 Encoder
2018-04-27 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -115,7 +115,7 @@ SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, ISeqInStream *inStream, UInt32 k
ISzAllocPtr alloc, ISzAllocPtr allocBig); ISzAllocPtr alloc, ISzAllocPtr allocBig);
SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen,
UInt32 keepWindowSize, ISzAllocPtr alloc, ISzAllocPtr allocBig); 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); Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize);
const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp); const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp);
void LzmaEnc_Finish(CLzmaEncHandle pp); void LzmaEnc_Finish(CLzmaEncHandle pp);
@ -133,7 +133,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
size_t packSize = packSizeLimit; size_t packSize = packSizeLimit;
UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX; UInt32 unpackSize = LZMA2_UNPACK_SIZE_MAX;
unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0); unsigned lzHeaderSize = 5 + (p->needInitProp ? 1 : 0);
Bool useCopyBlock; BoolInt useCopyBlock;
SRes res; SRes res;
*packSizeRes = 0; *packSizeRes = 0;
@ -373,7 +373,7 @@ typedef struct
size_t outBufSize; /* size of allocated outBufs[i] */ size_t outBufSize; /* size of allocated outBufs[i] */
size_t outBufsDataSizes[MTCODER__BLOCKS_MAX]; size_t outBufsDataSizes[MTCODER__BLOCKS_MAX];
Bool mtCoder_WasConstructed; BoolInt mtCoder_WasConstructed;
CMtCoder mtCoder; CMtCoder mtCoder;
Byte *outBufs[MTCODER__BLOCKS_MAX]; Byte *outBufs[MTCODER__BLOCKS_MAX];

@ -1,5 +1,5 @@
/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder /* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
2016-05-16 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #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; size_t outSize2 = *destLen;
Byte *filteredStream; Byte *filteredStream;
Bool useFilter; BoolInt useFilter;
int mainResult = SZ_ERROR_OUTPUT_EOF; int mainResult = SZ_ERROR_OUTPUT_EOF;
CLzmaEncProps props; CLzmaEncProps props;
LzmaEncProps_Init(&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; size_t minSize = 0;
Bool bestIsFiltered = False; BoolInt bestIsFiltered = False;
/* passes for SZ_FILTER_AUTO: /* passes for SZ_FILTER_AUTO:
0 - BCJ + LZMA 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 outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;
size_t outPropsSize = 5; size_t outPropsSize = 5;
SRes curRes; SRes curRes;
Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1); BoolInt curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
if (curModeIsFiltered && !bestIsFiltered) if (curModeIsFiltered && !bestIsFiltered)
break; break;
if (useFilter && i == 0) if (useFilter && i == 0)

@ -1,13 +1,13 @@
/* LzmaDec.c -- LZMA Decoder /* LzmaDec.c -- LZMA Decoder
2018-02-28 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
#include <string.h>
/* #include "CpuArch.h" */ /* #include "CpuArch.h" */
#include "LzmaDec.h" #include "LzmaDec.h"
#include <string.h>
#define kNumTopBits 24 #define kNumTopBits 24
#define kTopValue ((UInt32)1 << kNumTopBits) #define kTopValue ((UInt32)1 << kNumTopBits)
@ -19,7 +19,7 @@
#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); } #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_0(p) range = bound; *(p) = (CLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (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) \ #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 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_0_CHECK range = bound;
#define UPDATE_1_CHECK range -= bound; code -= bound; #define UPDATE_1_CHECK range -= bound; code -= bound;
#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \ #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); curLen = ((rem < len) ? (unsigned)rem : len);
pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0); pos = dicPos - rep0 + (dicPos < rep0 ? dicBufSize : 0);
processedPos += curLen; processedPos += (UInt32)curLen;
len -= curLen; len -= curLen;
if (curLen <= dicBufSize - pos) 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; Byte *dest = dic + dicPos;
ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
const Byte *lim = dest + curLen; const Byte *lim = dest + curLen;
dicPos += curLen; dicPos += (SizeT)curLen;
do do
*(dest) = (Byte)*(dest + src); *(dest) = (Byte)*(dest + src);
while (++dest != lim); 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->buf = buf;
p->range = range; p->range = range;
p->code = code; p->code = code;
p->remainLen = len; p->remainLen = (UInt32)len;
p->dicPos = dicPos; p->dicPos = dicPos;
p->processedPos = processedPos; p->processedPos = processedPos;
p->reps[0] = rep0; p->reps[0] = rep0;
p->reps[1] = rep1; p->reps[1] = rep1;
p->reps[2] = rep2; p->reps[2] = rep2;
p->reps[3] = rep3; p->reps[3] = rep3;
p->state = state; p->state = (UInt32)state;
return SZ_OK; 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) if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
p->checkDicSize = p->prop.dicSize; p->checkDicSize = p->prop.dicSize;
p->processedPos += len; p->processedPos += (UInt32)len;
p->remainLen -= len; p->remainLen -= (UInt32)len;
while (len != 0) while (len != 0)
{ {
len--; 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->remainLen = kMatchSpecLenStart + 1;
p->tempBufSize = 0; p->tempBufSize = 0;
@ -979,10 +979,10 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
p->tempBufSize = rem; p->tempBufSize = rem;
if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) 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) if (dummyRes == DUMMY_ERROR)
{ {
(*srcLen) += lookAhead; (*srcLen) += (SizeT)lookAhead;
*status = LZMA_STATUS_NEEDS_MORE_INPUT; *status = LZMA_STATUS_NEEDS_MORE_INPUT;
return SZ_OK; 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 */ return SZ_ERROR_FAIL; /* some internal error */
lookAhead -= rem; lookAhead -= rem;
} }
(*srcLen) += lookAhead; (*srcLen) += (SizeT)lookAhead;
src += lookAhead; src += lookAhead;
inSize -= lookAhead; inSize -= (SizeT)lookAhead;
p->tempBufSize = 0; p->tempBufSize = 0;
} }
} }

File diff suppressed because it is too large Load Diff

@ -1,5 +1,5 @@
/* MtCoder.c -- Multi-thread Coder /* MtCoder.c -- Multi-thread Coder
2018-02-21 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -119,7 +119,7 @@ static SRes ThreadFunc2(CMtCoderThread *t)
unsigned bi; unsigned bi;
SRes res; SRes res;
SRes res2; SRes res2;
Bool finished; BoolInt finished;
unsigned bufIndex; unsigned bufIndex;
size_t size; size_t size;
const Byte *inData; const Byte *inData;
@ -294,7 +294,7 @@ static SRes ThreadFunc2(CMtCoderThread *t)
if (++wi >= mtc->numBlocksMax) if (++wi >= mtc->numBlocksMax)
wi = 0; wi = 0;
{ {
Bool isReady; BoolInt isReady;
CriticalSection_Enter(&mtc->cs); CriticalSection_Enter(&mtc->cs);
@ -547,7 +547,7 @@ SRes MtCoder_Code(CMtCoder *p)
{ {
const CMtCoderBlock *block = &p->blocks[bi]; const CMtCoderBlock *block = &p->blocks[bi];
unsigned bufIndex = block->bufIndex; unsigned bufIndex = block->bufIndex;
Bool finished = block->finished; BoolInt finished = block->finished;
if (res == SZ_OK && block->res != SZ_OK) if (res == SZ_OK && block->res != SZ_OK)
res = block->res; res = block->res;

@ -1,5 +1,5 @@
/* MtCoder.h -- Multi-thread Coder /* MtCoder.h -- Multi-thread Coder
2018-02-21 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#ifndef __MT_CODER_H #ifndef __MT_CODER_H
#define __MT_CODER_H #define __MT_CODER_H
@ -67,7 +67,7 @@ typedef struct
{ {
SRes res; SRes res;
unsigned bufIndex; unsigned bufIndex;
Bool finished; BoolInt finished;
} CMtCoderBlock; } CMtCoderBlock;
@ -97,7 +97,7 @@ typedef struct _CMtCoder
CAutoResetEvent readEvent; CAutoResetEvent readEvent;
CSemaphore blocksSemaphore; CSemaphore blocksSemaphore;
Bool stopReading; BoolInt stopReading;
SRes readRes; SRes readRes;
#ifdef MTCODER__USE_WRITE_THREAD #ifdef MTCODER__USE_WRITE_THREAD

@ -1,5 +1,5 @@
/* MtDec.c -- Multi-thread Decoder /* MtDec.c -- Multi-thread Decoder
2018-03-02 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -88,12 +88,13 @@ static WRes ArEvent_OptCreate_And_Reset(CEvent *p)
} }
struct __CMtDecBufLink
typedef struct
{ {
void *next; struct __CMtDecBufLink *next;
void *pad[3]; void *pad[3];
} CMtDecBufLink; };
typedef struct __CMtDecBufLink CMtDecBufLink;
#define MTDEC__LINK_DATA_OFFSET sizeof(CMtDecBufLink) #define MTDEC__LINK_DATA_OFFSET sizeof(CMtDecBufLink)
#define MTDEC__DATA_PTR_FROM_LINK(link) ((Byte *)(link) + MTDEC__LINK_DATA_OFFSET) #define MTDEC__DATA_PTR_FROM_LINK(link) ((Byte *)(link) + MTDEC__LINK_DATA_OFFSET)
@ -197,7 +198,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; SRes res;
CriticalSection_Enter(&p->mtProgress.cs); CriticalSection_Enter(&p->mtProgress.cs);
@ -207,7 +208,7 @@ static SRes MtDec_GetError_Spec(CMtDec *p, UInt64 interruptIndex, Bool *wasInter
return res; 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; SRes res;
CriticalSection_Enter(&p->mtProgress.cs); CriticalSection_Enter(&p->mtProgress.cs);
@ -271,9 +272,9 @@ static WRes ThreadFunc2(CMtDecThread *t)
for (;;) for (;;)
{ {
SRes res, codeRes; SRes res, codeRes;
Bool wasInterrupted, isAllocError, overflow, finish; BoolInt wasInterrupted, isAllocError, overflow, finish;
SRes threadingErrorSRes; SRes threadingErrorSRes;
Bool needCode, needWrite, needContinue; BoolInt needCode, needWrite, needContinue;
size_t inDataSize_Start; size_t inDataSize_Start;
UInt64 inDataSize; UInt64 inDataSize;
@ -289,7 +290,7 @@ static WRes ThreadFunc2(CMtDecThread *t)
Byte *afterEndData = NULL; Byte *afterEndData = NULL;
size_t afterEndData_Size = 0; size_t afterEndData_Size = 0;
Bool canCreateNewThread = False; BoolInt canCreateNewThread = False;
// CMtDecCallbackInfo parse; // CMtDecCallbackInfo parse;
CMtDecThread *nextThread; CMtDecThread *nextThread;
@ -629,7 +630,7 @@ static WRes ThreadFunc2(CMtDecThread *t)
if (res == SZ_OK && needCode && codeRes == SZ_OK) if (res == SZ_OK && needCode && codeRes == SZ_OK)
{ {
Bool isStartBlock = True; BoolInt isStartBlock = True;
CMtDecBufLink *link = (CMtDecBufLink *)t->inBuf; CMtDecBufLink *link = (CMtDecBufLink *)t->inBuf;
for (;;) for (;;)
@ -691,9 +692,9 @@ static WRes ThreadFunc2(CMtDecThread *t)
RINOK_THREAD(Event_Wait(&t->canWrite)); RINOK_THREAD(Event_Wait(&t->canWrite));
{ {
Bool isErrorMode = False; BoolInt isErrorMode = False;
Bool canRecode = True; BoolInt canRecode = True;
Bool needWriteToStream = needWrite; BoolInt needWriteToStream = needWrite;
if (p->exitThread) return 0; // it's never executed in normal cases if (p->exitThread) return 0; // it's never executed in normal cases

@ -1,5 +1,5 @@
/* MtDec.h -- Multi-thread Decoder /* MtDec.h -- Multi-thread Decoder
2018-03-02 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#ifndef __MT_DEC_H #ifndef __MT_DEC_H
#define __MT_DEC_H #define __MT_DEC_H
@ -76,7 +76,7 @@ typedef struct
// out // out
EMtDecParseState state; EMtDecParseState state;
Bool canCreateNewThread; BoolInt canCreateNewThread;
UInt64 outPos; // check it (size_t) UInt64 outPos; // check it (size_t)
} CMtDecCallbackInfo; } CMtDecCallbackInfo;
@ -107,11 +107,11 @@ typedef struct
if (*canRecode), we didn't flush current block data, so we still can decode current block later. if (*canRecode), we didn't flush current block data, so we still can decode current block later.
*/ */
SRes (*Write)(void *p, unsigned coderIndex, SRes (*Write)(void *p, unsigned coderIndex,
Bool needWriteToStream, BoolInt needWriteToStream,
const Byte *src, size_t srcSize, const Byte *src, size_t srcSize,
// int srcFinished, // int srcFinished,
Bool *needContinue, BoolInt *needContinue,
Bool *canRecode); BoolInt *canRecode);
} IMtDecCallback; } IMtDecCallback;
@ -140,22 +140,22 @@ typedef struct _CMtDec
size_t allocatedBufsSize; size_t allocatedBufsSize;
Bool exitThread; BoolInt exitThread;
WRes exitThreadWRes; WRes exitThreadWRes;
UInt64 blockIndex; UInt64 blockIndex;
Bool isAllocError; BoolInt isAllocError;
Bool overflow; BoolInt overflow;
SRes threadingErrorSRes; SRes threadingErrorSRes;
Bool needContinue; BoolInt needContinue;
// CAutoResetEvent finishedEvent; // CAutoResetEvent finishedEvent;
SRes readRes; SRes readRes;
SRes codeRes; SRes codeRes;
Bool wasInterrupted; BoolInt wasInterrupted;
unsigned numStartedThreads_Limit; unsigned numStartedThreads_Limit;
unsigned numStartedThreads; unsigned numStartedThreads;
@ -164,14 +164,14 @@ typedef struct _CMtDec
size_t crossStart; size_t crossStart;
size_t crossEnd; size_t crossEnd;
UInt64 readProcessed; UInt64 readProcessed;
Bool readWasFinished; BoolInt readWasFinished;
UInt64 inProcessed; UInt64 inProcessed;
unsigned filledThreadStart; unsigned filledThreadStart;
unsigned numFilledThreads; unsigned numFilledThreads;
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
Bool needInterrupt; BoolInt needInterrupt;
UInt64 interruptIndex; UInt64 interruptIndex;
CMtProgress mtProgress; CMtProgress mtProgress;
CMtDecThread threads[MTDEC__THREADS_MAX]; CMtDecThread threads[MTDEC__THREADS_MAX];

@ -1,5 +1,5 @@
/* Ppmd7.c -- PPMdH codec /* 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 */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -95,7 +95,7 @@ void Ppmd7_Free(CPpmd7 *p, ISzAllocPtr alloc)
p->Base = 0; 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) if (!p->Base || p->Size != size)
{ {
@ -342,7 +342,7 @@ void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)
p->DummySee.Count = 64; /* unused */ p->DummySee.Count = 64; /* unused */
} }
static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) static CTX_PTR CreateSuccessors(CPpmd7 *p, BoolInt skip)
{ {
CPpmd_State upState; CPpmd_State upState;
CTX_PTR c = p->MinContext; CTX_PTR c = p->MinContext;

@ -1,5 +1,5 @@
/* Ppmd7.h -- PPMdH compression codec /* 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 is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
/* This code supports virtual RangeDecoder and includes the implementation /* This code supports virtual RangeDecoder and includes the implementation
@ -60,7 +60,7 @@ typedef struct
} CPpmd7; } CPpmd7;
void Ppmd7_Construct(CPpmd7 *p); 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_Free(CPpmd7 *p, ISzAllocPtr alloc);
void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder); void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder);
#define Ppmd7_WasAllocated(p) ((p)->Base != NULL) #define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
@ -115,7 +115,7 @@ typedef struct
} CPpmd7z_RangeDec; } CPpmd7z_RangeDec;
void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p); 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) #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc); int Ppmd7_DecodeSymbol(CPpmd7 *p, const IPpmd7_RangeDec *rc);

@ -1,5 +1,5 @@
/* Ppmd7Dec.c -- PPMdH Decoder /* 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 */ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -8,7 +8,7 @@ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#define kTopValue (1 << 24) #define kTopValue (1 << 24)
Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) BoolInt Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p)
{ {
unsigned i; unsigned i;
p->Code = 0; p->Code = 0;

@ -1,5 +1,5 @@
/* 7zMain.c - Test application for 7z Decoder /* 7zMain.c - Test application for 7z Decoder
2018-04-19 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -176,7 +176,7 @@ static SRes Utf16_To_Char(CBuf *buf, const UInt16 *s
char defaultChar = '_'; char defaultChar = '_';
BOOL defUsed; BOOL defUsed;
unsigned numChars = 0; unsigned numChars = 0;
numChars = WideCharToMultiByte(codePage, 0, s, len, (char *)buf->data, size, &defaultChar, &defUsed); numChars = WideCharToMultiByte(codePage, 0, (LPCWSTR)s, len, (char *)buf->data, size, &defaultChar, &defUsed);
if (numChars == 0 || numChars >= size) if (numChars == 0 || numChars >= size)
return SZ_ERROR_FAIL; return SZ_ERROR_FAIL;
buf->data[numChars] = 0; buf->data[numChars] = 0;
@ -202,7 +202,7 @@ static WRes MyCreateDir(const UInt16 *name)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
return CreateDirectoryW(name, NULL) ? 0 : GetLastError(); return CreateDirectoryW((LPCWSTR)name, NULL) ? 0 : GetLastError();
#else #else
@ -227,7 +227,7 @@ static WRes MyCreateDir(const UInt16 *name)
static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name) static WRes OutFile_OpenUtf16(CSzFile *p, const UInt16 *name)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
return OutFile_OpenW(p, name); return OutFile_OpenW(p, (LPCWSTR)name);
#else #else
CBuf buf; CBuf buf;
WRes res; WRes res;
@ -354,7 +354,7 @@ static void PrintError(char *s)
PrintLF(); PrintLF();
} }
static void GetAttribString(UInt32 wa, Bool isDir, char *s) static void GetAttribString(UInt32 wa, BoolInt isDir, char *s)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.'); s[0] = (char)(((wa & FILE_ATTRIBUTE_DIRECTORY) != 0 || isDir) ? 'D' : '.');
@ -430,7 +430,7 @@ int MY_CDECL main(int numargs, char *args[])
res = SZ_OK; res = SZ_OK;
{ {
lookStream.buf = ISzAlloc_Alloc(&allocImp, kInputBufSize); lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize);
if (!lookStream.buf) if (!lookStream.buf)
res = SZ_ERROR_MEM; res = SZ_ERROR_MEM;
else else
@ -647,7 +647,7 @@ int MY_CDECL main(int numargs, char *args[])
We remove posix bits, if we detect posix mode field */ We remove posix bits, if we detect posix mode field */
if ((attrib & 0xF0000000) != 0) if ((attrib & 0xF0000000) != 0)
attrib &= 0x7FFF; attrib &= 0x7FFF;
SetFileAttributesW(destPath, attrib); SetFileAttributesW((LPCWSTR)destPath, attrib);
} }
#endif #endif
} }

@ -1,5 +1,5 @@
/* LzmaUtil.c -- Test application for LZMA compression /* LzmaUtil.c -- Test application for LZMA compression
2017-04-27 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#include "../../Precomp.h" #include "../../Precomp.h"
@ -177,7 +177,7 @@ static int main2(int numArgs, const char *args[], char *rs)
char c; char c;
int res; int res;
int encodeMode; int encodeMode;
Bool useOutFile = False; BoolInt useOutFile = False;
FileSeqInStream_CreateVTable(&inStream); FileSeqInStream_CreateVTable(&inStream);
File_Construct(&inStream.file); File_Construct(&inStream.file);

@ -1,5 +1,5 @@
/* SfxSetup.c - 7z SFX Setup /* SfxSetup.c - 7z SFX Setup
2017-04-04 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -127,7 +127,7 @@ static WRes MyCreateDir(const WCHAR *name)
#define kSignatureSearchLimit (1 << 22) #define kSignatureSearchLimit (1 << 22)
static Bool FindSignature(CSzFile *stream, UInt64 *resPos) static BoolInt FindSignature(CSzFile *stream, UInt64 *resPos)
{ {
Byte buf[kBufferSize]; Byte buf[kBufferSize];
size_t numPrevBytes = 0; 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; WIN32_FIND_DATAW fd;
HANDLE handle; HANDLE handle;
@ -254,7 +254,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
DWORD winRes; DWORD winRes;
const wchar_t *cmdLineParams; const wchar_t *cmdLineParams;
const char *errorMessage = NULL; const char *errorMessage = NULL;
Bool useShellExecute = True; BoolInt useShellExecute = True;
DWORD exitCode = 0; DWORD exitCode = 0;
LoadSecurityDlls(); LoadSecurityDlls();
@ -287,7 +287,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
cmdLineParams = GetCommandLineW(); cmdLineParams = GetCommandLineW();
#ifndef UNDER_CE #ifndef UNDER_CE
{ {
Bool quoteMode = False; BoolInt quoteMode = False;
for (;; cmdLineParams++) for (;; cmdLineParams++)
{ {
wchar_t c = *cmdLineParams; wchar_t c = *cmdLineParams;
@ -379,7 +379,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
if (res == SZ_OK) if (res == SZ_OK)
{ {
lookStream.buf = ISzAlloc_Alloc(&allocImp, kInputBufSize); lookStream.buf = (Byte *)ISzAlloc_Alloc(&allocImp, kInputBufSize);
if (!lookStream.buf) if (!lookStream.buf)
res = SZ_ERROR_MEM; res = SZ_ERROR_MEM;
else else
@ -420,7 +420,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
temp = path + pathLen; temp = path + pathLen;
SzArEx_GetFileNameUtf16(&db, i, temp); SzArEx_GetFileNameUtf16(&db, i, (UInt16 *)temp);
{ {
res = SzArEx_Extract(&db, &lookStream.vt, i, res = SzArEx_Extract(&db, &lookStream.vt, i,
&blockIndex, &outBuffer, &outBufferSize, &blockIndex, &outBuffer, &outBufferSize,
@ -527,7 +527,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
{ {
WCHAR *temp = path + pathLen; WCHAR *temp = path + pathLen;
UInt32 j; UInt32 j;
SzArEx_GetFileNameUtf16(&db, executeFileIndex, temp); SzArEx_GetFileNameUtf16(&db, executeFileIndex, (UInt16 *)temp);
for (j = 0; temp[j] != 0; j++) for (j = 0; temp[j] != 0; j++)
if (temp[j] == '/') if (temp[j] == '/')
temp[j] = CHAR_PATH_SEPARATOR; temp[j] = CHAR_PATH_SEPARATOR;

@ -1,5 +1,5 @@
/* Xz.h - Xz interface /* Xz.h - Xz interface
2018-02-28 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#ifndef __XZ_H #ifndef __XZ_H
#define __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) #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_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 ---------- */ /* ---------- xz stream ---------- */
@ -186,10 +186,10 @@ typedef struct
Byte *outBuf; Byte *outBuf;
size_t outBufSize; size_t outBufSize;
size_t outWritten; // is equal to lzmaDecoder.dicPos (in outBuf mode) size_t outWritten; // is equal to lzmaDecoder.dicPos (in outBuf mode)
Bool wasFinished; BoolInt wasFinished;
SRes res; SRes res;
ECoderStatus status; ECoderStatus status;
// Bool SingleBufMode; // BoolInt SingleBufMode;
int finished[MIXCODER_NUM_FILTERS_MAX - 1]; int finished[MIXCODER_NUM_FILTERS_MAX - 1];
size_t pos[MIXCODER_NUM_FILTERS_MAX - 1]; size_t pos[MIXCODER_NUM_FILTERS_MAX - 1];
@ -241,9 +241,9 @@ typedef struct
CXzCheck check; CXzCheck check;
CSha256 sha; CSha256 sha;
Bool parseMode; BoolInt parseMode;
Bool headerParsedOk; BoolInt headerParsedOk;
Bool decodeToStreamSignature; BoolInt decodeToStreamSignature;
unsigned decodeOnlyOneBlock; unsigned decodeOnlyOneBlock;
Byte *outBuf; Byte *outBuf;
@ -335,7 +335,7 @@ SRes XzUnpacker_CodeFull(CXzUnpacker *p, Byte *dest, SizeT *destLen,
const Byte *src, SizeT *srcLen, const Byte *src, SizeT *srcLen,
ECoderFinishMode finishMode, ECoderStatus *status); ECoderFinishMode finishMode, ECoderStatus *status);
Bool XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p); BoolInt XzUnpacker_IsStreamWasFinished(const CXzUnpacker *p);
/* /*
XzUnpacker_GetExtraSize() returns then number of uncofirmed bytes, XzUnpacker_GetExtraSize() returns then number of uncofirmed bytes,
@ -365,7 +365,7 @@ UInt64 XzUnpacker_GetExtraSize(const CXzUnpacker *p);
*/ */
void XzUnpacker_PrepareToRandomBlockDecoding(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)) #define XzUnpacker_GetPackSizeForIndex(p) ((p)->packSize + (p)->blockHeaderSize + XzFlags_GetCheckSize((p)->streamFlags))
@ -378,7 +378,7 @@ typedef struct
{ {
size_t inBufSize_ST; size_t inBufSize_ST;
size_t outStep_ST; size_t outStep_ST;
Bool ignoreErrors; BoolInt ignoreErrors;
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
unsigned numThreads; unsigned numThreads;

@ -1,5 +1,5 @@
/* XzDec.c -- Xz Decode /* XzDec.c -- Xz Decode
2018-04-24 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -245,7 +245,7 @@ SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAllocP
CBraState *decoder; CBraState *decoder;
if (id < XZ_ID_Delta || id > XZ_ID_SPARC) if (id < XZ_ID_Delta || id > XZ_ID_SPARC)
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
decoder = p->p; decoder = (CBraState *)p->p;
if (!decoder) if (!decoder)
{ {
decoder = (CBraState *)ISzAlloc_Alloc(alloc, sizeof(CBraState)); decoder = (CBraState *)ISzAlloc_Alloc(alloc, sizeof(CBraState));
@ -341,7 +341,7 @@ static SRes SbState_SetFromMethod(IStateCoder *p, ISzAllocPtr alloc)
typedef struct typedef struct
{ {
CLzma2Dec decoder; CLzma2Dec decoder;
Bool outBufMode; BoolInt outBufMode;
} CLzma2Dec_Spec; } CLzma2Dec_Spec;
@ -400,7 +400,7 @@ static SRes Lzma2State_Code2(void *pp, Byte *dest, SizeT *destLen, const Byte *s
res = Lzma2Dec_DecodeToBuf(&spec->decoder, dest, destLen, src, srcLen, (ELzmaFinishMode)finishMode, &status2); res = Lzma2Dec_DecodeToBuf(&spec->decoder, dest, destLen, src, srcLen, (ELzmaFinishMode)finishMode, &status2);
// *wasFinished = (status2 == LZMA_STATUS_FINISHED_WITH_MARK); // *wasFinished = (status2 == LZMA_STATUS_FINISHED_WITH_MARK);
// ECoderStatus values are identical to ELzmaStatus values of LZMA2 decoder // ECoderStatus values are identical to ELzmaStatus values of LZMA2 decoder
*status = status2; *status = (ECoderStatus)status2;
return res; return res;
} }
@ -637,8 +637,8 @@ static SRes MixCoder_Code(CMixCoder *p,
for (;;) for (;;)
{ {
Bool processed = False; BoolInt processed = False;
Bool allFinished = True; BoolInt allFinished = True;
SRes resMain = SZ_OK; SRes resMain = SZ_OK;
unsigned i; unsigned i;
@ -761,7 +761,7 @@ SRes Xz_ParseHeader(CXzStreamFlags *p, const Byte *buf)
return XzFlags_IsSupported(*p) ? SZ_OK : SZ_ERROR_UNSUPPORTED; 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) return indexSize == (((UInt64)GetUi32(buf + 4) + 1) << 2)
&& GetUi32(buf) == CrcCalc(buf + 4, 6) && 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; } 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 numFilters = XzBlock_GetNumFilters(p) - 1;
unsigned i; 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) static SRes XzDecMix_Init(CMixCoder *p, const CXzBlock *block, Byte *outBuf, size_t outBufSize)
{ {
unsigned i; unsigned i;
Bool needReInit = True; BoolInt needReInit = True;
unsigned numFilters = XzBlock_GetNumFilters(block); unsigned numFilters = XzBlock_GetNumFilters(block);
if (numFilters == p->numCoders && ((p->outBuf && outBuf) || (!p->outBuf && !outBuf))) 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; SRes res;
ECoderFinishMode finishMode2 = finishMode; ECoderFinishMode finishMode2 = finishMode;
Bool srcFinished2 = srcFinished; BoolInt srcFinished2 = srcFinished;
Bool destFinish = False; BoolInt destFinish = False;
if (p->block.packSize != (UInt64)(Int64)-1) 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); 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); return (p->state == XZ_STATE_STREAM_PADDING) && (((UInt32)p->padSize & 3) == 0);
} }
@ -1423,18 +1423,18 @@ typedef struct
size_t outCodeSize; size_t outCodeSize;
ECoderStatus status; ECoderStatus status;
SRes codeRes; SRes codeRes;
Bool skipMode; BoolInt skipMode;
// Bool finishedWithMark; // BoolInt finishedWithMark;
EMtDecParseState parseState; EMtDecParseState parseState;
Bool parsing_Truncated; BoolInt parsing_Truncated;
Bool atBlockHeader; BoolInt atBlockHeader;
CXzStreamFlags streamFlags; CXzStreamFlags streamFlags;
// UInt64 numFinishedStreams // UInt64 numFinishedStreams
UInt64 numStreams; UInt64 numStreams;
UInt64 numTotalBlocks; UInt64 numTotalBlocks;
UInt64 numBlocks; UInt64 numBlocks;
Bool dec_created; BoolInt dec_created;
CXzUnpacker dec; CXzUnpacker dec;
Byte mtPad[1 << 7]; Byte mtPad[1 << 7];
@ -1458,14 +1458,14 @@ typedef struct
ICompressProgress *progress; ICompressProgress *progress;
// CXzStatInfo *stat; // CXzStatInfo *stat;
Bool finishMode; BoolInt finishMode;
Bool outSize_Defined; BoolInt outSize_Defined;
UInt64 outSize; UInt64 outSize;
UInt64 outProcessed; UInt64 outProcessed;
UInt64 inProcessed; UInt64 inProcessed;
UInt64 readProcessed; UInt64 readProcessed;
Bool readWasFinished; BoolInt readWasFinished;
SRes readRes; SRes readRes;
SRes writeRes; SRes writeRes;
@ -1473,14 +1473,14 @@ typedef struct
size_t outBufSize; size_t outBufSize;
Byte *inBuf; Byte *inBuf;
size_t inBufSize; size_t inBufSize;
Bool dec_created;
CXzUnpacker dec; CXzUnpacker dec;
ECoderStatus status; ECoderStatus status;
SRes codeRes; SRes codeRes;
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
Bool mainDecoderWasCalled; BoolInt mainDecoderWasCalled;
// int statErrorDefined; // int statErrorDefined;
int finishedDecoderIndex; int finishedDecoderIndex;
@ -1494,12 +1494,12 @@ typedef struct
// UInt64 numBadBlocks; // UInt64 numBadBlocks;
SRes mainErrorCode; SRes mainErrorCode;
Bool isBlockHeaderState_Parse; BoolInt isBlockHeaderState_Parse;
Bool isBlockHeaderState_Write; BoolInt isBlockHeaderState_Write;
UInt64 outProcessed_Parse; UInt64 outProcessed_Parse;
Bool parsing_Truncated; BoolInt parsing_Truncated;
Bool mtc_WasConstructed; BoolInt mtc_WasConstructed;
CMtDec mtc; CMtDec mtc;
CXzDecMtThread coders[MTDEC__THREADS_MAX]; CXzDecMtThread coders[MTDEC__THREADS_MAX];
#endif #endif
@ -1525,7 +1525,8 @@ CXzDecMtHandle XzDecMt_Create(ISzAllocPtr alloc, ISzAllocPtr allocMid)
p->outBufSize = 0; p->outBufSize = 0;
p->inBuf = NULL; p->inBuf = NULL;
p->inBufSize = 0; p->inBufSize = 0;
p->dec_created = False;
XzUnpacker_Construct(&p->dec, &p->alignOffsetAlloc.vt);
p->unpackBlockMaxSize = 0; p->unpackBlockMaxSize = 0;
@ -1573,11 +1574,7 @@ static void XzDecMt_FreeOutBufs(CXzDecMt *p)
static void XzDecMt_FreeSt(CXzDecMt *p) static void XzDecMt_FreeSt(CXzDecMt *p)
{ {
if (p->dec_created) XzUnpacker_Free(&p->dec);
{
XzUnpacker_Free(&p->dec);
p->dec_created = False;
}
if (p->outBuf) if (p->outBuf)
{ {
@ -1968,11 +1965,11 @@ static SRes XzDecMt_Callback_Code(void *pp, unsigned coderIndex,
#define XZDECMT_STREAM_WRITE_STEP (1 << 24) #define XZDECMT_STREAM_WRITE_STEP (1 << 24)
static SRes XzDecMt_Callback_Write(void *pp, unsigned coderIndex, static SRes XzDecMt_Callback_Write(void *pp, unsigned coderIndex,
Bool needWriteToStream, BoolInt needWriteToStream,
const Byte *src, size_t srcSize, const Byte *src, size_t srcSize,
// int srcFinished, // int srcFinished,
Bool *needContinue, BoolInt *needContinue,
Bool *canRecode) BoolInt *canRecode)
{ {
CXzDecMt *me = (CXzDecMt *)pp; CXzDecMt *me = (CXzDecMt *)pp;
const CXzDecMtThread *coder = &me->coders[coderIndex]; const CXzDecMtThread *coder = &me->coders[coderIndex];
@ -2302,7 +2299,7 @@ void XzStatInfo_Clear(CXzStatInfo *p)
static SRes XzDecMt_Decode_ST(CXzDecMt *p static SRes XzDecMt_Decode_ST(CXzDecMt *p
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
, Bool tMode , BoolInt tMode
#endif #endif
, CXzStatInfo *stat) , CXzStatInfo *stat)
{ {
@ -2358,7 +2355,7 @@ static SRes XzDecMt_Decode_ST(CXzDecMt *p
for (;;) for (;;)
{ {
SizeT outSize; SizeT outSize;
Bool finished; BoolInt finished;
ECoderFinishMode finishMode; ECoderFinishMode finishMode;
SizeT inProcessed; SizeT inProcessed;
ECoderStatus status; ECoderStatus status;
@ -2466,7 +2463,7 @@ static SRes XzStatInfo_SetStat(const CXzUnpacker *dec,
int finishMode, int finishMode,
UInt64 readProcessed, UInt64 inProcessed, UInt64 readProcessed, UInt64 inProcessed,
SRes res, ECoderStatus status, SRes res, ECoderStatus status,
Bool decodingTruncated, BoolInt decodingTruncated,
CXzStatInfo *stat) CXzStatInfo *stat)
{ {
UInt64 extraSize; UInt64 extraSize;
@ -2531,7 +2528,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
{ {
CXzDecMt *p = (CXzDecMt *)pp; CXzDecMt *p = (CXzDecMt *)pp;
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
Bool tMode; BoolInt tMode;
#endif #endif
XzStatInfo_Clear(stat); XzStatInfo_Clear(stat);
@ -2564,13 +2561,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
p->codeRes = 0; p->codeRes = 0;
p->status = CODER_STATUS_NOT_SPECIFIED; 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); XzUnpacker_Init(&p->dec);
*isMT = False; *isMT = False;
@ -2600,6 +2591,8 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
{ {
IMtDecCallback vt; IMtDecCallback vt;
// we just free ST buffers here
// but we still keep state variables, that was set in XzUnpacker_Init()
XzDecMt_FreeSt(p); XzDecMt_FreeSt(p);
p->outProcessed_Parse = 0; p->outProcessed_Parse = 0;
@ -2636,7 +2629,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
vt.Write = XzDecMt_Callback_Write; vt.Write = XzDecMt_Callback_Write;
{ {
Bool needContinue; BoolInt needContinue;
SRes res = MtDec_Code(&p->mtc); SRes res = MtDec_Code(&p->mtc);
@ -2665,7 +2658,7 @@ SRes XzDecMt_Decode(CXzDecMtHandle pp,
if (!needContinue) if (!needContinue)
{ {
SRes codeRes; SRes codeRes;
Bool truncated = False; BoolInt truncated = False;
ECoderStatus status; ECoderStatus status;
CXzUnpacker *dec; CXzUnpacker *dec;

@ -1,5 +1,5 @@
/* XzEnc.c -- Xz Encode /* XzEnc.c -- Xz Encode
2018-04-28 : Igor Pavlov : Public domain */ 2019-02-02 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -366,7 +366,7 @@ static SRes SeqInFilter_Read(const ISeqInStream *pp, void *data, size_t *size)
SRes res; SRes res;
*size = sizeOriginal; *size = sizeOriginal;
res = p->StateCoder.Code2(p->StateCoder.p, res = p->StateCoder.Code2(p->StateCoder.p,
data, size, (Byte *)data, size,
p->buf + p->curPos, &srcLen, p->buf + p->curPos, &srcLen,
p->srcWasFinished, CODER_FINISH_ANY, p->srcWasFinished, CODER_FINISH_ANY,
&status); &status);
@ -814,7 +814,7 @@ static SRes Xz_CompressBlock(
SRes res; SRes res;
Byte *outBuf = NULL; Byte *outBuf = NULL;
size_t outSize = 0; size_t outSize = 0;
Bool useStream = (fp || inStream); BoolInt useStream = (fp || inStream);
// useStream = True; // useStream = True;
if (!useStream) if (!useStream)
@ -940,7 +940,7 @@ typedef struct
#ifndef _7ZIP_ST #ifndef _7ZIP_ST
unsigned checkType; unsigned checkType;
ISeqOutStream *outStream; ISeqOutStream *outStream;
Bool mtCoder_WasConstructed; BoolInt mtCoder_WasConstructed;
CMtCoder mtCoder; CMtCoder mtCoder;
CXzEncBlockInfo EncBlocks[MTCODER__BLOCKS_MAX]; CXzEncBlockInfo EncBlocks[MTCODER__BLOCKS_MAX];
#endif #endif

@ -1,5 +1,5 @@
/* XzIn.c - Xz input /* XzIn.c - Xz input
2018-02-02 : Igor Pavlov : Public domain */ 2018-07-04 : Igor Pavlov : Public domain */
#include "Precomp.h" #include "Precomp.h"
@ -28,7 +28,7 @@ SRes Xz_ReadHeader(CXzStreamFlags *p, ISeqInStream *inStream)
{ unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \ { unsigned s = Xz_ReadVarInt(buf + pos, size - pos, res); \
if (s == 0) return SZ_ERROR_ARCHIVE; pos += s; } 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]; Byte header[XZ_BLOCK_HEADER_SIZE_MAX];
unsigned headerSize; unsigned headerSize;

Loading…
Cancel
Save