Coding style cleanups.
This commit is contained in:
+34
-33
@@ -107,49 +107,49 @@ int compress_lzma_dummy = 0;
|
|||||||
|
|
||||||
namespace MyLzma {
|
namespace MyLzma {
|
||||||
|
|
||||||
struct InStreamRam: public ISequentialInStream, public CMyUnknownImp
|
struct InStream: public ISequentialInStream, public CMyUnknownImp
|
||||||
{
|
{
|
||||||
MY_UNKNOWN_IMP
|
MY_UNKNOWN_IMP
|
||||||
const Byte *Data; size_t Size; size_t Pos;
|
const Byte *b_buf; size_t b_size; size_t b_pos;
|
||||||
void Init(const Byte *data, size_t size) {
|
void Init(const Byte *data, size_t size) {
|
||||||
Data = data; Size = size; Pos = 0;
|
b_buf = data; b_size = size; b_pos = 0;
|
||||||
}
|
}
|
||||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
STDMETHODIMP InStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize)
|
STDMETHODIMP InStream::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||||
{
|
{
|
||||||
UInt32 remain = Size - Pos;
|
size_t remain = b_size - b_pos;
|
||||||
if (size > remain) size = remain;
|
if (size > remain) size = (UInt32) remain;
|
||||||
memmove(data, Data + Pos, size);
|
memcpy(data, b_buf + b_pos, size);
|
||||||
Pos += size;
|
b_pos += size;
|
||||||
if (processedSize != NULL) *processedSize = size;
|
if (processedSize != NULL) *processedSize = size;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OutStreamRam : public ISequentialOutStream, public CMyUnknownImp
|
struct OutStream : public ISequentialOutStream, public CMyUnknownImp
|
||||||
{
|
{
|
||||||
MY_UNKNOWN_IMP
|
MY_UNKNOWN_IMP
|
||||||
Byte *Data; size_t Size; size_t Pos; bool Overflow;
|
Byte *b_buf; size_t b_size; size_t b_pos; bool overflow;
|
||||||
void Init(Byte *data, size_t size) {
|
void Init(Byte *data, size_t size) {
|
||||||
Data = data; Size = size; Pos = 0; Overflow = false;
|
b_buf = data; b_size = size; b_pos = 0; overflow = false;
|
||||||
}
|
}
|
||||||
HRESULT WriteByte(Byte b) {
|
HRESULT WriteByte(Byte c) {
|
||||||
if (Pos >= Size) { Overflow = true; return E_FAIL; }
|
if (b_pos >= b_size) { overflow = true; return E_FAIL; }
|
||||||
Data[Pos++] = b;
|
b_buf[b_pos++] = c;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||||
};
|
};
|
||||||
|
|
||||||
STDMETHODIMP OutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
STDMETHODIMP OutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||||
{
|
{
|
||||||
UInt32 i;
|
size_t remain = b_size - b_pos;
|
||||||
for (i = 0; i < size && Pos < Size; i++)
|
if (size > remain) size = (UInt32) remain, overflow = true;
|
||||||
Data[Pos++] = ((const Byte *)data)[i];
|
memcpy(b_buf + b_pos, data, size);
|
||||||
if (processedSize != NULL) *processedSize = i;
|
b_pos += size;
|
||||||
if (i != size) { Overflow = true; return E_FAIL; }
|
if (processedSize != NULL) *processedSize = size;
|
||||||
return S_OK;
|
return overflow ? E_FAIL : S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
|
struct ProgressInfo : public ICompressProgressInfo, public CMyUnknownImp
|
||||||
@@ -197,8 +197,8 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
const lzma_compress_config_t *lcconf = cconf_parm ? &cconf_parm->conf_lzma : NULL;
|
||||||
lzma_compress_result_t *res = &cresult->result_lzma;
|
lzma_compress_result_t *res = &cresult->result_lzma;
|
||||||
|
|
||||||
MyLzma::InStreamRam is; is.AddRef();
|
MyLzma::InStream is; is.AddRef();
|
||||||
MyLzma::OutStreamRam os; os.AddRef();
|
MyLzma::OutStream os; os.AddRef();
|
||||||
is.Init(src, src_len);
|
is.Init(src, src_len);
|
||||||
os.Init(dst, *dst_len);
|
os.Init(dst, *dst_len);
|
||||||
|
|
||||||
@@ -348,16 +348,16 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
goto error;
|
goto error;
|
||||||
if (enc.WriteCoderProperties(&os) != S_OK)
|
if (enc.WriteCoderProperties(&os) != S_OK)
|
||||||
goto error;
|
goto error;
|
||||||
if (os.Overflow) {
|
if (os.overflow) {
|
||||||
//r = UPX_E_OUTPUT_OVERRUN;
|
//r = UPX_E_OUTPUT_OVERRUN;
|
||||||
r = UPX_E_NOT_COMPRESSIBLE;
|
r = UPX_E_NOT_COMPRESSIBLE;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
assert(os.Pos == 5);
|
assert(os.b_pos == 5);
|
||||||
#if defined(USE_LZMA_PROPERTIES)
|
#if defined(USE_LZMA_PROPERTIES)
|
||||||
os.Pos = 1;
|
os.b_pos = 1;
|
||||||
#else
|
#else
|
||||||
os.Pos = 0;
|
os.b_pos = 0;
|
||||||
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
// extra stuff in first byte: 5 high bits convenience for stub decompressor
|
||||||
unsigned t = res->lit_context_bits + res->lit_pos_bits;
|
unsigned t = res->lit_context_bits + res->lit_pos_bits;
|
||||||
os.WriteByte((t << 3) | res->pos_bits);
|
os.WriteByte((t << 3) | res->pos_bits);
|
||||||
@@ -370,25 +370,26 @@ int upx_lzma_compress ( const upx_bytep src, unsigned src_len,
|
|||||||
} catch(...) { return UPX_E_OUT_OF_MEMORY; }
|
} catch(...) { return UPX_E_OUT_OF_MEMORY; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
assert(is.Pos <= src_len);
|
assert(is.b_pos <= src_len);
|
||||||
assert(os.Pos <= *dst_len);
|
assert(os.b_pos <= *dst_len);
|
||||||
if (rh == E_OUTOFMEMORY)
|
if (rh == E_OUTOFMEMORY)
|
||||||
r = UPX_E_OUT_OF_MEMORY;
|
r = UPX_E_OUT_OF_MEMORY;
|
||||||
else if (os.Overflow)
|
else if (os.overflow)
|
||||||
{
|
{
|
||||||
assert(os.Pos == *dst_len);
|
assert(os.b_pos == *dst_len);
|
||||||
//r = UPX_E_OUTPUT_OVERRUN;
|
//r = UPX_E_OUTPUT_OVERRUN;
|
||||||
r = UPX_E_NOT_COMPRESSIBLE;
|
r = UPX_E_NOT_COMPRESSIBLE;
|
||||||
}
|
}
|
||||||
else if (rh == S_OK)
|
else if (rh == S_OK)
|
||||||
{
|
{
|
||||||
assert(is.Pos == src_len);
|
assert(is.b_pos == src_len);
|
||||||
r = UPX_E_OK;
|
r = UPX_E_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
error:
|
error:
|
||||||
*dst_len = os.Pos;
|
*dst_len = os.b_pos;
|
||||||
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
//printf("\nlzma_compress: %d: %u %u %u %u %u, %u - > %u\n", r, res->pos_bits, res->lit_pos_bits, res->lit_context_bits, res->dict_size, res->num_probs, src_len, *dst_len);
|
||||||
|
//printf("%u %u %u\n", is.__m_RefCount, os.__m_RefCount, progress.__m_RefCount);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user