summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/util/chdcodec.cpp16
-rw-r--r--src/lib/util/un7z.cpp29
2 files changed, 29 insertions, 16 deletions
diff --git a/src/lib/util/chdcodec.cpp b/src/lib/util/chdcodec.cpp
index 7d3f3185212..be48cd55ec9 100644
--- a/src/lib/util/chdcodec.cpp
+++ b/src/lib/util/chdcodec.cpp
@@ -114,11 +114,11 @@ public:
private:
// internal helpers
- static void *fast_alloc(void *p, size_t size);
- static void fast_free(void *p, void *address);
+ static void *fast_alloc(ISzAllocPtr p, size_t size);
+ static void fast_free(ISzAllocPtr p, void *address);
static constexpr int MAX_LZMA_ALLOCS = 64;
- uint32_t * m_allocptr[MAX_LZMA_ALLOCS];
+ uint32_t *m_allocptr[MAX_LZMA_ALLOCS];
};
@@ -1020,9 +1020,9 @@ chd_lzma_allocator::~chd_lzma_allocator()
// allocates and frees memory frequently
//-------------------------------------------------
-void *chd_lzma_allocator::fast_alloc(void *p, size_t size)
+void *chd_lzma_allocator::fast_alloc(ISzAllocPtr p, size_t size)
{
- auto *codec = reinterpret_cast<chd_lzma_allocator *>(p);
+ auto *const codec = static_cast<chd_lzma_allocator *>(const_cast<ISzAlloc *>(p));
// compute the size, rounding to the nearest 1k
size = (size + 0x3ff) & ~0x3ff;
@@ -1059,12 +1059,12 @@ void *chd_lzma_allocator::fast_alloc(void *p, size_t size)
// allocates and frees memory frequently
//-------------------------------------------------
-void chd_lzma_allocator::fast_free(void *p, void *address)
+void chd_lzma_allocator::fast_free(ISzAllocPtr p, void *address)
{
if (address == nullptr)
return;
- auto *codec = reinterpret_cast<chd_lzma_allocator *>(p);
+ auto *const codec = static_cast<chd_lzma_allocator *>(const_cast<ISzAlloc *>(p));
// find the hunk
uint32_t *ptr = reinterpret_cast<uint32_t *>(address) - 1;
@@ -1149,7 +1149,7 @@ uint32_t chd_lzma_compressor::compress(const uint8_t *src, uint32_t srclen, uint
void chd_lzma_compressor::configure_properties(CLzmaEncProps &props, uint32_t hunkbytes)
{
LzmaEncProps_Init(&props);
- props.level = 9;
+ props.level = 8;
props.reduceSize = hunkbytes;
LzmaEncProps_Normalize(&props);
}
diff --git a/src/lib/util/un7z.cpp b/src/lib/util/un7z.cpp
index b35af479d5d..896818a45e3 100644
--- a/src/lib/util/un7z.cpp
+++ b/src/lib/util/un7z.cpp
@@ -51,8 +51,8 @@ struct CFileInStream : public ISeekInStream
{
CFileInStream() noexcept
{
- Read = [] (void *pp, void *buf, size_t *size) { return reinterpret_cast<CFileInStream *>(pp)->read(buf, *size); };
- Seek = [] (void *pp, Int64 *pos, ESzSeek origin) { return reinterpret_cast<CFileInStream *>(pp)->seek(*pos, origin); };
+ Read = &CFileInStream::read_static;
+ Seek = &CFileInStream::seek_static;
}
random_read::ptr file;
@@ -109,6 +109,16 @@ private:
pos = currfpos;
return SZ_OK;
}
+
+ static SRes read_static(ISeekInStream const *pp, void *buf, size_t *size) noexcept
+ {
+ return static_cast<CFileInStream *>(const_cast<ISeekInStream *>(pp))->read(buf, *size);
+ }
+
+ static SRes seek_static(ISeekInStream const *pp, Int64 *pos, ESzSeek origin) noexcept
+ {
+ return static_cast<CFileInStream *>(const_cast<ISeekInStream *>(pp))->seek(*pos, origin);
+ }
};
@@ -128,7 +138,7 @@ public:
virtual ~m7z_file_impl()
{
if (m_out_buffer)
- IAlloc_Free(&m_alloc_imp, m_out_buffer);
+ ISzAlloc_Free(&m_alloc_imp, m_out_buffer);
if (m_inited)
SzArEx_Free(&m_db, &m_alloc_imp);
}
@@ -230,7 +240,7 @@ private:
std::vector<char> m_utf8_buf;
CFileInStream m_archive_stream;
- CLookToRead m_look_stream;
+ CLookToRead2 m_look_stream;
CSzArEx m_db;
ISzAlloc m_alloc_imp;
ISzAlloc m_alloc_temp_imp;
@@ -240,6 +250,7 @@ private:
UInt32 m_block_index;
Byte * m_out_buffer;
std::size_t m_out_buffer_size;
+ Byte m_look_stream_buf[65'536];
};
@@ -314,9 +325,11 @@ m7z_file_impl::m7z_file_impl(std::string &&filename) noexcept
m_alloc_temp_imp.Alloc = &SzAllocTemp;
m_alloc_temp_imp.Free = &SzFreeTemp;
- LookToRead_CreateVTable(&m_look_stream, False);
+ LookToRead2_CreateVTable(&m_look_stream, False);
m_look_stream.realStream = &m_archive_stream;
- LookToRead_Init(&m_look_stream);
+ m_look_stream.buf = m_look_stream_buf;
+ m_look_stream.bufSize = std::size(m_look_stream_buf);
+ LookToRead2_Init(&m_look_stream);
}
@@ -362,7 +375,7 @@ std::error_condition m7z_file_impl::initialize() noexcept
SzArEx_Init(&m_db);
m_inited = true;
- SRes const res = SzArEx_Open(&m_db, &m_look_stream.s, &m_alloc_imp, &m_alloc_temp_imp);
+ SRes const res = SzArEx_Open(&m_db, &m_look_stream.vt, &m_alloc_imp, &m_alloc_temp_imp);
if (res != SZ_OK)
{
osd_printf_error("un7z: error opening %s as 7z archive (%d)\n", m_filename, int(res));
@@ -458,7 +471,7 @@ std::error_condition m7z_file_impl::decompress(void *buffer, std::size_t length)
std::size_t offset(0);
std::size_t out_size_processed(0);
SRes const res = SzArEx_Extract(
- &m_db, &m_look_stream.s, m_curr_file_idx, // requested file
+ &m_db, &m_look_stream.vt, m_curr_file_idx, // requested file
&m_block_index, &m_out_buffer, &m_out_buffer_size, // solid block caching
&offset, &out_size_processed, // data size/offset
&m_alloc_imp, &m_alloc_temp_imp); // allocator helpers