fixed compilation with latest LZMA SDK on Windows.

LZMA SDK recently added an #include <windows.h> to its headers, meaning it's no longer safe to include its headers globally in platform independent files.
The following changes were necessary:

- rename DWORD type in zipdir.c
- add USE_WINDOWS_DWORD and reorder includes in file_7z.cpp
- wrap LZMA decoder stream into a local struct that's declared anonymously in files.h and adjust files.cpp for this change.
This commit is contained in:
Christoph Oelckers 2014-06-26 09:43:51 +02:00
commit 270541f942
4 changed files with 47 additions and 29 deletions

View file

@ -33,11 +33,15 @@
**
*/
#define USE_WINDOWS_DWORD
#include "LzmaDec.h"
#include "files.h"
#include "i_system.h"
#include "templates.h"
#include "m_misc.h"
//==========================================================================
//
// FileReader
@ -370,6 +374,15 @@ extern "C" void bz_internal_error (int errcode)
//
//==========================================================================
// This is retarded but necessary to work around the inclusion of windows.h in recent
// LZMA versions, meaning it's no longer possible to include the LZMA headers in files.h.
// As a result we cannot declare the CLzmaDec member in the header so we work around
// it my wrapping it into another struct that can be declared anonymously in the header.
struct FileReaderLZMA::StreamPointer
{
CLzmaDec Stream;
};
static void *SzAlloc(void *, size_t size) { return malloc(size); }
static void SzFree(void *, void *address) { free(address); }
ISzAlloc g_Alloc = { SzAlloc, SzFree };
@ -398,20 +411,22 @@ FileReaderLZMA::FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool
FillBuffer();
LzmaDec_Construct(&Stream);
err = LzmaDec_Allocate(&Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc);
Streamp = new StreamPointer;
LzmaDec_Construct(&Streamp->Stream);
err = LzmaDec_Allocate(&Streamp->Stream, header + 4, LZMA_PROPS_SIZE, &g_Alloc);
if (err != SZ_OK)
{
I_Error("FileReaderLZMA: LzmaDec_Allocate failed: %d\n", err);
}
LzmaDec_Init(&Stream);
LzmaDec_Init(&Streamp->Stream);
}
FileReaderLZMA::~FileReaderLZMA ()
{
LzmaDec_Free(&Stream, &g_Alloc);
LzmaDec_Free(&Streamp->Stream, &g_Alloc);
delete Streamp;
}
long FileReaderLZMA::Read (void *buffer, long len)
@ -426,7 +441,7 @@ long FileReaderLZMA::Read (void *buffer, long len)
size_t out_processed = len;
size_t in_processed = InSize;
err = LzmaDec_DecodeToBuf(&Stream, next_out, &out_processed, InBuff + InPos, &in_processed, finish_mode, &status);
err = LzmaDec_DecodeToBuf(&Streamp->Stream, next_out, &out_processed, InBuff + InPos, &in_processed, finish_mode, &status);
InPos += in_processed;
InSize -= in_processed;
next_out += out_processed;