4.46 beta

This commit is contained in:
Igor Pavlov
2007-05-25 00:00:00 +00:00
committed by Kornel Lesiński
parent a145bfc7cf
commit c574fc0f4b
191 changed files with 1318 additions and 854 deletions

View File

@@ -1,4 +1,4 @@
/* 7zCrc.c */
/* 7zCrcT8.c */
#include "7zCrc.h"

View File

@@ -1,4 +1,4 @@
// Common/Alloc.c
/* Alloc.c */
#ifdef _WIN32
#include <windows.h>
@@ -7,7 +7,7 @@
#include "Alloc.h"
// #define _SZ_ALLOC_DEBUG
/* #define _SZ_ALLOC_DEBUG */
/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
#ifdef _SZ_ALLOC_DEBUG

View File

@@ -1,4 +1,4 @@
// Common/Alloc.h
/* Alloc.h */
#ifndef __COMMON_ALLOC_H
#define __COMMON_ALLOC_H

View File

@@ -46,10 +46,12 @@ void ConvertNumberToString(CFileSize value, char *s)
#ifdef USE_WINDOWS_FUNCTIONS
// ReadFile and WriteFile functions in Windows have BUG:
// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
// (Insufficient system resources exist to complete the requested service).
/*
ReadFile and WriteFile functions in Windows have BUG:
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
(Insufficient system resources exist to complete the requested service).
*/
#define kChunkSizeMax (1 << 24)
#endif
@@ -161,7 +163,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
value.LowPart = (DWORD)pos;
value.HighPart = (LONG)((UInt64)pos >> 32);
#ifdef _SZ_FILE_SIZE_32
// VC 6.0 has bug with >> 32 shifts.
/* VC 6.0 has bug with >> 32 shifts. */
value.HighPart = 0;
#endif
value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN);
@@ -354,7 +356,7 @@ int main(int numargs, char *args[])
printf("\nEverything is Ok\n");
return 0;
}
if (res == SZE_OUTOFMEMORY)
if (res == (SZ_RESULT)SZE_OUTOFMEMORY)
PrintError("can not allocate memory");
else
printf("\nERROR #%d\n", res);

View File

@@ -1,4 +1,4 @@
// BranchARM.h
/* BranchARM.h */
#ifndef __BRANCH_ARM_H
#define __BRANCH_ARM_H

View File

@@ -1,4 +1,4 @@
// BranchARMThumb.h
/* BranchARMThumb.h */
#ifndef __BRANCH_ARM_THUMB_H
#define __BRANCH_ARM_THUMB_H

View File

@@ -1,4 +1,4 @@
// BranchIA64.h
/* BranchIA64.h */
#ifndef __BRANCH_IA64_H
#define __BRANCH_IA64_H

View File

@@ -1,4 +1,4 @@
// BranchPPC.h
/* BranchPPC.h */
#ifndef __BRANCH_PPC_H
#define __BRANCH_PPC_H

View File

@@ -1,4 +1,4 @@
// BranchSPARC.h
/* BranchSPARC.h */
#ifndef __BRANCH_SPARC_H
#define __BRANCH_SPARC_H

View File

@@ -1,4 +1,4 @@
// Compression/HuffmanEncode.c
/* Compress/HuffmanEncode.c */
#include "HuffmanEncode.h"
#include "../../Sort.h"
@@ -9,13 +9,13 @@
#define NUM_COUNTERS 64
// use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M
/* use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M */
#define HUFFMAN_SPEED_OPT
void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymbols, UInt32 maxLen)
{
UInt32 num = 0;
// if (maxLen > 10) maxLen = 10;
/* if (maxLen > 10) maxLen = 10; */
{
UInt32 i;
@@ -133,7 +133,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
for (len = 1; len <= kMaxLen; len++)
nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;
}
// if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1;
/* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
{
UInt32 i;

View File

@@ -1,4 +1,4 @@
// Compress/HuffmanEncode.h
/* Compress/HuffmanEncode.h */
#ifndef __COMPRESS_HUFFMANENCODE_H
#define __COMPRESS_HUFFMANENCODE_H

View File

@@ -163,7 +163,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
sizeReserv = historySize >> 1;
if (historySize > ((UInt32)2 << 30))
sizeReserv = historySize >> 2;
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 12);
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
@@ -622,6 +622,19 @@ UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
MOVE_POS_RET
}
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
{
UInt32 offset;
GET_MATCHES_HEADER(3)
HASH_ZIP_CALC;
curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos;
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, p->pos, p->buffer, p->son,
p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
distances, 2) - (distances));
MOVE_POS_RET
}
void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
@@ -696,6 +709,20 @@ void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
while (--num != 0);
}
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
{
SKIP_HEADER(3)
HASH_ZIP_CALC;
curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos;
p->son[p->cyclicBufferPos] = curMatch;
MOVE_POS
}
while (--num != 0);
}
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
{
vTable->Init = (Mf_Init_Func)MatchFinder_Init;

View File

@@ -98,6 +98,8 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
void MatchFinder_Init(CMatchFinder *p);
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
#endif

View File

@@ -1,6 +1,17 @@
/* MatchFinderMt.c */
#ifdef _WIN32
#define USE_ALLOCA
#endif
#ifdef USE_ALLOCA
#ifdef _WIN32
#include <malloc.h>
#else
#include <stdlib.h>
#endif
#endif
#include "../../7zCrc.h"
#include "LzHash.h"
@@ -460,7 +471,14 @@ void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
static unsigned StdCall HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
static unsigned StdCall BtThreadFunc2(void *p) { alloca(0x180); BtThreadFunc((CMatchFinderMt *)p); return 0; }
static unsigned StdCall BtThreadFunc2(void *p)
{
#ifdef USE_ALLOCA
alloca(0x180);
#endif
BtThreadFunc((CMatchFinderMt *)p);
return 0;
}
HRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)

