cbfstool/lzma: Use stdint and stdbool types

This is the first patch on a long road to refactor and fix the lzma
code in cbfstool. I want to submit it in small atomic patches, so that
any potential errors are easy to spot before it's too late.

Change-Id: Ib557f8c83f49f18488639f38bf98d3ce849e61af
Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
Reviewed-on: http://review.coreboot.org/4834
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Alexandru Gagniuc 2014-01-26 22:55:01 -06:00
parent aa2f739ae8
commit 91e9f27973
9 changed files with 580 additions and 620 deletions

View File

@ -7,10 +7,10 @@
#include "LzHash.h" #include "LzHash.h"
#define kEmptyHashValue 0 #define kEmptyHashValue 0
#define kMaxValForNormalize ((UInt32)0xFFFFFFFF) #define kMaxValForNormalize ((uint32_t)0xFFFFFFFF)
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */ #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
#define kNormalizeMask (~(kNormalizeStepMin - 1)) #define kNormalizeMask (~(kNormalizeStepMin - 1))
#define kMaxHistorySize ((UInt32)3 << 30) #define kMaxHistorySize ((uint32_t)3 << 30)
#define kStartMaxLen 3 #define kStartMaxLen 3
@ -25,9 +25,9 @@ static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */ /* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc) static int LzInWindow_Create(CMatchFinder *p, uint32_t keepSizeReserv, ISzAlloc *alloc)
{ {
UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; uint32_t blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
if (p->directInput) if (p->directInput)
{ {
p->blockSize = blockSize; p->blockSize = blockSize;
@ -37,17 +37,17 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a
{ {
LzInWindow_Free(p, alloc); LzInWindow_Free(p, alloc);
p->blockSize = blockSize; p->blockSize = blockSize;
p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); p->bufferBase = (uint8_t *)alloc->Alloc(alloc, (size_t)blockSize);
} }
return (p->bufferBase != 0); return (p->bufferBase != 0);
} }
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } uint8_t *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
static Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 bindex) { return p->buffer[bindex]; } static uint8_t MatchFinder_GetIndexByte(CMatchFinder *p, int32_t bindex) { return p->buffer[bindex]; }
static UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; } static uint32_t MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) void MatchFinder_ReduceOffsets(CMatchFinder *p, uint32_t subValue)
{ {
p->posLimit -= subValue; p->posLimit -= subValue;
p->pos -= subValue; p->pos -= subValue;
@ -60,9 +60,9 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
return; return;
if (p->directInput) if (p->directInput)
{ {
UInt32 curSize = 0xFFFFFFFF - p->streamPos; uint32_t curSize = 0xFFFFFFFF - p->streamPos;
if (curSize > p->directInputRem) if (curSize > p->directInputRem)
curSize = (UInt32)p->directInputRem; curSize = (uint32_t)p->directInputRem;
p->directInputRem -= curSize; p->directInputRem -= curSize;
p->streamPos += curSize; p->streamPos += curSize;
if (p->directInputRem == 0) if (p->directInputRem == 0)
@ -71,7 +71,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
} }
for (;;) for (;;)
{ {
Byte *dest = p->buffer + (p->streamPos - p->pos); uint8_t *dest = p->buffer + (p->streamPos - p->pos);
size_t size = (p->bufferBase + p->blockSize - dest); size_t size = (p->bufferBase + p->blockSize - dest);
if (size == 0) if (size == 0)
return; return;
@ -83,7 +83,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
p->streamEndWasReached = 1; p->streamEndWasReached = 1;
return; return;
} }
p->streamPos += (UInt32)size; p->streamPos += (uint32_t)size;
if (p->streamPos - p->pos > p->keepSizeAfter) if (p->streamPos - p->pos > p->keepSizeAfter)
return; return;
} }
@ -132,7 +132,7 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
void MatchFinder_Construct(CMatchFinder *p) void MatchFinder_Construct(CMatchFinder *p)
{ {
UInt32 i; uint32_t i;
p->bufferBase = 0; p->bufferBase = 0;
p->directInput = 0; p->directInput = 0;
p->hash = 0; p->hash = 0;
@ -140,7 +140,7 @@ void MatchFinder_Construct(CMatchFinder *p)
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
UInt32 r = i; uint32_t r = i;
int j; int j;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
@ -160,26 +160,26 @@ void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
LzInWindow_Free(p, alloc); LzInWindow_Free(p, alloc);
} }
static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc) static CLzRef* AllocRefs(uint32_t num, ISzAlloc *alloc)
{ {
size_t sizeInBytes = (size_t)num * sizeof(CLzRef); size_t sizeInuint8_ts = (size_t)num * sizeof(CLzRef);
if (sizeInBytes / sizeof(CLzRef) != num) if (sizeInuint8_ts / sizeof(CLzRef) != num)
return 0; return 0;
return (CLzRef *)alloc->Alloc(alloc, sizeInBytes); return (CLzRef *)alloc->Alloc(alloc, sizeInuint8_ts);
} }
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, int MatchFinder_Create(CMatchFinder *p, uint32_t historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, uint32_t keepAddBufferBefore, uint32_t matchMaxLen, uint32_t keepAddBufferAfter,
ISzAlloc *alloc) ISzAlloc *alloc)
{ {
UInt32 sizeReserv; uint32_t sizeReserv;
if (historySize > kMaxHistorySize) if (historySize > kMaxHistorySize)
{ {
MatchFinder_Free(p, alloc); MatchFinder_Free(p, alloc);
return 0; return 0;
} }
sizeReserv = historySize >> 1; sizeReserv = historySize >> 1;
if (historySize > ((UInt32)2 << 30)) if (historySize > ((uint32_t)2 << 30))
sizeReserv = historySize >> 2; sizeReserv = historySize >> 2;
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19); sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
@ -188,8 +188,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */ /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
if (LzInWindow_Create(p, sizeReserv, alloc)) if (LzInWindow_Create(p, sizeReserv, alloc))
{ {
UInt32 newCyclicBufferSize = historySize + 1; uint32_t newCyclicBufferSize = historySize + 1;
UInt32 hs; uint32_t hs;
p->matchMaxLen = matchMaxLen; p->matchMaxLen = matchMaxLen;
{ {
p->fixedHashSize = 0; p->fixedHashSize = 0;
@ -221,8 +221,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
} }
{ {
UInt32 prevSize = p->hashSizeSum + p->numSons; uint32_t prevSize = p->hashSizeSum + p->numSons;
UInt32 newSize; uint32_t newSize;
p->historySize = historySize; p->historySize = historySize;
p->hashSizeSum = hs; p->hashSizeSum = hs;
p->cyclicBufferSize = newCyclicBufferSize; p->cyclicBufferSize = newCyclicBufferSize;
@ -245,8 +245,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
static void MatchFinder_SetLimits(CMatchFinder *p) static void MatchFinder_SetLimits(CMatchFinder *p)
{ {
UInt32 limit = kMaxValForNormalize - p->pos; uint32_t limit = kMaxValForNormalize - p->pos;
UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; uint32_t limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
if (limit2 < limit) if (limit2 < limit)
limit = limit2; limit = limit2;
limit2 = p->streamPos - p->pos; limit2 = p->streamPos - p->pos;
@ -260,7 +260,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
if (limit2 < limit) if (limit2 < limit)
limit = limit2; limit = limit2;
{ {
UInt32 lenLimit = p->streamPos - p->pos; uint32_t lenLimit = p->streamPos - p->pos;
if (lenLimit > p->matchMaxLen) if (lenLimit > p->matchMaxLen)
lenLimit = p->matchMaxLen; lenLimit = p->matchMaxLen;
p->lenLimit = lenLimit; p->lenLimit = lenLimit;
@ -270,7 +270,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
void MatchFinder_Init(CMatchFinder *p) void MatchFinder_Init(CMatchFinder *p)
{ {
UInt32 i; uint32_t i;
for (i = 0; i < p->hashSizeSum; i++) for (i = 0; i < p->hashSizeSum; i++)
p->hash[i] = kEmptyHashValue; p->hash[i] = kEmptyHashValue;
p->cyclicBufferPos = 0; p->cyclicBufferPos = 0;
@ -282,17 +282,17 @@ void MatchFinder_Init(CMatchFinder *p)
MatchFinder_SetLimits(p); MatchFinder_SetLimits(p);
} }
static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) static uint32_t MatchFinder_GetSubValue(CMatchFinder *p)
{ {
return (p->pos - p->historySize - 1) & kNormalizeMask; return (p->pos - p->historySize - 1) & kNormalizeMask;
} }
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems) void MatchFinder_Normalize3(uint32_t subValue, CLzRef *items, uint32_t numItems)
{ {
UInt32 i; uint32_t i;
for (i = 0; i < numItems; i++) for (i = 0; i < numItems; i++)
{ {
UInt32 value = items[i]; uint32_t value = items[i];
if (value <= subValue) if (value <= subValue)
value = kEmptyHashValue; value = kEmptyHashValue;
else else
@ -303,7 +303,7 @@ void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
static void MatchFinder_Normalize(CMatchFinder *p) static void MatchFinder_Normalize(CMatchFinder *p)
{ {
UInt32 subValue = MatchFinder_GetSubValue(p); uint32_t subValue = MatchFinder_GetSubValue(p);
MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons); MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
MatchFinder_ReduceOffsets(p, subValue); MatchFinder_ReduceOffsets(p, subValue);
} }
@ -319,22 +319,22 @@ 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, static uint32_t * Hc_GetMatchesSpec(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue,
UInt32 *distances, UInt32 maxLen) uint32_t *distances, uint32_t maxLen)
{ {
son[_cyclicBufferPos] = curMatch; son[_cyclicBufferPos] = curMatch;
for (;;) for (;;)
{ {
UInt32 delta = pos - curMatch; uint32_t delta = pos - curMatch;
if (cutValue-- == 0 || delta >= _cyclicBufferSize) if (cutValue-- == 0 || delta >= _cyclicBufferSize)
return distances; return distances;
{ {
const Byte *pb = cur - delta; const uint8_t *pb = cur - delta;
curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)]; curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
if (pb[maxLen] == cur[maxLen] && *pb == *cur) if (pb[maxLen] == cur[maxLen] && *pb == *cur)
{ {
UInt32 len = 0; uint32_t len = 0;
while (++len != lenLimit) while (++len != lenLimit)
if (pb[len] != cur[len]) if (pb[len] != cur[len])
break; break;
@ -350,16 +350,16 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos,
} }
} }
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, uint32_t * GetMatchesSpec1(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue,
UInt32 *distances, UInt32 maxLen) uint32_t *distances, uint32_t maxLen)
{ {
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1); CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
UInt32 len0 = 0, len1 = 0; uint32_t len0 = 0, len1 = 0;
for (;;) for (;;)
{ {
UInt32 delta = pos - curMatch; uint32_t delta = pos - curMatch;
if (cutValue-- == 0 || delta >= _cyclicBufferSize) if (cutValue-- == 0 || delta >= _cyclicBufferSize)
{ {
*ptr0 = *ptr1 = kEmptyHashValue; *ptr0 = *ptr1 = kEmptyHashValue;
@ -367,8 +367,8 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
} }
{ {
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
const Byte *pb = cur - delta; const uint8_t *pb = cur - delta;
UInt32 len = (len0 < len1 ? len0 : len1); uint32_t len = (len0 < len1 ? len0 : len1);
if (pb[len] == cur[len]) if (pb[len] == cur[len])
{ {
if (++len != lenLimit && pb[len] == cur[len]) if (++len != lenLimit && pb[len] == cur[len])
@ -405,15 +405,15 @@ 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_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue) uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue)
{ {
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
CLzRef *ptr1 = son + (_cyclicBufferPos << 1); CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
UInt32 len0 = 0, len1 = 0; uint32_t len0 = 0, len1 = 0;
for (;;) for (;;)
{ {
UInt32 delta = pos - curMatch; uint32_t delta = pos - curMatch;
if (cutValue-- == 0 || delta >= _cyclicBufferSize) if (cutValue-- == 0 || delta >= _cyclicBufferSize)
{ {
*ptr0 = *ptr1 = kEmptyHashValue; *ptr0 = *ptr1 = kEmptyHashValue;
@ -421,8 +421,8 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
} }
{ {
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
const Byte *pb = cur - delta; const uint8_t *pb = cur - delta;
UInt32 len = (len0 < len1 ? len0 : len1); uint32_t len = (len0 < len1 ? len0 : len1);
if (pb[len] == cur[len]) if (pb[len] == cur[len])
{ {
while (++len != lenLimit) while (++len != lenLimit)
@ -465,7 +465,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const
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 hashValue; const Byte *cur; UInt32 curMatch; \ uint32_t lenLimit; uint32_t hashValue; const uint8_t *cur; uint32_t curMatch; \
lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
cur = p->buffer; cur = p->buffer;
@ -475,15 +475,15 @@ 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 = (uint32_t)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
distances + offset, maxLen) - distances); MOVE_POS_RET; distances + offset, maxLen) - distances); MOVE_POS_RET;
#define SKIP_FOOTER \ #define SKIP_FOOTER \
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS; SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static uint32_t Bt2_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{ {
UInt32 offset; uint32_t offset;
GET_MATCHES_HEADER(2) GET_MATCHES_HEADER(2)
HASH2_CALC; HASH2_CALC;
curMatch = p->hash[hashValue]; curMatch = p->hash[hashValue];
@ -492,9 +492,9 @@ static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, 1) GET_MATCHES_FOOTER(offset, 1)
} }
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) uint32_t Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{ {
UInt32 offset; uint32_t offset;
GET_MATCHES_HEADER(3) GET_MATCHES_HEADER(3)
HASH_ZIP_CALC; HASH_ZIP_CALC;
curMatch = p->hash[hashValue]; curMatch = p->hash[hashValue];
@ -503,9 +503,9 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, 2) GET_MATCHES_FOOTER(offset, 2)
} }
static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static uint32_t Bt3_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{ {
UInt32 hash2Value, delta2, maxLen, offset; uint32_t hash2Value, delta2, maxLen, offset;
GET_MATCHES_HEADER(3) GET_MATCHES_HEADER(3)
HASH3_CALC; HASH3_CALC;
@ -536,9 +536,9 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen) GET_MATCHES_FOOTER(offset, maxLen)
} }
static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static uint32_t Bt4_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{ {
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset; uint32_t hash2Value, hash3Value, delta2, delta3, maxLen, offset;
GET_MATCHES_HEADER(4) GET_MATCHES_HEADER(4)
HASH4_CALC; HASH4_CALC;
@ -583,9 +583,9 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
GET_MATCHES_FOOTER(offset, maxLen) GET_MATCHES_FOOTER(offset, maxLen)
} }
static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) static uint32_t Hc4_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{ {
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset; uint32_t hash2Value, hash3Value, delta2, delta3, maxLen, offset;
GET_MATCHES_HEADER(4) GET_MATCHES_HEADER(4)
HASH4_CALC; HASH4_CALC;
@ -627,24 +627,24 @@ 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 = (uint32_t)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
distances + offset, maxLen) - (distances)); distances + offset, maxLen) - (distances));
MOVE_POS_RET MOVE_POS_RET
} }
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) uint32_t Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances)
{ {
UInt32 offset; uint32_t offset;
GET_MATCHES_HEADER(3) GET_MATCHES_HEADER(3)
HASH_ZIP_CALC; HASH_ZIP_CALC;
curMatch = p->hash[hashValue]; curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos; p->hash[hashValue] = p->pos;
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), offset = (uint32_t)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
distances, 2) - (distances)); distances, 2) - (distances));
MOVE_POS_RET MOVE_POS_RET
} }
static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) static void Bt2_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{ {
do do
{ {
@ -657,7 +657,7 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0); while (--num != 0);
} }
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{ {
do do
{ {
@ -670,11 +670,11 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0); while (--num != 0);
} }
static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) static void Bt3_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{ {
do do
{ {
UInt32 hash2Value; uint32_t hash2Value;
SKIP_HEADER(3) SKIP_HEADER(3)
HASH3_CALC; HASH3_CALC;
curMatch = p->hash[kFix3HashSize + hashValue]; curMatch = p->hash[kFix3HashSize + hashValue];
@ -685,11 +685,11 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0); while (--num != 0);
} }
static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) static void Bt4_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{ {
do do
{ {
UInt32 hash2Value, hash3Value; uint32_t hash2Value, hash3Value;
SKIP_HEADER(4) SKIP_HEADER(4)
HASH4_CALC; HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue]; curMatch = p->hash[kFix4HashSize + hashValue];
@ -701,11 +701,11 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0); while (--num != 0);
} }
static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) static void Hc4_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{ {
do do
{ {
UInt32 hash2Value, hash3Value; uint32_t hash2Value, hash3Value;
SKIP_HEADER(4) SKIP_HEADER(4)
HASH4_CALC; HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue]; curMatch = p->hash[kFix4HashSize + hashValue];
@ -718,7 +718,7 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0); while (--num != 0);
} }
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num)
{ {
do do
{ {

View File

@ -10,53 +10,53 @@
extern "C" { extern "C" {
#endif #endif
typedef UInt32 CLzRef; typedef uint32_t CLzRef;
typedef struct _CMatchFinder typedef struct _CMatchFinder
{ {
Byte *buffer; uint8_t *buffer;
UInt32 pos; uint32_t pos;
UInt32 posLimit; uint32_t posLimit;
UInt32 streamPos; uint32_t streamPos;
UInt32 lenLimit; uint32_t lenLimit;
UInt32 cyclicBufferPos; uint32_t cyclicBufferPos;
UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ uint32_t cyclicBufferSize; /* it must be = (historySize + 1) */
UInt32 matchMaxLen; uint32_t matchMaxLen;
CLzRef *hash; CLzRef *hash;
CLzRef *son; CLzRef *son;
UInt32 hashMask; uint32_t hashMask;
UInt32 cutValue; uint32_t cutValue;
Byte *bufferBase; uint8_t *bufferBase;
ISeqInStream *stream; ISeqInStream *stream;
int streamEndWasReached; int streamEndWasReached;
UInt32 blockSize; uint32_t blockSize;
UInt32 keepSizeBefore; uint32_t keepSizeBefore;
UInt32 keepSizeAfter; uint32_t keepSizeAfter;
UInt32 numHashBytes; uint32_t numHashBytes;
int directInput; int directInput;
size_t directInputRem; size_t directInputRem;
int btMode; int btMode;
int bigHash; int bigHash;
UInt32 historySize; uint32_t historySize;
UInt32 fixedHashSize; uint32_t fixedHashSize;
UInt32 hashSizeSum; uint32_t hashSizeSum;
UInt32 numSons; uint32_t numSons;
SRes result; SRes result;
UInt32 crc[256]; uint32_t crc[256];
} CMatchFinder; } CMatchFinder;
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)]) #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(int32_t)(index)])
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
int MatchFinder_NeedMove(CMatchFinder *p); int MatchFinder_NeedMove(CMatchFinder *p);
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); uint8_t *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
void MatchFinder_MoveBlock(CMatchFinder *p); void MatchFinder_MoveBlock(CMatchFinder *p);
void MatchFinder_ReadIfRequired(CMatchFinder *p); void MatchFinder_ReadIfRequired(CMatchFinder *p);
@ -66,16 +66,16 @@ void MatchFinder_Construct(CMatchFinder *p);
historySize <= 3 GB historySize <= 3 GB
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
*/ */
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, int MatchFinder_Create(CMatchFinder *p, uint32_t historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, uint32_t keepAddBufferBefore, uint32_t matchMaxLen, uint32_t keepAddBufferAfter,
ISzAlloc *alloc); ISzAlloc *alloc);
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems); void MatchFinder_Normalize3(uint32_t subValue, CLzRef *items, uint32_t numItems);
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); void MatchFinder_ReduceOffsets(CMatchFinder *p, uint32_t subValue);
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, uint32_t * GetMatchesSpec1(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const uint8_t *buffer, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t _cutValue,
UInt32 *distances, UInt32 maxLen); uint32_t *distances, uint32_t maxLen);
/* /*
Conditions: Conditions:
@ -84,11 +84,11 @@ Conditions:
*/ */
typedef void (*Mf_Init_Func)(void *object); typedef void (*Mf_Init_Func)(void *object);
typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index); typedef uint8_t (*Mf_GetIndexByte_Func)(void *object, int32_t index);
typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); typedef uint32_t (*Mf_GetNumAvailableBytes_Func)(void *object);
typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); typedef const uint8_t * (*Mf_GetPointerToCurrentPos_Func)(void *object);
typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); typedef uint32_t (*Mf_GetMatches_Func)(void *object, uint32_t *distances);
typedef void (*Mf_Skip_Func)(void *object, UInt32); typedef void (*Mf_Skip_Func)(void *object, uint32_t);
typedef struct _IMatchFinder typedef struct _IMatchFinder
{ {
@ -103,10 +103,10 @@ typedef struct _IMatchFinder
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
void MatchFinder_Init(CMatchFinder *p); void MatchFinder_Init(CMatchFinder *p);
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); uint32_t Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances);
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); uint32_t Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances);
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num);
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -12,43 +12,43 @@
#define kFix4HashSize (kHash2Size + kHash3Size) #define kFix4HashSize (kHash2Size + kHash3Size)
#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8); #define HASH2_CALC hashValue = cur[0] | ((uint32_t)cur[1] << 8);
#define HASH3_CALC { \ #define HASH3_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ uint32_t temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \ hash2Value = temp & (kHash2Size - 1); \
hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } hashValue = (temp ^ ((uint32_t)cur[2] << 8)) & p->hashMask; }
#define HASH4_CALC { \ #define HASH4_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ uint32_t temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \ hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ hash3Value = (temp ^ ((uint32_t)cur[2] << 8)) & (kHash3Size - 1); \
hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; } hashValue = (temp ^ ((uint32_t)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
#define HASH5_CALC { \ #define HASH5_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ uint32_t temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \ hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ hash3Value = (temp ^ ((uint32_t)cur[2] << 8)) & (kHash3Size - 1); \
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \ hash4Value = (temp ^ ((uint32_t)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \ hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
hash4Value &= (kHash4Size - 1); } hash4Value &= (kHash4Size - 1); }
/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ /* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((uint32_t)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; #define HASH_ZIP_CALC hashValue = ((cur[2] | ((uint32_t)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
#define MT_HASH2_CALC \ #define MT_HASH2_CALC \
hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
#define MT_HASH3_CALC { \ #define MT_HASH3_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ uint32_t temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \ hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } hash3Value = (temp ^ ((uint32_t)cur[2] << 8)) & (kHash3Size - 1); }
#define MT_HASH4_CALC { \ #define MT_HASH4_CALC { \
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ uint32_t temp = p->crc[cur[0]] ^ cur[1]; \
hash2Value = temp & (kHash2Size - 1); \ hash2Value = temp & (kHash2Size - 1); \
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \ hash3Value = (temp ^ ((uint32_t)cur[2] << 8)) & (kHash3Size - 1); \
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } hash4Value = (temp ^ ((uint32_t)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
#endif #endif

View File

@ -6,7 +6,7 @@
#include <string.h> #include <string.h>
#define kNumTopBits 24 #define kNumTopBits 24
#define kTopValue ((UInt32)1 << kNumTopBits) #define kTopValue ((uint32_t)1 << kNumTopBits)
#define kNumBitModelTotalBits 11 #define kNumBitModelTotalBits 11
#define kBitModelTotal (1 << kNumBitModelTotalBits) #define kBitModelTotal (1 << kNumBitModelTotalBits)
@ -107,7 +107,7 @@
#define LZMA_BASE_SIZE 1846 #define LZMA_BASE_SIZE 1846
#define LZMA_LIT_SIZE 768 #define LZMA_LIT_SIZE 768
#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp))) #define LzmaProps_GetNumProbs(p) ((uint32_t)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
#if Literal != LZMA_BASE_SIZE #if Literal != LZMA_BASE_SIZE
StopCompilingDueBUG StopCompilingDueBUG
@ -128,32 +128,32 @@ Out:
= kMatchSpecLenStart + 2 : State Init Marker = kMatchSpecLenStart + 2 : State Init Marker
*/ */
static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const Byte *bufLimit) static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, size_t limit_parm, const uint8_t *bufLimit)
{ {
CLzmaProb *probs = p->probs; CLzmaProb *probs = p->probs;
unsigned state = p->state; unsigned state = p->state;
UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3]; uint32_t rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1; unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1; unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
unsigned lc = p->prop.lc; unsigned lc = p->prop.lc;
Byte *dic = p->dic; uint8_t *dic = p->dic;
SizeT dicBufSize = p->dicBufSize; size_t dicBufSize = p->dicBufSize;
SizeT dicPos = p->dicPos; size_t dicPos = p->dicPos;
UInt32 processedPos = p->processedPos; uint32_t processedPos = p->processedPos;
UInt32 checkDicSize = p->checkDicSize; uint32_t checkDicSize = p->checkDicSize;
unsigned len = 0; unsigned len = 0;
const Byte *buf = p->buf; const uint8_t *buf = p->buf;
UInt32 range = p->range; uint32_t range = p->range;
UInt32 code = p->code; uint32_t code = p->code;
do do
{ {
CLzmaProb *prob; CLzmaProb *prob;
UInt32 bound; uint32_t bound;
unsigned ttt; unsigned ttt;
unsigned posState = processedPos & pbMask; unsigned posState = processedPos & pbMask;
@ -175,7 +175,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
} }
else else
{ {
unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)]; unsigned matchuint8_t = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
unsigned offs = 0x100; unsigned offs = 0x100;
state -= (state < 10) ? 3 : 6; state -= (state < 10) ? 3 : 6;
symbol = 1; symbol = 1;
@ -183,14 +183,14 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
{ {
unsigned bit; unsigned bit;
CLzmaProb *probLit; CLzmaProb *probLit;
matchByte <<= 1; matchuint8_t <<= 1;
bit = (matchByte & offs); bit = (matchuint8_t & offs);
probLit = prob + offs + bit + symbol; probLit = prob + offs + bit + symbol;
GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit) GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
} }
while (symbol < 0x100); while (symbol < 0x100);
} }
dic[dicPos++] = (Byte)symbol; dic[dicPos++] = (uint8_t)symbol;
processedPos++; processedPos++;
continue; continue;
} }
@ -227,7 +227,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
} }
else else
{ {
UInt32 distance; uint32_t distance;
UPDATE_1(prob); UPDATE_1(prob);
prob = probs + IsRepG1 + state; prob = probs + IsRepG1 + state;
IF_BIT_0(prob) IF_BIT_0(prob)
@ -293,7 +293,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
if (state >= kNumStates) if (state >= kNumStates)
{ {
UInt32 distance; uint32_t distance;
prob = probs + PosSlot + prob = probs + PosSlot +
((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits); ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
TREE_6_DECODE(prob, distance); TREE_6_DECODE(prob, distance);
@ -307,7 +307,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
distance <<= numDirectBits; distance <<= numDirectBits;
prob = probs + SpecPos + distance - posSlot - 1; prob = probs + SpecPos + distance - posSlot - 1;
{ {
UInt32 mask = 1; uint32_t mask = 1;
unsigned i = 1; unsigned i = 1;
do do
{ {
@ -326,9 +326,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
range >>= 1; range >>= 1;
{ {
UInt32 t; uint32_t t;
code -= range; code -= range;
t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */ t = (0 - ((uint32_t)code >> 31)); /* (uint32_t)((int32_t)code >> 31) */
distance = (distance << 1) + (t + 1); distance = (distance << 1) + (t + 1);
code += range & t; code += range & t;
} }
@ -351,7 +351,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
GET_BIT2(prob + i, i, ; , distance |= 4); GET_BIT2(prob + i, i, ; , distance |= 4);
GET_BIT2(prob + i, i, ; , distance |= 8); GET_BIT2(prob + i, i, ; , distance |= 8);
} }
if (distance == (UInt32)0xFFFFFFFF) if (distance == (uint32_t)0xFFFFFFFF)
{ {
len += kMatchSpecLenStart; len += kMatchSpecLenStart;
state -= kNumStates; state -= kNumStates;
@ -378,21 +378,21 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
if (limit_parm == dicPos) if (limit_parm == dicPos)
return SZ_ERROR_DATA; return SZ_ERROR_DATA;
{ {
SizeT rem = limit_parm - dicPos; size_t rem = limit_parm - dicPos;
unsigned curLen = ((rem < len) ? (unsigned)rem : len); unsigned curLen = ((rem < len) ? (unsigned)rem : len);
SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0); size_t pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
processedPos += curLen; processedPos += curLen;
len -= curLen; len -= curLen;
if (pos + curLen <= dicBufSize) if (pos + curLen <= dicBufSize)
{ {
Byte *dest = dic + dicPos; uint8_t *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 uint8_t *lim = dest + curLen;
dicPos += curLen; dicPos += curLen;
do do
*(dest) = (Byte)*(dest + src); *(dest) = (uint8_t)*(dest + src);
while (++dest != lim); while (++dest != lim);
} }
else else
@ -425,15 +425,15 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit_parm, const
return SZ_OK; return SZ_OK;
} }
static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, size_t limit)
{ {
if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
{ {
Byte *dic = p->dic; uint8_t *dic = p->dic;
SizeT dicPos = p->dicPos; size_t dicPos = p->dicPos;
SizeT dicBufSize = p->dicBufSize; size_t dicBufSize = p->dicBufSize;
unsigned len = p->remainLen; unsigned len = p->remainLen;
UInt32 rep0 = p->reps[0]; uint32_t rep0 = p->reps[0];
if (limit - dicPos < len) if (limit - dicPos < len)
len = (unsigned)(limit - dicPos); len = (unsigned)(limit - dicPos);
@ -451,14 +451,14 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
} }
} }
static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit) static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, size_t limit, const uint8_t *bufLimit)
{ {
do do
{ {
SizeT limit2 = limit; size_t limit2 = limit;
if (p->checkDicSize == 0) if (p->checkDicSize == 0)
{ {
UInt32 rem = p->prop.dicSize - p->processedPos; uint32_t rem = p->prop.dicSize - p->processedPos;
if (limit - p->dicPos > rem) if (limit - p->dicPos > rem)
limit2 = p->dicPos + rem; limit2 = p->dicPos + rem;
} }
@ -484,18 +484,18 @@ typedef enum
DUMMY_REP DUMMY_REP
} ELzmaDummy; } ELzmaDummy;
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize) static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const uint8_t *buf, size_t inSize)
{ {
UInt32 range = p->range; uint32_t range = p->range;
UInt32 code = p->code; uint32_t code = p->code;
const Byte *bufLimit = buf + inSize; const uint8_t *bufLimit = buf + inSize;
CLzmaProb *probs = p->probs; CLzmaProb *probs = p->probs;
unsigned state = p->state; unsigned state = p->state;
ELzmaDummy res; ELzmaDummy res;
{ {
CLzmaProb *prob; CLzmaProb *prob;
UInt32 bound; uint32_t bound;
unsigned ttt; unsigned ttt;
unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1); unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
@ -519,7 +519,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
} }
else else
{ {
unsigned matchByte = p->dic[p->dicPos - p->reps[0] + unsigned matchuint8_t = p->dic[p->dicPos - p->reps[0] +
((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)]; ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
unsigned offs = 0x100; unsigned offs = 0x100;
unsigned symbol = 1; unsigned symbol = 1;
@ -527,8 +527,8 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
{ {
unsigned bit; unsigned bit;
CLzmaProb *probLit; CLzmaProb *probLit;
matchByte <<= 1; matchuint8_t <<= 1;
bit = (matchByte & offs); bit = (matchuint8_t & offs);
probLit = prob + offs + bit + symbol; probLit = prob + offs + bit + symbol;
GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit) GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
} }
@ -675,14 +675,14 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
} }
static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data) static void LzmaDec_InitRc(CLzmaDec *p, const uint8_t *data)
{ {
p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]); p->code = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | ((uint32_t)data[3] << 8) | ((uint32_t)data[4]);
p->range = 0xFFFFFFFF; p->range = 0xFFFFFFFF;
p->needFlush = 0; p->needFlush = 0;
} }
static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) static void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState)
{ {
p->needFlush = 1; p->needFlush = 1;
p->remainLen = 0; p->remainLen = 0;
@ -701,13 +701,13 @@ static void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
void LzmaDec_Init(CLzmaDec *p) void LzmaDec_Init(CLzmaDec *p)
{ {
p->dicPos = 0; p->dicPos = 0;
LzmaDec_InitDicAndState(p, True, True); LzmaDec_InitDicAndState(p, true, true);
} }
static void LzmaDec_InitStateReal(CLzmaDec *p) static void LzmaDec_InitStateReal(CLzmaDec *p)
{ {
UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp)); uint32_t numProbs = Literal + ((uint32_t)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
UInt32 i; uint32_t i;
CLzmaProb *probs = p->probs; CLzmaProb *probs = p->probs;
for (i = 0; i < numProbs; i++) for (i = 0; i < numProbs; i++)
probs[i] = kBitModelTotal >> 1; probs[i] = kBitModelTotal >> 1;
@ -716,10 +716,10 @@ static void LzmaDec_InitStateReal(CLzmaDec *p)
p->needInitState = 0; p->needInitState = 0;
} }
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit, const uint8_t *src, size_t *srcLen,
ELzmaFinishMode finishMode, ELzmaStatus *status) ELzmaFinishMode finishMode, ELzmaStatus *status)
{ {
SizeT inSize = *srcLen; size_t inSize = *srcLen;
(*srcLen) = 0; (*srcLen) = 0;
LzmaDec_WriteRem(p, dicLimit); LzmaDec_WriteRem(p, dicLimit);
@ -771,8 +771,8 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
if (p->tempBufSize == 0) if (p->tempBufSize == 0)
{ {
SizeT processed; size_t processed;
const Byte *bufLimit; const uint8_t *bufLimit;
if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
{ {
int dummyRes = LzmaDec_TryDummy(p, src, inSize); int dummyRes = LzmaDec_TryDummy(p, src, inSize);
@ -796,7 +796,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
p->buf = src; p->buf = src;
if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0) if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
return SZ_ERROR_DATA; return SZ_ERROR_DATA;
processed = (SizeT)(p->buf - src); processed = (size_t)(p->buf - src);
(*srcLen) += processed; (*srcLen) += processed;
src += processed; src += processed;
inSize -= processed; inSize -= processed;
@ -837,14 +837,14 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA; return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
} }
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) SRes LzmaDec_DecodeToBuf(CLzmaDec *p, uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
{ {
SizeT outSize = *destLen; size_t outSize = *destLen;
SizeT inSize = *srcLen; size_t inSize = *srcLen;
*srcLen = *destLen = 0; *srcLen = *destLen = 0;
for (;;) for (;;)
{ {
SizeT inSizeCur = inSize, outSizeCur, dicPos; size_t inSizeCur = inSize, outSizeCur, dicPos;
ELzmaFinishMode curFinishMode; ELzmaFinishMode curFinishMode;
SRes res; SRes res;
if (p->dicPos == p->dicBufSize) if (p->dicPos == p->dicBufSize)
@ -895,15 +895,15 @@ void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
LzmaDec_FreeDict(p, alloc); LzmaDec_FreeDict(p, alloc);
} }
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) SRes LzmaProps_Decode(CLzmaProps *p, const uint8_t *data, unsigned size)
{ {
UInt32 dicSize; uint32_t dicSize;
Byte d; uint8_t d;
if (size < LZMA_PROPS_SIZE) if (size < LZMA_PROPS_SIZE)
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
else else
dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24); dicSize = data[1] | ((uint32_t)data[2] << 8) | ((uint32_t)data[3] << 16) | ((uint32_t)data[4] << 24);
if (dicSize < LZMA_DIC_MIN) if (dicSize < LZMA_DIC_MIN)
dicSize = LZMA_DIC_MIN; dicSize = LZMA_DIC_MIN;
@ -923,7 +923,7 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
{ {
UInt32 numProbs = LzmaProps_GetNumProbs(propNew); uint32_t numProbs = LzmaProps_GetNumProbs(propNew);
if (p->probs == 0 || numProbs != p->numProbs) if (p->probs == 0 || numProbs != p->numProbs)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
@ -935,7 +935,7 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
return SZ_OK; return SZ_OK;
} }
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) SRes LzmaDec_AllocateProbs(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
{ {
CLzmaProps propNew; CLzmaProps propNew;
RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaProps_Decode(&propNew, props, propsSize));
@ -944,17 +944,17 @@ SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, I
return SZ_OK; return SZ_OK;
} }
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) SRes LzmaDec_Allocate(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc)
{ {
CLzmaProps propNew; CLzmaProps propNew;
SizeT dicBufSize; size_t dicBufSize;
RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaProps_Decode(&propNew, props, propsSize));
RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc)); RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
dicBufSize = propNew.dicSize; dicBufSize = propNew.dicSize;
if (p->dic == 0 || dicBufSize != p->dicBufSize) if (p->dic == 0 || dicBufSize != p->dicBufSize)
{ {
LzmaDec_FreeDict(p, alloc); LzmaDec_FreeDict(p, alloc);
p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize); p->dic = (uint8_t *)alloc->Alloc(alloc, dicBufSize);
if (p->dic == 0) if (p->dic == 0)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
@ -966,14 +966,14 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
return SZ_OK; return SZ_OK;
} }
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes LzmaDecode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, const uint8_t *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc) ELzmaStatus *status, ISzAlloc *alloc)
{ {
CLzmaDec p; CLzmaDec p;
SRes res; SRes res;
SizeT inSize = *srcLen; size_t inSize = *srcLen;
SizeT outSize = *destLen; size_t outSize = *destLen;
*srcLen = *destLen = 0; *srcLen = *destLen = 0;
if (inSize < RC_INIT_SIZE) if (inSize < RC_INIT_SIZE)
return SZ_ERROR_INPUT_EOF; return SZ_ERROR_INPUT_EOF;

View File

@ -15,9 +15,9 @@ extern "C" {
but memory usage for CLzmaDec::probs will be doubled in that case */ but memory usage for CLzmaDec::probs will be doubled in that case */
#ifdef _LZMA_PROB32 #ifdef _LZMA_PROB32
#define CLzmaProb UInt32 #define CLzmaProb uint32_t
#else #else
#define CLzmaProb UInt16 #define CLzmaProb uint16_t
#endif #endif
@ -28,7 +28,7 @@ extern "C" {
typedef struct _CLzmaProps typedef struct _CLzmaProps
{ {
unsigned lc, lp, pb; unsigned lc, lp, pb;
UInt32 dicSize; uint32_t dicSize;
} CLzmaProps; } CLzmaProps;
/* LzmaProps_Decode - decodes properties /* LzmaProps_Decode - decodes properties
@ -37,7 +37,7 @@ Returns:
SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_UNSUPPORTED - Unsupported properties
*/ */
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); SRes LzmaProps_Decode(CLzmaProps *p, const uint8_t *data, unsigned size);
/* ---------- LZMA Decoder state ---------- */ /* ---------- LZMA Decoder state ---------- */
@ -51,21 +51,21 @@ typedef struct
{ {
CLzmaProps prop; CLzmaProps prop;
CLzmaProb *probs; CLzmaProb *probs;
Byte *dic; uint8_t *dic;
const Byte *buf; const uint8_t *buf;
UInt32 range, code; uint32_t range, code;
SizeT dicPos; size_t dicPos;
SizeT dicBufSize; size_t dicBufSize;
UInt32 processedPos; uint32_t processedPos;
UInt32 checkDicSize; uint32_t checkDicSize;
unsigned state; unsigned state;
UInt32 reps[4]; uint32_t reps[4];
unsigned remainLen; unsigned remainLen;
int needFlush; int needFlush;
int needInitState; int needInitState;
UInt32 numProbs; uint32_t numProbs;
unsigned tempBufSize; unsigned tempBufSize;
Byte tempBuf[LZMA_REQUIRED_INPUT_MAX]; uint8_t tempBuf[LZMA_REQUIRED_INPUT_MAX];
} CLzmaDec; } CLzmaDec;
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
@ -131,10 +131,10 @@ LzmaDec_Allocate* can return:
SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_UNSUPPORTED - Unsupported properties
*/ */
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); SRes LzmaDec_AllocateProbs(CLzmaDec *p, const uint8_t *props, unsigned propsSize, ISzAlloc *alloc);
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); SRes LzmaDec_Allocate(CLzmaDec *state, const uint8_t *prop, unsigned propsSize, ISzAlloc *alloc);
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
/* ---------- Dictionary Interface ---------- */ /* ---------- Dictionary Interface ---------- */
@ -178,8 +178,8 @@ Returns:
SZ_ERROR_DATA - Data error SZ_ERROR_DATA - Data error
*/ */
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, SRes LzmaDec_DecodeToDic(CLzmaDec *p, size_t dicLimit,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); const uint8_t *src, size_t *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
/* ---------- Buffer Interface ---------- */ /* ---------- Buffer Interface ---------- */
@ -195,8 +195,8 @@ finishMode:
LZMA_FINISH_END - Stream must be finished after (*destLen). LZMA_FINISH_END - Stream must be finished after (*destLen).
*/ */
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, SRes LzmaDec_DecodeToBuf(CLzmaDec *p, uint8_t *dest, size_t *destLen,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); const uint8_t *src, size_t *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
/* ---------- One Call Interface ---------- */ /* ---------- One Call Interface ---------- */
@ -220,8 +220,8 @@ Returns:
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
*/ */
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes LzmaDecode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t *srcLen,
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, const uint8_t *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc); ELzmaStatus *status, ISzAlloc *alloc);
#ifdef __cplusplus #ifdef __cplusplus

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ extern "C" {
typedef struct _CLzmaEncProps typedef struct _CLzmaEncProps
{ {
int level; /* 0 <= level <= 9 */ int level; /* 0 <= level <= 9 */
UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version uint32_t dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
(1 << 12) <= dictSize <= (1 << 30) for 64-bit version (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
default = (1 << 24) */ default = (1 << 24) */
int lc; /* 0 <= lc <= 8, default = 3 */ int lc; /* 0 <= lc <= 8, default = 3 */
@ -25,14 +25,14 @@ typedef struct _CLzmaEncProps
int fb; /* 5 <= fb <= 273, default = 32 */ int fb; /* 5 <= fb <= 273, default = 32 */
int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
int numHashBytes; /* 2, 3 or 4, default = 4 */ int numHashBytes; /* 2, 3 or 4, default = 4 */
UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ uint32_t mc; /* 1 <= mc <= (1 << 30), default = 32 */
unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
int numThreads; /* 1 or 2, default = 2 */ int numThreads; /* 1 or 2, default = 2 */
} CLzmaEncProps; } CLzmaEncProps;
void LzmaEncProps_Init(CLzmaEncProps *p); void LzmaEncProps_Init(CLzmaEncProps *p);
void LzmaEncProps_Normalize(CLzmaEncProps *p); void LzmaEncProps_Normalize(CLzmaEncProps *p);
UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); uint32_t LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
/* ---------- CLzmaEncHandle Interface ---------- */ /* ---------- CLzmaEncHandle Interface ---------- */
@ -52,10 +52,10 @@ typedef void * CLzmaEncHandle;
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc); CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig); void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, uint8_t *properties, size_t *size);
SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes LzmaEnc_MemEncode(CLzmaEncHandle p, uint8_t *dest, size_t *destLen, const uint8_t *src, size_t srcLen,
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
/* ---------- One Call Interface ---------- */ /* ---------- One Call Interface ---------- */
@ -69,8 +69,8 @@ Return code:
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
*/ */
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, SRes LzmaEncode(uint8_t *dest, size_t *destLen, const uint8_t *src, size_t srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, const CLzmaEncProps *props, uint8_t *propsEncoded, size_t *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -5,6 +5,8 @@
#define __7Z_TYPES_H #define __7Z_TYPES_H
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -52,48 +54,6 @@ typedef int WRes;
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
#endif #endif
typedef unsigned char Byte;
typedef short Int16;
typedef unsigned short UInt16;
#ifdef _LZMA_UINT32_IS_ULONG
typedef long Int32;
typedef unsigned long UInt32;
#else
typedef int Int32;
typedef unsigned int UInt32;
#endif
#ifdef _SZ_NO_INT_64
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
NOTES: Some code will work incorrectly in that case! */
typedef long Int64;
typedef unsigned long UInt64;
#else
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 Int64;
typedef unsigned __int64 UInt64;
#else
typedef long long int Int64;
typedef unsigned long long int UInt64;
#endif
#endif
#ifdef _LZMA_NO_SYSTEM_SIZE_T
typedef UInt32 SizeT;
#else
typedef size_t SizeT;
#endif
typedef int Bool;
#define True 1
#define False 0
#ifdef _WIN32 #ifdef _WIN32
#define MY_STD_CALL __stdcall #define MY_STD_CALL __stdcall
@ -124,12 +84,12 @@ typedef int Bool;
typedef struct typedef struct
{ {
Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ uint8_t (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
} IByteIn; } IByteIn;
typedef struct typedef struct
{ {
void (*Write)(void *p, Byte b); void (*Write)(void *p, uint8_t b);
} IByteOut; } IByteOut;
typedef struct ISeqInStream typedef struct ISeqInStream
@ -145,7 +105,7 @@ typedef struct ISeqInStream
/* it can return SZ_ERROR_INPUT_EOF */ /* it can return SZ_ERROR_INPUT_EOF */
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); SRes SeqInStream_ReadByte(ISeqInStream *stream, uint8_t *buf);
typedef struct ISeqOutStream typedef struct ISeqOutStream
{ {
@ -167,7 +127,7 @@ typedef enum
typedef struct typedef struct
{ {
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); SRes (*Seek)(void *p, int64_t *pos, ESzSeek origin);
} ISeekInStream; } ISeekInStream;
typedef struct typedef struct
@ -181,11 +141,11 @@ typedef struct
SRes (*Read)(void *p, void *buf, size_t *size); SRes (*Read)(void *p, void *buf, size_t *size);
/* reads directly (without buffer). It's same as ISeqInStream::Read */ /* reads directly (without buffer). It's same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); SRes (*Seek)(void *p, int64_t *pos, ESzSeek origin);
} ILookInStream; } ILookInStream;
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset);
/* reads via ILookInStream::Read */ /* reads via ILookInStream::Read */
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
@ -199,7 +159,7 @@ typedef struct
ISeekInStream *realStream; ISeekInStream *realStream;
size_t pos; size_t pos;
size_t size; size_t size;
Byte buf[LookToRead_BUF_SIZE]; uint8_t buf[LookToRead_BUF_SIZE];
} CLookToRead; } CLookToRead;
void LookToRead_CreateVTable(CLookToRead *p, int lookahead); void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
@ -223,9 +183,9 @@ void SecToRead_CreateVTable(CSecToRead *p);
typedef struct typedef struct
{ {
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); SRes (*Progress)(void *p, uint64_t inSize, uint64_t outSize);
/* Returns: result. (result != SZ_OK) means break. /* Returns: result. (result != SZ_OK) means break.
Value (UInt64)(Int64)-1 for size means unknown value. */ Value (uint64_t)(int64_t)-1 for size means unknown value. */
} ICompressProgress; } ICompressProgress;
typedef struct typedef struct

View File

@ -186,9 +186,9 @@ void do_lzma_uncompress(char *dst, int dst_len, char *src, int src_len)
size_t destlen = out_sizemax; size_t destlen = out_sizemax;
size_t srclen = src_len - (LZMA_PROPS_SIZE + 8); size_t srclen = src_len - (LZMA_PROPS_SIZE + 8);
int res = LzmaDecode((Byte *) dst, &destlen, int res = LzmaDecode((uint8_t *) dst, &destlen,
(Byte *) &src[LZMA_PROPS_SIZE + 8], &srclen, (uint8_t *) &src[LZMA_PROPS_SIZE + 8], &srclen,
(Byte *) &src[0], LZMA_PROPS_SIZE, (uint8_t *) &src[0], LZMA_PROPS_SIZE,
LZMA_FINISH_END, LZMA_FINISH_END,
&status, &status,
&LZMAalloc); &LZMAalloc);