Whoops, last File_Extractor update broke rarvm, reverted that mess and fixed all the warnings with casting

CQTexperiment
Chris Moeller 2013-10-04 16:31:10 -07:00
parent d76c1c2210
commit 145dd84c35
28 changed files with 279 additions and 269 deletions

View File

@ -81,7 +81,7 @@ static inline unrar_err_t handle_err( Rar_Extractor::read_callback_t* h, blargg_
extern "C"
{
static unrar_err_t my_unrar_read( void* data, void* out, long* count, unrar_pos_t pos )
static unrar_err_t my_unrar_read( void* data, void* out, int* count, unrar_pos_t pos )
{
Rar_Extractor::read_callback_t* h = STATIC_CAST(Rar_Extractor::read_callback_t*,data);
if ( h->pos != pos )

View File

@ -295,12 +295,18 @@ BLARGG_EXPORT const char* fex_err_details( fex_err_t err )
//// Wrappers
BLARGG_EXPORT fex_err_t fex_read( fex_t* fe, void* out, int count )
BLARGG_EXPORT fex_err_t fex_read( fex_t* fe, void* out, long count )
{
RETURN_ERR( fe->stat() );
return fe->reader().read( out, count );
}
BLARGG_EXPORT fex_err_t fex_skip( fex_t* fe, long count )
{
RETURN_ERR( fe->stat() );
return fe->reader().skip( count );
}
BLARGG_EXPORT void fex_close ( fex_t* fe ) { delete fe; }
BLARGG_EXPORT fex_type_t fex_type ( const fex_t* fe ) { return fe->type(); }
BLARGG_EXPORT int fex_done ( const fex_t* fe ) { return fe->done(); }

View File

@ -150,10 +150,13 @@ unsigned int fex_crc32( const fex_t* );
/** Reads n bytes from current file. Reading past end of file results in
fex_err_file_eof. */
fex_err_t fex_read( fex_t*, void* out, int n );
fex_err_t fex_read( fex_t*, void* out, long n );
/** Number of bytes read from current file */
uint64_t fex_tell( const fex_t* );
/** Skips the specified number of bytes in the current file */
fex_err_t fex_skip( fex_t*, long n );
/** Points *out at current file's data in memory. Pointer is valid until
fex_next(), fex_rewind(), fex_seek_arc(), or fex_close() is called. Pointer

View File

@ -20,7 +20,8 @@ Archive::Archive() : Raw( this )
bool Archive::IsSignature(byte *D)
{
bool Valid=false;
if (D[0]==0x52) {
if (D[0]==0x52)
{
#ifndef SFX_MODULE
if (D[1]==0x45 && D[2]==0x7e && D[3]==0x5e)
{

View File

@ -9,7 +9,7 @@ class Archive:public File
private:
bool IsSignature(byte *D);
void ConvertUnknownHeader();
long ReadOldHeader();
int ReadOldHeader();
RawRead Raw;

View File

@ -216,7 +216,7 @@ unrar_err_t Archive::ReadHeader()
// Rar.Read()s are checked by caller of ReadOldHeader() (see above)
#ifndef SFX_MODULE
long Archive::ReadOldHeader()
int Archive::ReadOldHeader()
{
Raw.Reset();
if (CurBlockPos<=SFXSize)

View File

@ -5,18 +5,18 @@ template <class T> class Array
{
private:
T *Buffer;
long BufSize;
long AllocSize;
int BufSize;
int AllocSize;
public:
Rar_Error_Handler& ErrHandler;
Array(Rar_Error_Handler*);
Array(long Size,Rar_Error_Handler*);
Array(int Size,Rar_Error_Handler*);
~Array();
inline void CleanData();
inline T& operator [](long Item);
inline long Size();
void Add(long Items);
void Alloc(long Items);
inline T& operator [](int Item);
inline int Size();
void Add(int Items);
void Alloc(int Items);
void Reset();
void operator = (Array<T> &Src);
void Push(T Item);
@ -37,7 +37,7 @@ template <class T> Array<T>::Array(Rar_Error_Handler* eh) : ErrHandler( *eh )
}
template <class T> Array<T>::Array(long Size, Rar_Error_Handler* eh) : ErrHandler( *eh )
template <class T> Array<T>::Array(int Size, Rar_Error_Handler* eh) : ErrHandler( *eh )
{
Buffer=(T *)rarmalloc(sizeof(T)*Size);
if (Buffer==NULL && Size!=0)
@ -54,28 +54,28 @@ template <class T> Array<T>::~Array()
}
template <class T> inline T& Array<T>::operator [](long Item)
template <class T> inline T& Array<T>::operator [](int Item)
{
return(Buffer[Item]);
}
template <class T> inline long Array<T>::Size()
template <class T> inline int Array<T>::Size()
{
return(BufSize);
}
template <class T> void Array<T>::Add(long Items)
template <class T> void Array<T>::Add(int Items)
{
long BufSize = this->BufSize; // don't change actual vars until alloc succeeds
T* Buffer = this->Buffer;
int BufSize = this->BufSize; // don't change actual vars until alloc succeeds
T* Buffer = this->Buffer;
BufSize+=Items;
if (BufSize>AllocSize)
{
long Suggested=AllocSize+AllocSize/4+32;
long NewSize=Max(BufSize,Suggested);
int Suggested=AllocSize+AllocSize/4+32;
int NewSize=Max(BufSize,Suggested);
Buffer=(T *)rarrealloc(Buffer,NewSize*sizeof(T));
if (Buffer==NULL)
@ -88,7 +88,7 @@ template <class T> void Array<T>::Add(long Items)
}
template <class T> void Array<T>::Alloc(long Items)
template <class T> void Array<T>::Alloc(int Items)
{
if (Items>AllocSize)
Add(Items-BufSize);

View File

@ -29,7 +29,7 @@ void RangeCoder::InitDecoder(Unpack *UnpackRead)
}
inline long RangeCoder::GetCurrentCount()
inline int RangeCoder::GetCurrentCount()
{
return (code-low)/(range /= SubRange.scale);
}

View File

@ -8,7 +8,7 @@ class RangeCoder
{
public:
void InitDecoder(Unpack *UnpackRead);
inline long GetCurrentCount();
inline int GetCurrentCount();
inline uint GetCurrentShiftCount(uint SHIFT);
inline void Decode();
inline void PutChar(unsigned int c);

View File

@ -95,10 +95,10 @@ unrar_err_t CmdExtract::ExtractCurrentFile( bool SkipSolid, bool check_compatibi
void CmdExtract::UnstoreFile(Int64 DestUnpSize)
{
Buffer.Alloc(Min(DestUnpSize,0x10000));
Buffer.Alloc((int)Min(DestUnpSize,0x10000));
while (1)
{
uint Code=DataIO.UnpRead(&Buffer[0],Buffer.Size());
unsigned int Code=DataIO.UnpRead(&Buffer[0],Buffer.Size());
if (Code==0 || (int)Code==-1)
break;
Code=Code<DestUnpSize ? Code:int64to32(DestUnpSize);

View File

@ -22,7 +22,7 @@ void BitInput::handle_mem_error( Rar_Error_Handler& ErrHandler )
ErrHandler.MemoryError();
}
void BitInput::faddbits(long Bits)
void BitInput::faddbits(int Bits)
{
addbits(Bits);
}

View File

@ -19,7 +19,7 @@ public:
{
InAddr=InBit=0;
}
void addbits(long Bits)
void addbits(int Bits)
{
Bits+=InBit;
InAddr+=Bits>>3;
@ -27,13 +27,13 @@ public:
}
unsigned int getbits()
{
uint BitField=(uint)InBuf[InAddr] << 16;
unsigned int BitField=(uint)InBuf[InAddr] << 16;
BitField|=(uint)InBuf[InAddr+1] << 8;
BitField|=(uint)InBuf[InAddr+2];
BitField >>= (8-InBit);
return(BitField & 0xffff);
}
void faddbits(long Bits);
void faddbits(int Bits);
unsigned int fgetbits();
bool Overflow(int IncPtr) {return(InAddr+IncPtr>=MAX_SIZE);}
};

View File

@ -399,7 +399,7 @@ inline bool PPM_CONTEXT::decodeSymbol1(ModelPPM *Model)
Model->Coder.SubRange.scale=U.SummFreq;
STATE* p=U.Stats;
int i, HiCnt;
long count=Model->Coder.GetCurrentCount();
int count=Model->Coder.GetCurrentCount();
if (count>=Model->Coder.SubRange.scale)
return(false);
if (count < (HiCnt=p->Freq))
@ -450,7 +450,7 @@ inline void PPM_CONTEXT::update2(ModelPPM *Model,STATE* p)
}
inline SEE2_CONTEXT* PPM_CONTEXT::makeEscFreq2(ModelPPM *Model,long Diff)
inline SEE2_CONTEXT* PPM_CONTEXT::makeEscFreq2(ModelPPM *Model,int Diff)
{
SEE2_CONTEXT* psee2c;
if (NumStats != 256)
@ -474,7 +474,7 @@ inline SEE2_CONTEXT* PPM_CONTEXT::makeEscFreq2(ModelPPM *Model,long Diff)
inline bool PPM_CONTEXT::decodeSymbol2(ModelPPM *Model)
{
long count, HiCnt, i=NumStats-Model->NumMasked;
int count, HiCnt, i=NumStats-Model->NumMasked;
SEE2_CONTEXT* psee2c=makeEscFreq2(Model,i);
STATE* ps[256], ** pps=ps, * p=U.Stats-1;
HiCnt=0;

View File

@ -75,7 +75,7 @@ struct PPM_CONTEXT
inline void update2(ModelPPM *Model,STATE* p); // BCDE successor
void rescale(ModelPPM *Model);
inline PPM_CONTEXT* createChild(ModelPPM *Model,STATE* pStats,STATE& FirstState);
inline SEE2_CONTEXT* makeEscFreq2(ModelPPM *Model,long Diff);
inline SEE2_CONTEXT* makeEscFreq2(ModelPPM *Model,int Diff);
};
#ifndef STRICT_ALIGNMENT_REQUIRED

View File

@ -96,6 +96,10 @@ struct Rar_Allocator
#define PRESENT_INT32
#endif
typedef unsigned char byte; //8 bits
typedef unsigned short ushort; //preferably 16 bits, but can be more
typedef unsigned int uint; //32 bits or more
typedef blargg_wchar_t wchar;
#define SHORT16(x) (sizeof(ushort)==2 ? (ushort)(x):((x)&0xffff))
@ -123,7 +127,7 @@ ushort OldCRC(ushort StartCRC,const void *Addr,size_t Size);
//// rartime.hpp
struct RarTime
{
uint time;
unsigned time;
void SetDos(uint DosTime) { time = DosTime; }
};
@ -145,8 +149,8 @@ private:
bool SkipUnpCRC;
public:
long UnpRead(byte *Addr,long Count);
void UnpWrite(byte *Addr,long Count);
int UnpRead(byte *Addr,uint Count);
void UnpWrite(byte *Addr,uint Count);
void SetSkipUnpCRC( bool b ) { SkipUnpCRC = b; }
void SetPackedSizeToRead( Int64 n ) { UnpPackedSize = n; }
@ -154,7 +158,7 @@ public:
void Seek(Int64 Offset, int Method = 0 ) { (void)Method; Tell_ = Offset; }
Int64 Tell() { return Tell_; }
long Read( void* p, long n );
int Read( void* p, int n );
};
//// rar.hpp

View File

@ -139,10 +139,10 @@ inline uint* RarVM::GetOperand(VM_PreparedOperand *CmdOp)
void RarVM::Execute(VM_PreparedProgram *Prg)
{
memcpy(R,Prg->InitR,sizeof(Prg->InitR));
uint GlobalSize=Min(Prg->GlobalData.Size(),VM_GLOBALMEMSIZE);
unsigned int GlobalSize=Min(Prg->GlobalData.Size(),VM_GLOBALMEMSIZE);
if (GlobalSize)
memcpy(Mem+VM_GLOBALMEMADDR,&Prg->GlobalData[0],GlobalSize);
uint StaticSize=Min(Prg->StaticData.Size(),VM_GLOBALMEMSIZE-GlobalSize);
unsigned int StaticSize=Min(Prg->StaticData.Size(),VM_GLOBALMEMSIZE-GlobalSize);
if (StaticSize)
memcpy(Mem+VM_GLOBALMEMADDR+GlobalSize,&Prg->StaticData[0],StaticSize);
@ -185,7 +185,7 @@ Note:
return(false); \
Cmd=PreparedCode+(IP);
bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,long CodeSize)
bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize)
{
int MaxOpCount=25000000;
VM_PreparedCommand *Cmd=PreparedCode;
@ -399,7 +399,7 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,long CodeSize)
break;
case VM_CALL:
R[7]-=4;
SET_VALUE(false,(uint *)&Mem[R[7]&VM_MEMMASK],Cmd-PreparedCode+1);
SET_VALUE(false,(uint *)&Mem[R[7]&VM_MEMMASK],(uint)(Cmd-PreparedCode+1));
SET_IP(GET_VALUE(false,Op1));
continue;
case VM_NOT:
@ -449,8 +449,8 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,long CodeSize)
#endif
case VM_PUSHA:
{
const uint RegCount=sizeof(R)/sizeof(R[0]);
for (uint I=0,SP=R[7]-4;I<RegCount;I++,SP-=4)
const int RegCount=sizeof(R)/sizeof(R[0]);
for (int I=0,SP=R[7]-4;I<RegCount;I++,SP-=4)
SET_VALUE(false,(uint *)&Mem[SP & VM_MEMMASK],R[I]);
R[7]-=RegCount*4;
}
@ -544,7 +544,7 @@ bool RarVM::ExecuteCode(VM_PreparedCommand *PreparedCode,long CodeSize)
void RarVM::Prepare(byte *Code,long CodeSize,VM_PreparedProgram *Prg)
void RarVM::Prepare(byte *Code,int CodeSize,VM_PreparedProgram *Prg)
{
InitBitInput();
memcpy(InBuf,Code,Min(CodeSize,BitInput::MAX_SIZE));
@ -583,7 +583,7 @@ void RarVM::Prepare(byte *Code,long CodeSize,VM_PreparedProgram *Prg)
if (DataFlag&0x8000)
{
uint DataSize=ReadData(*this)+1;
int DataSize=ReadData(*this)+1;
for (int I=0;InAddr<CodeSize && I<DataSize;I++)
{
Prg->StaticData.Add(1);
@ -627,7 +627,7 @@ void RarVM::Prepare(byte *Code,long CodeSize,VM_PreparedProgram *Prg)
if (CurCmd->Op1.Type==VM_OPINT && (VM_CmdFlags[CurCmd->OpCode]&(VMCF_JUMP|VMCF_PROC)))
{
// Calculating jump distance.
long Distance=CurCmd->Op1.Data;
int Distance=CurCmd->Op1.Data;
if (Distance>=256)
Distance-=256;
else
@ -773,7 +773,7 @@ uint RarVM::ReadData(BitInput &Inp)
}
void RarVM::SetMemory(uint Pos,byte *Data,uint DataSize)
void RarVM::SetMemory(unsigned int Pos,byte *Data,unsigned int DataSize)
{
if (Pos<VM_MEMSIZE && Data!=Mem+Pos)
memmove(Mem+Pos,Data,Min(DataSize,VM_MEMSIZE-Pos));
@ -854,7 +854,7 @@ void RarVM::Optimize(VM_PreparedProgram *Prg)
#ifdef VM_STANDARDFILTERS
VM_StandardFilters RarVM::IsStandardFilter(byte *Code,long CodeSize)
VM_StandardFilters RarVM::IsStandardFilter(byte *Code,int CodeSize)
{
static const
struct StandardFilterSignature
@ -895,7 +895,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
case VMSF_E8E9:
{
byte *Data=Mem;
long DataSize=R[4];
int DataSize=R[4];
uint FileOffset=R[6];
if (DataSize>=VM_GLOBALMEMADDR || DataSize<4)
@ -910,8 +910,8 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
if (CurByte==0xe8 || CurByte==CmpByte2)
{
#ifdef PRESENT_INT32
sint32 Offset=(sint32)(CurPos+FileOffset);
sint32 Addr=(sint32)(GET_VALUE(false,Data));
sint32 Offset=CurPos+FileOffset;
sint32 Addr=GET_VALUE(false,Data);
if (Addr<0)
{
if (Addr+Offset>=0)
@ -941,7 +941,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
case VMSF_ITANIUM:
{
byte *Data=Mem;
long DataSize=R[4];
int DataSize=R[4];
uint FileOffset=R[6];
if (DataSize>=VM_GLOBALMEMADDR || DataSize<21)
@ -980,7 +980,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
break;
case VMSF_DELTA:
{
long DataSize=R[4],Channels=R[0],SrcPos=0,Border=DataSize*2;
int DataSize=R[4],Channels=R[0],SrcPos=0,Border=DataSize*2;
SET_VALUE(false,&Mem[VM_GLOBALMEMADDR+0x20],DataSize);
if (DataSize>=VM_GLOBALMEMADDR/2)
break;
@ -990,14 +990,14 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
for (int CurChannel=0;CurChannel<Channels;CurChannel++)
{
byte PrevByte=0;
for (long DestPos=DataSize+CurChannel;DestPos<Border;DestPos+=Channels)
for (int DestPos=DataSize+CurChannel;DestPos<Border;DestPos+=Channels)
Mem[DestPos]=(PrevByte-=Mem[SrcPos++]);
}
}
break;
case VMSF_RGB:
{
long DataSize=R[4],Width=R[0]-3,PosR=R[1];
int DataSize=R[4],Width=R[0]-3,PosR=R[1];
byte *SrcData=Mem,*DestData=SrcData+DataSize;
const int Channels=3;
SET_VALUE(false,&Mem[VM_GLOBALMEMADDR+0x20],DataSize);
@ -1010,7 +1010,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
for (int I=CurChannel;I<DataSize;I+=Channels)
{
unsigned int Predicted;
long UpperPos=I-Width;
int UpperPos=I-Width;
if (UpperPos>=3)
{
byte *UpperData=DestData+UpperPos;
@ -1033,7 +1033,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
DestData[I]=PrevByte=(byte)(Predicted-*(SrcData++));
}
}
for (long I=PosR,Border=DataSize-2;I<Border;I+=3)
for (int I=PosR,Border=DataSize-2;I<Border;I+=3)
{
byte G=DestData[I+1];
DestData[I]+=G;
@ -1043,7 +1043,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
break;
case VMSF_AUDIO:
{
long DataSize=R[4],Channels=R[0];
int DataSize=R[4],Channels=R[0];
byte *SrcData=Mem,*DestData=SrcData+DataSize;
SET_VALUE(false,&Mem[VM_GLOBALMEMADDR+0x20],DataSize);
if (DataSize>=VM_GLOBALMEMADDR/2)
@ -1110,7 +1110,7 @@ void RarVM::ExecuteStandardFilter(VM_StandardFilters FilterType)
break;
case VMSF_UPCASE:
{
long DataSize=R[4],SrcPos=0,DestPos=DataSize;
int DataSize=R[4],SrcPos=0,DestPos=DataSize;
if (DataSize>=VM_GLOBALMEMADDR/2)
break;
while (SrcPos<DataSize)
@ -1134,7 +1134,7 @@ unsigned int RarVM::FilterItanium_GetBits(byte *Data,int BitPos,int BitCount)
{
int InAddr=BitPos/8;
int InBit=BitPos&7;
uint BitField=(uint)Data[InAddr++];
unsigned int BitField=(uint)Data[InAddr++];
BitField|=(uint)Data[InAddr++] << 8;
BitField|=(uint)Data[InAddr++] << 16;
BitField|=(uint)Data[InAddr] << 24;

View File

@ -71,7 +71,7 @@ struct VM_PreparedProgram
uint InitR[7];
byte *FilteredData;
uint FilteredDataSize;
unsigned int FilteredDataSize;
};
class RarVM:private BitInput
@ -84,9 +84,9 @@ class RarVM:private BitInput
#ifdef VM_OPTIMIZE
void Optimize(VM_PreparedProgram *Prg);
#endif
bool ExecuteCode(VM_PreparedCommand *PreparedCode,long CodeSize);
bool ExecuteCode(VM_PreparedCommand *PreparedCode,int CodeSize);
#ifdef VM_STANDARDFILTERS
VM_StandardFilters IsStandardFilter(byte *Code,long CodeSize);
VM_StandardFilters IsStandardFilter(byte *Code,int CodeSize);
void ExecuteStandardFilter(VM_StandardFilters FilterType);
unsigned int FilterItanium_GetBits(byte *Data,int BitPos,int BitCount);
void FilterItanium_SetBits(byte *Data,unsigned int BitField,int BitPos,
@ -102,10 +102,10 @@ class RarVM:private BitInput
void Init();
void handle_mem_error( Rar_Error_Handler& );
friend class Unpack;
void Prepare(byte *Code,long CodeSize,VM_PreparedProgram *Prg);
void Prepare(byte *Code,int CodeSize,VM_PreparedProgram *Prg);
void Execute(VM_PreparedProgram *Prg);
void SetLowEndianValue(uint *Addr,uint Value);
void SetMemory(uint Pos,byte *Data,uint DataSize);
void SetMemory(unsigned int Pos,byte *Data,unsigned int DataSize);
static uint ReadData(BitInput &Inp);
};

View File

@ -14,7 +14,7 @@ void RawRead::Reset()
Data.Reset();
}
void RawRead::Read(long Size)
void RawRead::Read(int Size)
{
// (removed decryption)
if (Size!=0)

View File

@ -6,20 +6,20 @@ class RawRead
private:
Array<byte> Data;
File *SrcFile;
long DataSize;
long ReadPos;
int DataSize;
int ReadPos;
friend class Archive;
public:
RawRead(File *SrcFile);
void Reset();
void Read(long Size);
void Read(int Size);
void Get(byte &Field);
void Get(ushort &Field);
void Get(uint &Field);
void Get(byte *Field,int Size);
uint GetCRC(bool ProcessedOnly);
long Size() {return DataSize;}
long PaddedSize() {return Data.Size()-DataSize;}
int Size() {return DataSize;}
int PaddedSize() {return Data.Size()-DataSize;}
};
#endif

View File

@ -19,14 +19,14 @@ void SubAllocator::Clean()
}
inline void SubAllocator::InsertNode(void* p,long indx)
inline void SubAllocator::InsertNode(void* p,int indx)
{
((RAR_NODE*) p)->next=FreeList[indx].next;
FreeList[indx].next=(RAR_NODE*) p;
}
inline void* SubAllocator::RemoveNode(long indx)
inline void* SubAllocator::RemoveNode(int indx)
{
RAR_NODE* RetVal=FreeList[indx].next;
FreeList[indx].next=RetVal->next;
@ -34,7 +34,7 @@ inline void* SubAllocator::RemoveNode(long indx)
}
inline uint SubAllocator::U2B(long NU)
inline uint SubAllocator::U2B(int NU)
{
return /*8*NU+4*NU*/UNIT_SIZE*NU;
}
@ -44,13 +44,13 @@ inline uint SubAllocator::U2B(long NU)
calculate RAR_MEM_BLK + Items address. Real RAR_MEM_BLK size must be
equal to UNIT_SIZE, so we cannot just add Items to RAR_MEM_BLK address
*/
inline RAR_MEM_BLK* SubAllocator::MBPtr(RAR_MEM_BLK *BasePtr,long Items)
inline RAR_MEM_BLK* SubAllocator::MBPtr(RAR_MEM_BLK *BasePtr,int Items)
{
return((RAR_MEM_BLK*)( ((byte *)(BasePtr))+U2B(Items) ));
}
inline void SubAllocator::SplitBlock(void* pv,long OldIndx,long NewIndx)
inline void SubAllocator::SplitBlock(void* pv,int OldIndx,int NewIndx)
{
int i, UDiff=Indx2Units[OldIndx]-Indx2Units[NewIndx];
byte* p=((byte*) pv)+U2B(Indx2Units[NewIndx]);
@ -76,7 +76,7 @@ void SubAllocator::StopSubAllocator()
}
bool SubAllocator::StartSubAllocator(long SASize)
bool SubAllocator::StartSubAllocator(int SASize)
{
uint t=SASize << 20;
if (SubAllocatorSize == t)
@ -102,9 +102,9 @@ void SubAllocator::InitSubAllocator()
int i, k;
memset(FreeList,0,sizeof(FreeList));
pText=HeapStart;
uint Size2=FIXED_UNIT_SIZE*(SubAllocatorSize/8/FIXED_UNIT_SIZE*7);
uint Size2=(uint)(FIXED_UNIT_SIZE*(SubAllocatorSize/8/FIXED_UNIT_SIZE*7));
uint RealSize2=Size2/FIXED_UNIT_SIZE*UNIT_SIZE;
uint Size1=SubAllocatorSize-Size2;
uint Size1=(uint)(SubAllocatorSize-Size2);
uint RealSize1=Size1/FIXED_UNIT_SIZE*UNIT_SIZE+Size1%FIXED_UNIT_SIZE;
#ifdef STRICT_ALIGNMENT_REQUIRED
if (Size1%FIXED_UNIT_SIZE!=0)
@ -163,7 +163,7 @@ inline void SubAllocator::GlueFreeBlocks()
}
}
void* SubAllocator::AllocUnitsRare(long indx)
void* SubAllocator::AllocUnitsRare(int indx)
{
if ( !GlueCount )
{
@ -172,7 +172,7 @@ void* SubAllocator::AllocUnitsRare(long indx)
if ( FreeList[indx].next )
return RemoveNode(indx);
}
long i=indx;
int i=indx;
do
{
if (++i == N_INDEXES)
@ -195,7 +195,7 @@ void* SubAllocator::AllocUnitsRare(long indx)
}
inline void* SubAllocator::AllocUnits(long NU)
inline void* SubAllocator::AllocUnits(int NU)
{
int indx=Units2Indx[NU-1];
if ( FreeList[indx].next )
@ -219,7 +219,7 @@ void* SubAllocator::AllocContext()
}
void* SubAllocator::ExpandUnits(void* OldPtr,long OldNU)
void* SubAllocator::ExpandUnits(void* OldPtr,int OldNU)
{
int i0=Units2Indx[OldNU-1], i1=Units2Indx[OldNU-1+1];
if (i0 == i1)
@ -234,7 +234,7 @@ void* SubAllocator::ExpandUnits(void* OldPtr,long OldNU)
}
void* SubAllocator::ShrinkUnits(void* OldPtr,long OldNU,long NewNU)
void* SubAllocator::ShrinkUnits(void* OldPtr,int OldNU,int NewNU)
{
int i0=Units2Indx[OldNU-1], i1=Units2Indx[NewNU-1];
if (i0 == i1)
@ -254,7 +254,7 @@ void* SubAllocator::ShrinkUnits(void* OldPtr,long OldNU,long NewNU)
}
void SubAllocator::FreeUnits(void* ptr,long OldNU)
void SubAllocator::FreeUnits(void* ptr,int OldNU)
{
InsertNode(ptr,Units2Indx[OldNU-1]);
}

View File

@ -53,14 +53,14 @@ struct RAR_NODE
class SubAllocator
{
private:
inline void InsertNode(void* p,long indx);
inline void* RemoveNode(long indx);
inline uint U2B(long NU);
inline void SplitBlock(void* pv,long OldIndx,long NewIndx);
inline void InsertNode(void* p,int indx);
inline void* RemoveNode(int indx);
inline uint U2B(int NU);
inline void SplitBlock(void* pv,int OldIndx,int NewIndx);
uint GetUsedMemory();
inline void GlueFreeBlocks();
void* AllocUnitsRare(long indx);
inline RAR_MEM_BLK* MBPtr(RAR_MEM_BLK *BasePtr,long Items);
void* AllocUnitsRare(int indx);
inline RAR_MEM_BLK* MBPtr(RAR_MEM_BLK *BasePtr,int Items);
long SubAllocatorSize;
byte Indx2Units[N_INDEXES], Units2Indx[128], GlueCount;
@ -71,14 +71,14 @@ class SubAllocator
SubAllocator();
~SubAllocator() {StopSubAllocator();}
void Clean();
bool StartSubAllocator(long SASize);
bool StartSubAllocator(int SASize);
void StopSubAllocator();
void InitSubAllocator();
inline void* AllocContext();
inline void* AllocUnits(long NU);
inline void* ExpandUnits(void* ptr,long OldNU);
inline void* ShrinkUnits(void* ptr,long OldNU,long NewNU);
inline void FreeUnits(void* ptr,long OldNU);
inline void* AllocUnits(int NU);
inline void* ExpandUnits(void* ptr,int OldNU);
inline void* ShrinkUnits(void* ptr,int OldNU,int NewNU);
inline void FreeUnits(void* ptr,int OldNU);
long GetAllocatedMemory() {return(SubAllocatorSize);};
byte *pText, *UnitsStart,*HeapEnd,*FakeUnitsStart;

View File

@ -78,7 +78,7 @@ void Unpack::DoUnpack(int Method,bool Solid)
}
inline void Unpack::InsertOldDist(uint Distance)
inline void Unpack::InsertOldDist(unsigned int Distance)
{
OldDist[3]=OldDist[2];
OldDist[2]=OldDist[1];
@ -87,7 +87,7 @@ inline void Unpack::InsertOldDist(uint Distance)
}
inline void Unpack::InsertLastMatch(uint Length,uint Distance)
inline void Unpack::InsertLastMatch(unsigned int Length,unsigned int Distance)
{
LastDist=Distance;
LastLength=Length;
@ -95,12 +95,12 @@ inline void Unpack::InsertLastMatch(uint Length,uint Distance)
// These optimizations give 22% speedup on x86, 44% speedup on PowerPC
void Unpack::CopyString(uint Length,uint Distance)
void Unpack::CopyString(unsigned int Length,unsigned int Distance)
{
uint UnpPtr = this->UnpPtr; // cache in register
unsigned UnpPtr = this->UnpPtr; // cache in register
byte* const Window = this->Window; // cache in register
uint DestPtr=UnpPtr-Distance;
unsigned int DestPtr=UnpPtr-Distance;
if (UnpPtr<MAXWINSIZE-260 && DestPtr<MAXWINSIZE-260)
{
this->UnpPtr += Length;
@ -132,7 +132,7 @@ void Unpack::CopyString(uint Length,uint Distance)
}
long Unpack::DecodeNumber(struct Decode *Dec)
int Unpack::DecodeNumber(struct Decode *Dec)
{
unsigned int Bits;
unsigned int BitField=getbits() & 0xfffe;
@ -180,7 +180,7 @@ long Unpack::DecodeNumber(struct Decode *Dec)
else
Bits=15;
uint N=Dec->DecodePos[Bits]+((BitField-Dec->DecodeLen[Bits-1])>>(16-Bits));
unsigned int N=Dec->DecodePos[Bits]+((BitField-Dec->DecodeLen[Bits-1])>>(16-Bits));
if (N>=Dec->MaxNum)
N=0;
// do after reading values, to allow better instruction scheduling
@ -320,7 +320,7 @@ void Unpack::Unpack29(bool Solid)
continue;
}
long Number=DecodeNumber((struct Decode *)&LD);
int Number=DecodeNumber((struct Decode *)&LD);
if (Number<256)
{
Window[UnpPtr++]=(byte)Number;
@ -335,8 +335,8 @@ void Unpack::Unpack29(bool Solid)
addbits(Bits);
}
long DistNumber=DecodeNumber((struct Decode *)&DD);
uint Distance=DDecode[DistNumber]+1;
int DistNumber=DecodeNumber((struct Decode *)&DD);
unsigned int Distance=DDecode[DistNumber]+1;
if ((Bits=DBits[DistNumber])>0)
{
if (DistNumber>9)
@ -353,7 +353,7 @@ void Unpack::Unpack29(bool Solid)
}
else
{
long LowDist=DecodeNumber((struct Decode *)&LDD);
int LowDist=DecodeNumber((struct Decode *)&LDD);
if (LowDist==16)
{
LowDistRepCount=LOW_DIST_REP_COUNT-1;
@ -405,14 +405,14 @@ void Unpack::Unpack29(bool Solid)
}
if (Number<263)
{
long DistNum=Number-259;
uint Distance=OldDist[DistNum];
for (long I=DistNum;I>0;I--)
int DistNum=Number-259;
unsigned int Distance=OldDist[DistNum];
for (int I=DistNum;I>0;I--)
OldDist[I]=OldDist[I-1];
OldDist[0]=Distance;
long LengthNumber=DecodeNumber((struct Decode *)&RD);
long Length=LDecode[LengthNumber]+2;
int LengthNumber=DecodeNumber((struct Decode *)&RD);
int Length=LDecode[LengthNumber]+2;
if ((Bits=LBits[LengthNumber])>0)
{
Length+=getbits()>>(16-Bits);
@ -524,7 +524,7 @@ bool Unpack::ReadVMCodePPM()
}
bool Unpack::AddVMCode(uint FirstByte,byte *Code,long CodeSize)
bool Unpack::AddVMCode(unsigned int FirstByte,byte *Code,int CodeSize)
{
// TODO: auto clear object to free bit input on normal return?
Inp.InitBitInput();
@ -595,7 +595,7 @@ bool Unpack::AddVMCode(uint FirstByte,byte *Code,long CodeSize)
PrgStack.Add(1);
EmptyCount=1;
}
long StackPos=PrgStack.Size()-EmptyCount;
int StackPos=PrgStack.Size()-EmptyCount;
PrgStack[StackPos]=StackFilter;
LastStackFilter = NULL;
StackFilter->ExecCount=Filter->ExecCount;
@ -647,7 +647,7 @@ bool Unpack::AddVMCode(uint FirstByte,byte *Code,long CodeSize)
StackFilter->Prg.AltCmd=&Filter->Prg.Cmd[0];
StackFilter->Prg.CmdCount=Filter->Prg.CmdCount;
long StaticDataSize=Filter->Prg.StaticData.Size();
int StaticDataSize=Filter->Prg.StaticData.Size();
if (StaticDataSize>0 && StaticDataSize<VM_GLOBALMEMSIZE)
{
// read statically defined data contained in DB commands
@ -675,7 +675,7 @@ bool Unpack::AddVMCode(uint FirstByte,byte *Code,long CodeSize)
uint DataSize=RarVM::ReadData(Inp);
if (DataSize>VM_GLOBALMEMSIZE-VM_FIXEDGLOBALSIZE)
return(false);
uint CurSize=StackFilter->Prg.GlobalData.Size();
unsigned int CurSize=StackFilter->Prg.GlobalData.Size();
if (CurSize<DataSize+VM_FIXEDGLOBALSIZE)
StackFilter->Prg.GlobalData.Add(DataSize+VM_FIXEDGLOBALSIZE-CurSize);
byte *GlobalData=&StackFilter->Prg.GlobalData[VM_FIXEDGLOBALSIZE];
@ -694,7 +694,7 @@ bool Unpack::AddVMCode(uint FirstByte,byte *Code,long CodeSize)
bool Unpack::UnpReadBuf()
{
long DataSize=ReadTop-InAddr;
int DataSize=ReadTop-InAddr;
if (DataSize<0)
return(false);
if (InAddr>BitInput::MAX_SIZE/2)
@ -706,7 +706,7 @@ bool Unpack::UnpReadBuf()
}
else
DataSize=ReadTop;
long ReadCode=UnpIO->UnpRead(InBuf+DataSize,(BitInput::MAX_SIZE-DataSize)&~0xf);
int ReadCode=UnpIO->UnpRead(InBuf+DataSize,(BitInput::MAX_SIZE-DataSize)&~0xf);
if (ReadCode>0)
ReadTop+=ReadCode;
ReadBorder=ReadTop-30;
@ -716,8 +716,8 @@ bool Unpack::UnpReadBuf()
void Unpack::UnpWriteBuf()
{
uint WrittenBorder=WrPtr;
uint WriteSize=(UnpPtr-WrittenBorder)&MAXWINMASK;
unsigned int WrittenBorder=WrPtr;
unsigned int WriteSize=(UnpPtr-WrittenBorder)&MAXWINMASK;
for (int I=0;I<PrgStack.Size();I++)
{
UnpackFilter *flt=PrgStack[I];
@ -728,8 +728,8 @@ void Unpack::UnpWriteBuf()
flt->NextWindow=false;
continue;
}
uint BlockStart=flt->BlockStart;
uint BlockLength=flt->BlockLength;
unsigned int BlockStart=flt->BlockStart;
unsigned int BlockLength=flt->BlockLength;
if (((BlockStart-WrittenBorder)&MAXWINMASK)<WriteSize)
{
if (WrittenBorder!=BlockStart)
@ -740,12 +740,12 @@ void Unpack::UnpWriteBuf()
}
if (BlockLength<=WriteSize)
{
uint BlockEnd=(BlockStart+BlockLength)&MAXWINMASK;
unsigned int BlockEnd=(BlockStart+BlockLength)&MAXWINMASK;
if (BlockStart<BlockEnd || BlockEnd==0)
VM.SetMemory(0,Window+BlockStart,BlockLength);
else
{
uint FirstPartLength=MAXWINSIZE-BlockStart;
unsigned int FirstPartLength=MAXWINSIZE-BlockStart;
VM.SetMemory(0,Window+BlockStart,FirstPartLength);
VM.SetMemory(FirstPartLength,Window,BlockEnd);
}
@ -773,7 +773,7 @@ void Unpack::UnpWriteBuf()
ParentPrg->GlobalData.Reset();
byte *FilteredData=Prg->FilteredData;
uint FilteredDataSize=Prg->FilteredDataSize;
unsigned int FilteredDataSize=Prg->FilteredDataSize;
delete PrgStack[I];
PrgStack[I]=NULL;
@ -853,7 +853,7 @@ void Unpack::ExecuteCode(VM_PreparedProgram *Prg)
}
void Unpack::UnpWriteArea(uint StartPtr,uint EndPtr)
void Unpack::UnpWriteArea(unsigned int StartPtr,unsigned int EndPtr)
{
if (EndPtr!=StartPtr)
UnpSomeRead=true;
@ -868,11 +868,11 @@ void Unpack::UnpWriteArea(uint StartPtr,uint EndPtr)
}
void Unpack::UnpWriteData(byte *Data,long Size)
void Unpack::UnpWriteData(byte *Data,int Size)
{
if (WrittenFileSize>=DestUnpSize)
return;
long WriteSize=Size;
int WriteSize=Size;
Int64 LeftToWrite=DestUnpSize-WrittenFileSize;
if (WriteSize>LeftToWrite)
WriteSize=int64to32(LeftToWrite);
@ -928,13 +928,13 @@ bool Unpack::ReadTables()
}
MakeDecodeTables(BitLength,(struct Decode *)&BD,BC);
const long TableSize=HUFF_TABLE_SIZE;
for (long I=0;I<TableSize;)
const int TableSize=HUFF_TABLE_SIZE;
for (int I=0;I<TableSize;)
{
if (InAddr>ReadTop-5)
if (!UnpReadBuf())
return(false);
long Number=DecodeNumber((struct Decode *)&BD);
int Number=DecodeNumber((struct Decode *)&BD);
if (Number<16)
{
Table[I]=(Number+UnpOldTable[I]) & 0xf;
@ -1038,9 +1038,9 @@ void Unpack::InitFilters()
}
void Unpack::MakeDecodeTables(unsigned char *LenTab,struct Decode *Dec,long Size)
void Unpack::MakeDecodeTables(unsigned char *LenTab,struct Decode *Dec,int Size)
{
long LenCount[16],TmpPos[16],I;
int LenCount[16],TmpPos[16],I;
long M,N;
memset(LenCount,0,sizeof(LenCount));
memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));

View File

@ -5,63 +5,63 @@ enum BLOCK_TYPES {BLOCK_LZ,BLOCK_PPM};
struct Decode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[2];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[2];
};
struct LitDecode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[NC];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[NC];
};
struct DistDecode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[DC];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[DC];
};
struct LowDistDecode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[LDC];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[LDC];
};
struct RepDecode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[RC];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[RC];
};
struct BitDecode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[BC];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[BC];
};
struct UnpackFilter
: Rar_Allocator
{
unsigned long BlockStart;
unsigned long BlockLength;
unsigned long ExecCount;
unsigned int BlockStart;
unsigned int BlockLength;
unsigned int ExecCount;
bool NextWindow;
// position of parent filter in Filters array used as prototype for filter
// in PrgStack array. Not defined for filters in Filters array.
unsigned long ParentFilter;
unsigned int ParentFilter;
VM_PreparedProgram Prg;
UnpackFilter( Rar_Error_Handler* eh ) : Prg( eh ) { }
@ -70,10 +70,10 @@ struct UnpackFilter
/***************************** Unpack v 2.0 *********************************/
struct MultDecode
{
uint MaxNum;
uint DecodeLen[16];
uint DecodePos[16];
uint DecodeNum[MC20];
unsigned int MaxNum;
unsigned int DecodeLen[16];
unsigned int DecodePos[16];
unsigned int DecodeNum[MC20];
};
struct AudioVariables
@ -81,9 +81,9 @@ struct AudioVariables
int K1,K2,K3,K4,K5;
int D1,D2,D3,D4;
int LastDelta;
uint Dif[11];
uint ByteCount;
long LastChar;
unsigned int Dif[11];
unsigned int ByteCount;
int LastChar;
};
/***************************** Unpack v 2.0 *********************************/
@ -98,20 +98,20 @@ private:
bool UnpReadBuf();
void UnpWriteBuf();
void ExecuteCode(VM_PreparedProgram *Prg);
void UnpWriteArea(uint StartPtr,uint EndPtr);
void UnpWriteData(byte *Data,long Size);
void UnpWriteArea(unsigned int StartPtr,unsigned int EndPtr);
void UnpWriteData(byte *Data,int Size);
bool ReadTables();
void MakeDecodeTables(unsigned char *LenTab,struct Decode *Dec,long Size);
long DecodeNumber(struct Decode *Dec);
void MakeDecodeTables(unsigned char *LenTab,struct Decode *Dec,int Size);
int DecodeNumber(struct Decode *Dec);
void CopyString();
inline void InsertOldDist(uint Distance);
inline void InsertLastMatch(uint Length,uint Distance);
inline void InsertOldDist(unsigned int Distance);
inline void InsertLastMatch(unsigned int Length,unsigned int Distance);
void UnpInitData(int Solid);
void CopyString(uint Length,uint Distance);
void CopyString(unsigned int Length,unsigned int Distance);
bool ReadEndOfBlock();
bool ReadVMCode();
bool ReadVMCodePPM();
bool AddVMCode(uint FirstByte,byte *Code,long CodeSize);
bool AddVMCode(unsigned int FirstByte,byte *Code,int CodeSize);
void InitFilters();
ComprDataIO *UnpIO;
@ -133,9 +133,9 @@ private:
/* lengths of preceding blocks, one length per filter. Used to reduce
size required to write block length if lengths are repeating */
Array<long> OldFilterLengths;
Array<int> OldFilterLengths;
long LastFilter;
int LastFilter;
bool TablesRead;
struct LitDecode LD;
@ -144,13 +144,13 @@ private:
struct RepDecode RD;
struct BitDecode BD;
uint OldDist[4],OldDistPtr;
uint LastDist,LastLength;
unsigned int OldDist[4],OldDistPtr;
unsigned int LastDist,LastLength;
uint UnpPtr,WrPtr;
unsigned int UnpPtr,WrPtr;
long ReadTop;
long ReadBorder;
int ReadTop;
int ReadBorder;
unsigned char UnpOldTable[HUFF_TABLE_SIZE];
@ -168,7 +168,7 @@ private:
Int64 WrittenFileSize;
bool FileExtracted;
long PrevLowDist,LowDistRepCount;
int PrevLowDist,LowDistRepCount;
/***************************** Unpack v 1.5 *********************************/
void Unpack15(bool Solid);
@ -178,18 +178,18 @@ private:
void GetFlagsBuf();
void OldUnpInitData(int Solid);
void InitHuff();
void CorrHuff(uint *CharSet,uint *NumToPlace);
void OldCopyString(uint Distance,uint Length);
uint DecodeNum(long Num,uint StartPos,
const uint *DecTab,const uint *PosTab);
void CorrHuff(unsigned int *CharSet,unsigned int *NumToPlace);
void OldCopyString(unsigned int Distance,unsigned int Length);
unsigned int DecodeNum(int Num,unsigned int StartPos,
const unsigned int *DecTab,const unsigned int *PosTab);
void OldUnpWriteBuf();
uint ChSet[256],ChSetA[256],ChSetB[256],ChSetC[256];
uint Place[256],PlaceA[256],PlaceB[256],PlaceC[256];
uint NToPl[256],NToPlB[256],NToPlC[256];
uint FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3;
long Buf60,NumHuf,StMode,LCount,FlagsCnt;
uint Nhfb,Nlzb,MaxDist3;
unsigned int ChSet[256],ChSetA[256],ChSetB[256],ChSetC[256];
unsigned int Place[256],PlaceA[256],PlaceB[256],PlaceC[256];
unsigned int NToPl[256],NToPlB[256],NToPlC[256];
unsigned int FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3;
int Buf60,NumHuf,StMode,LCount,FlagsCnt;
unsigned int Nhfb,Nlzb,MaxDist3;
/***************************** Unpack v 1.5 *********************************/
/***************************** Unpack v 2.0 *********************************/
@ -197,11 +197,11 @@ private:
struct MultDecode MD[4];
unsigned char UnpOldTable20[MC20*4];
int UnpAudioBlock,UnpChannels,UnpCurChannel,UnpChannelDelta;
void CopyString20(uint Length,uint Distance);
void CopyString20(unsigned int Length,unsigned int Distance);
bool ReadTables20();
void UnpInitData20(int Solid);
void ReadLastTables();
byte DecodeAudio(long Delta);
byte DecodeAudio(int Delta);
struct AudioVariables AudV[4];
/***************************** Unpack v 2.0 *********************************/

View File

@ -2,55 +2,55 @@
#ifdef RAR_COMMON_HPP
#define STARTL1 2
const
static uint DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00,
0xee00,0xf000,0xf200,0xf200,0xffff};
const
static uint PosL1[]={0,0,0,2,3,5,7,11,16,20,24,32,32};
static unsigned int PosL1[]={0,0,0,2,3,5,7,11,16,20,24,32,32};
#define STARTL2 3
const
static uint DecL2[]={0xa000,0xc000,0xd000,0xe000,0xea00,0xee00,
static unsigned int DecL2[]={0xa000,0xc000,0xd000,0xe000,0xea00,0xee00,
0xf000,0xf200,0xf240,0xffff};
const
static uint PosL2[]={0,0,0,0,5,7,9,13,18,22,26,34,36};
static unsigned int PosL2[]={0,0,0,0,5,7,9,13,18,22,26,34,36};
#define STARTHF0 4
const
static uint DecHf0[]={0x8000,0xc000,0xe000,0xf200,0xf200,0xf200,
static unsigned int DecHf0[]={0x8000,0xc000,0xe000,0xf200,0xf200,0xf200,
0xf200,0xf200,0xffff};
const
static uint PosHf0[]={0,0,0,0,0,8,16,24,33,33,33,33,33};
static unsigned int PosHf0[]={0,0,0,0,0,8,16,24,33,33,33,33,33};
#define STARTHF1 5
const
static uint DecHf1[]={0x2000,0xc000,0xe000,0xf000,0xf200,0xf200,
static unsigned int DecHf1[]={0x2000,0xc000,0xe000,0xf000,0xf200,0xf200,
0xf7e0,0xffff};
const
static uint PosHf1[]={0,0,0,0,0,0,4,44,60,76,80,80,127};
static unsigned int PosHf1[]={0,0,0,0,0,0,4,44,60,76,80,80,127};
#define STARTHF2 5
const
static uint DecHf2[]={0x1000,0x2400,0x8000,0xc000,0xfa00,0xffff,
static unsigned int DecHf2[]={0x1000,0x2400,0x8000,0xc000,0xfa00,0xffff,
0xffff,0xffff};
const
static uint PosHf2[]={0,0,0,0,0,0,2,7,53,117,233,0,0};
static unsigned int PosHf2[]={0,0,0,0,0,0,2,7,53,117,233,0,0};
#define STARTHF3 6
const
static uint DecHf3[]={0x800,0x2400,0xee00,0xfe80,0xffff,0xffff,
static unsigned int DecHf3[]={0x800,0x2400,0xee00,0xfe80,0xffff,0xffff,
0xffff};
const
static uint PosHf3[]={0,0,0,0,0,0,0,2,16,218,251,0,0};
static unsigned int PosHf3[]={0,0,0,0,0,0,0,2,16,218,251,0,0};
#define STARTHF4 8
const
static uint DecHf4[]={0xff00,0xffff,0xffff,0xffff,0xffff,0xffff};
static unsigned int DecHf4[]={0xff00,0xffff,0xffff,0xffff,0xffff,0xffff};
const
static uint PosHf4[]={0,0,0,0,0,0,0,0,0,255,0,0,0};
static unsigned int PosHf4[]={0,0,0,0,0,0,0,0,0,255,0,0,0};
void Unpack::Unpack15(bool Solid)
@ -158,21 +158,21 @@ void Unpack::OldUnpWriteBuf()
void Unpack::ShortLZ()
{
const
static uint ShortLen1[]={1,3,4,4,5,6,7,8,8,4,4,5,6,6,4,0};
static unsigned int ShortLen1[]={1,3,4,4,5,6,7,8,8,4,4,5,6,6,4,0};
const
static uint ShortXor1[]={0,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xfe,
static unsigned int ShortXor1[]={0,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xfe,
0xff,0xc0,0x80,0x90,0x98,0x9c,0xb0};
const
static uint ShortLen2[]={2,3,3,3,4,4,5,6,6,4,4,5,6,6,4,0};
static unsigned int ShortLen2[]={2,3,3,3,4,4,5,6,6,4,4,5,6,6,4,0};
const
static uint ShortXor2[]={0,0x40,0x60,0xa0,0xd0,0xe0,0xf0,0xf8,
static unsigned int ShortXor2[]={0,0x40,0x60,0xa0,0xd0,0xe0,0xf0,0xf8,
0xfc,0xc0,0x80,0x90,0x98,0x9c,0xb0};
uint Length,SaveLength;
uint LastDistance;
uint Distance;
long DistancePlace;
unsigned int Length,SaveLength;
unsigned int LastDistance;
unsigned int Distance;
int DistancePlace;
NumHuf=0;
unsigned int BitField=fgetbits();
@ -181,7 +181,7 @@ void Unpack::ShortLZ()
faddbits(1);
if (BitField >= 0x8000)
{
OldCopyString((uint)LastDist,LastLength);
OldCopyString((unsigned int)LastDist,LastLength);
return;
}
BitField <<= 1;
@ -275,10 +275,10 @@ void Unpack::ShortLZ()
void Unpack::LongLZ()
{
uint Length;
uint Distance;
uint DistancePlace,NewDistancePlace;
uint OldAvr2,OldAvr3;
unsigned int Length;
unsigned int Distance;
unsigned int DistancePlace,NewDistancePlace;
unsigned int OldAvr2,OldAvr3;
NumHuf=0;
Nlzb+=16;
@ -369,10 +369,10 @@ void Unpack::LongLZ()
void Unpack::HuffDecode()
{
uint CurByte,NewBytePlace;
uint Length;
uint Distance;
long BytePlace;
unsigned int CurByte,NewBytePlace;
unsigned int Length;
unsigned int Distance;
int BytePlace;
unsigned int BitField=fgetbits();
@ -447,8 +447,8 @@ void Unpack::HuffDecode()
void Unpack::GetFlagsBuf()
{
uint Flags,NewFlagsPlace;
uint FlagsPlace=DecodeNum(fgetbits(),STARTHF2,DecHf2,PosHf2);
unsigned int Flags,NewFlagsPlace;
unsigned int FlagsPlace=DecodeNum(fgetbits(),STARTHF2,DecHf2,PosHf2);
while (1)
{
@ -499,7 +499,7 @@ void Unpack::InitHuff()
}
void Unpack::CorrHuff(uint *CharSet,uint *NumToPlace)
void Unpack::CorrHuff(unsigned int *CharSet,unsigned int *NumToPlace)
{
int I,J;
for (I=7;I>=0;I--)
@ -511,7 +511,7 @@ void Unpack::CorrHuff(uint *CharSet,uint *NumToPlace)
}
void Unpack::OldCopyString(uint Distance,uint Length)
void Unpack::OldCopyString(unsigned int Distance,unsigned int Length)
{
DestUnpSize-=Length;
while (Length--)
@ -522,10 +522,10 @@ void Unpack::OldCopyString(uint Distance,uint Length)
}
uint Unpack::DecodeNum(long Num,uint StartPos,
const uint *DecTab,const uint *PosTab)
unsigned int Unpack::DecodeNum(int Num,unsigned int StartPos,
const unsigned int *DecTab,const unsigned int *PosTab)
{
long I;
int I;
for (Num&=0xfff0,I=0;DecTab[I]<=Num;I++)
StartPos++;
faddbits(StartPos);

View File

@ -3,16 +3,16 @@
#include "rar.hpp"
// Presumably these optimizations give similar speedup as those for CopyString in unpack.cpp
void Unpack::CopyString20(uint Length,uint Distance)
void Unpack::CopyString20(unsigned int Length,unsigned int Distance)
{
LastDist=OldDist[OldDistPtr++ & 3]=Distance;
LastLength=Length;
DestUnpSize-=Length;
uint UnpPtr = this->UnpPtr; // cache in register
unsigned UnpPtr = this->UnpPtr; // cache in register
byte* const Window = this->Window; // cache in register
uint DestPtr=UnpPtr-Distance;
unsigned int DestPtr=UnpPtr-Distance;
if (UnpPtr<MAXWINSIZE-300 && DestPtr<MAXWINSIZE-300)
{
this->UnpPtr += Length;
@ -87,7 +87,7 @@ void Unpack::Unpack20(bool Solid)
}
if (UnpAudioBlock)
{
long AudioNumber=DecodeNumber((struct Decode *)&MD[UnpCurChannel]);
int AudioNumber=DecodeNumber((struct Decode *)&MD[UnpCurChannel]);
if (AudioNumber==256)
{
@ -102,7 +102,7 @@ void Unpack::Unpack20(bool Solid)
continue;
}
long Number=DecodeNumber((struct Decode *)&LD);
int Number=DecodeNumber((struct Decode *)&LD);
if (Number<256)
{
Window[UnpPtr++]=(byte)Number;
@ -118,8 +118,8 @@ void Unpack::Unpack20(bool Solid)
addbits(Bits);
}
long DistNumber=DecodeNumber((struct Decode *)&DD);
uint Distance=DDecode[DistNumber]+1;
int DistNumber=DecodeNumber((struct Decode *)&DD);
unsigned int Distance=DDecode[DistNumber]+1;
if ((Bits=DBits[DistNumber])>0)
{
Distance+=getbits()>>(16-Bits);
@ -149,9 +149,9 @@ void Unpack::Unpack20(bool Solid)
}
if (Number<261)
{
uint Distance=OldDist[(OldDistPtr-(Number-256)) & 3];
long LengthNumber=DecodeNumber((struct Decode *)&RD);
long Length=LDecode[LengthNumber]+2;
unsigned int Distance=OldDist[(OldDistPtr-(Number-256)) & 3];
int LengthNumber=DecodeNumber((struct Decode *)&RD);
int Length=LDecode[LengthNumber]+2;
if ((Bits=LBits[LengthNumber])>0)
{
Length+=getbits()>>(16-Bits);
@ -225,7 +225,7 @@ bool Unpack::ReadTables20()
if (InAddr>ReadTop-5)
if (!UnpReadBuf())
return(false);
long Number=DecodeNumber((struct Decode *)&BD);
int Number=DecodeNumber((struct Decode *)&BD);
if (Number<16)
{
Table[I]=(Number+UnpOldTable20[I]) & 0xf;
@ -304,7 +304,7 @@ void Unpack::UnpInitData20(int Solid)
}
byte Unpack::DecodeAudio(long Delta)
byte Unpack::DecodeAudio(int Delta)
{
struct AudioVariables *V=&AudV[UnpCurChannel];
V->ByteCount++;
@ -312,10 +312,10 @@ byte Unpack::DecodeAudio(long Delta)
V->D3=V->D2;
V->D2=V->LastDelta-V->D1;
V->D1=V->LastDelta;
long PCh=8*V->LastChar+V->K1*V->D1+V->K2*V->D2+V->K3*V->D3+V->K4*V->D4+V->K5*UnpChannelDelta;
int PCh=8*V->LastChar+V->K1*V->D1+V->K2*V->D2+V->K3*V->D3+V->K4*V->D4+V->K5*UnpChannelDelta;
PCh=(PCh>>3) & 0xFF;
uint Ch=PCh-Delta;
unsigned int Ch=PCh-Delta;
int D=((signed char)Delta)<<3;
@ -336,9 +336,9 @@ byte Unpack::DecodeAudio(long Delta)
if ((V->ByteCount & 0x1F)==0)
{
uint MinDif=V->Dif[0],NumMinDif=0;
unsigned int MinDif=V->Dif[0],NumMinDif=0;
V->Dif[0]=0;
for (long I=1;I<sizeof(V->Dif)/sizeof(V->Dif[0]);I++)
for (int I=1;I<sizeof(V->Dif)/sizeof(V->Dif[0]);I++)
{
if (V->Dif[I]<MinDif)
{

View File

@ -37,10 +37,6 @@ typedef unrar_long_long unrar_pos_t;
/** Boolean, where 0 is false and 1 is true */
typedef int unrar_bool;
typedef unsigned char byte; //8 bits
typedef unsigned short ushort; //preferably 16 bits, but can be more
typedef unsigned long uint; //32 bits or more
/******** Open/close ********/
@ -57,7 +53,7 @@ file at offset pos and set *count to avail, where avail is the lesser of *count
and file_size-pos. Put read bytes into *out and return unrar_ok. If fewer than
avail bytes could be read successfully, return a non-zero error code. */
typedef unrar_err_t (*unrar_read_func)( void* user_data,
void* out, long* count, unrar_pos_t pos );
void* out, int* count, unrar_pos_t pos );
/** Same as unrar_open(), except data is read using supplied function rather
than from file. */
@ -98,8 +94,8 @@ typedef struct unrar_info_t
const char* name; /**< Name, in Unicode if is_unicode is true */
const blargg_wchar_t* name_w; /**< Name in Unicode, "" if unavailable */
unrar_bool is_unicode; /**< True if name is Unicode (UTF-8) */
uint dos_date; /**< Date in DOS-style format, 0 if unavailable */
uint crc; /**< Checksum; algorithm depends on archive */
unsigned int dos_date; /**< Date in DOS-style format, 0 if unavailable */
unsigned int crc; /**< Checksum; algorithm depends on archive */
unrar_bool is_crc32; /**< True if crc is CRC-32 */
} unrar_info_t;
@ -131,7 +127,7 @@ that passed to unrar_extract_custom(). Callback must do the following: Write
count bytes from *in to wherever extracted data goes and return unrar_ok. If
data cannot be written successfully, return a non-zero error code. */
typedef unrar_err_t (*unrar_write_func)( void* user_data,
const void* in, uint count );
const void* in, int count );
/** Extracts current file and writes data using supplied function. Any error
it returns will be returned by this function, and archive will still be

View File

@ -24,7 +24,7 @@ struct unrar_extract_mem_t
};
extern "C" {
static unrar_err_t extract_write( void* user_data, const void* in, uint count )
static unrar_err_t extract_write( void* user_data, const void* in, int count )
{
unrar_extract_mem_t* p = (unrar_extract_mem_t*) user_data;
@ -32,7 +32,7 @@ extern "C" {
if ( remain > 0 )
{
if ( count > remain )
count = remain;
count = (int)remain;
memcpy( p->out, in, count );
p->out += count;
@ -53,13 +53,13 @@ unrar_err_t unrar_extract( unrar_t* p, void* out, unrar_pos_t size )
}
inline
static bool is_entire_file( const unrar_t* p, const void* in, uint count )
static bool is_entire_file( const unrar_t* p, const void* in, int count )
{
return (count == p->Arc.NewLhd.UnpSize && p->Unp && in == p->Unp->window_wrptr());
}
extern "C" {
static unrar_err_t extract_mem( void* data, void const* in, uint count )
static unrar_err_t extract_mem( void* data, void const* in, int count )
{
unrar_t* p = (unrar_t*) data;
@ -129,7 +129,7 @@ const char* unrar_err_str( unrar_err_t err )
return "problem with RAR";
}
long ComprDataIO::Read( void* p, long n )
int ComprDataIO::Read( void* p, int n )
{
unrar_err_t err = user_read( user_read_data, p, &n, Tell_ );
if ( err )
@ -142,7 +142,7 @@ long ComprDataIO::Read( void* p, long n )
return n;
}
void ComprDataIO::UnpWrite( byte* out, long count )
void ComprDataIO::UnpWrite( byte* out, uint count )
{
if ( !SkipUnpCRC )
{
@ -156,15 +156,15 @@ void ComprDataIO::UnpWrite( byte* out, long count )
}
}
long ComprDataIO::UnpRead( byte* out, long count )
int ComprDataIO::UnpRead( byte* out, uint count )
{
if ( count <= 0 )
return 0;
if ( count > (uint) UnpPackedSize )
count = UnpPackedSize;
count = (uint) UnpPackedSize;
long result = Read( out, count );
int result = Read( out, count );
UnpPackedSize -= result;
return result;
}

View File

@ -5,7 +5,7 @@
#include <stdio.h>
extern "C" {
static unrar_err_t unrar_read_file( void* user_data, void* out, long* count, unrar_pos_t pos )
static unrar_err_t unrar_read_file( void* user_data, void* out, int* count, unrar_pos_t pos )
{
FILE* file = (FILE*) user_data;