View File

@@ -71,9 +71,9 @@ typedef struct _CMatchFinderMt
UInt32 matchMaxLen;
UInt32 numHashBytes;
UInt32 pos;
Byte *buffer; // Pointer to virtual Buffer begin
Byte *buffer; /* Pointer to virtual Buffer begin */
UInt32 cyclicBufferPos;
UInt32 cyclicBufferSize; // it must be historySize + 1
UInt32 cyclicBufferSize; /* it must be historySize + 1 */
UInt32 cutValue;
/* BT + Hash */

View File

@@ -1,4 +1,4 @@
// IStream.h
/* IStream.h */
#ifndef __C_ISTREAM_H
#define __C_ISTREAM_H

View File

@@ -21,12 +21,12 @@ HRes MyCloseHandle(HANDLE *h)
return SZ_OK;
}
HRes Thread_Create(CThread *thread, unsigned (StdCall *startAddress)(void *), LPVOID parameter)
HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
{
/* DWORD threadId; */
unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
thread->handle =
/* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */
(HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, NULL);
(HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);
/* maybe we must use errno here, but probably GetLastError() is also OK. */
return BoolToHRes(thread->handle != 0);
}
@@ -48,13 +48,22 @@ HRes Thread_Close(CThread *thread)
return MyCloseHandle(&thread->handle);
}
HRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
HRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
{
p->handle = CreateEvent(NULL, FALSE, (initialSignaled ? TRUE : FALSE), NULL);
p->handle = CreateEvent(NULL, manualReset, (initialSignaled ? TRUE : FALSE), NULL);
return BoolToHRes(p->handle != 0);
}
HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p) { return AutoResetEvent_Create(p, 0); }
HRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
{ return Event_Create(p, TRUE, initialSignaled); }
HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
{ return ManualResetEvent_Create(p, 0); }
HRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
{ return Event_Create(p, FALSE, initialSignaled); }
HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
{ return AutoResetEvent_Create(p, 0); }
HRes Event_Set(CEvent *p) { return BOOLToHRes(SetEvent(p->handle)); }
HRes Event_Reset(CEvent *p) { return BOOLToHRes(ResetEvent(p->handle)); }
HRes Event_Wait(CEvent *p) { return WaitObject(p->handle); }
@@ -71,9 +80,9 @@ HRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
{
return BOOLToHRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
}
HRes Semaphore_ReleaseN(CSemaphore *p, LONG releaseCount)
HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
{
return Semaphore_Release(p, releaseCount, NULL);
return Semaphore_Release(p, (LONG)releaseCount, NULL);
}
HRes Semaphore_Release1(CSemaphore *p)
{
@@ -89,7 +98,7 @@ HRes CriticalSection_Init(CCriticalSection *p)
__try
{
InitializeCriticalSection(p);
// InitializeCriticalSectionAndSpinCount(p, 0);
/* InitializeCriticalSectionAndSpinCount(p, 0); */
}
__except (EXCEPTION_EXECUTE_HANDLER) { return SZE_OUTOFMEMORY; }
return SZ_OK;

View File

@@ -1,4 +1,4 @@
/* Thresds.h */
/* Threads.h */
#ifndef __7Z_THRESDS_H
#define __7Z_THRESDS_H
@@ -15,7 +15,11 @@ typedef struct _CThread
#define Thread_Construct(thread) (thread)->handle = NULL
#define Thread_WasCreated(thread) ((thread)->handle != NULL)
HRes Thread_Create(CThread *thread, unsigned (StdCall *startAddress)(void *), LPVOID parameter);
typedef unsigned THREAD_FUNC_RET_TYPE;
#define THREAD_FUNC_CALL_TYPE StdCall
#define THREAD_FUNC_DECL THREAD_FUNC_RET_TYPE THREAD_FUNC_CALL_TYPE
HRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter);
HRes Thread_Wait(CThread *thread);
HRes Thread_Close(CThread *thread);
@@ -25,9 +29,13 @@ typedef struct _CEvent
} CEvent;
typedef CEvent CAutoResetEvent;
typedef CEvent CManualResetEvent;
#define Event_Construct(event) (event)->handle = NULL
#define Event_IsCreated(event) ((event)->handle != NULL)
HRes ManualResetEvent_Create(CManualResetEvent *event, int initialSignaled);
HRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *event);
HRes AutoResetEvent_Create(CAutoResetEvent *event, int initialSignaled);
HRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *event);
HRes Event_Set(CEvent *event);
@@ -44,6 +52,7 @@ typedef struct _CSemaphore
#define Semaphore_Construct(p) (p)->handle = NULL
HRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount);
HRes Semaphore_ReleaseN(CSemaphore *p, UInt32 num);
HRes Semaphore_Release1(CSemaphore *p);
HRes Semaphore_Wait(CSemaphore *p);
HRes Semaphore_Close(CSemaphore *p);