From 0e3bee6f300b9e441161a3f642354750ff603f0c Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Mon, 23 Jun 2014 19:52:32 +0200 Subject: [PATCH 1/3] - Enable 'language' feature on unix targets. The sdl version of the function 'SetLanguageIDs' is very limited, comparing to the win32 counterpart, as it will try to accept only the language codes (ie 'enu', 'fr', 'ptb', etc). If a different string is provided, zdoom will default its language to English. --- src/sdl/i_system.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index e46b8e59d..f7137d103 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -97,13 +97,7 @@ SDL_Cursor *X11Cursor; SDL_Cursor *FirstCursor; #endif -DWORD LanguageIDs[4] = -{ - MAKE_ID ('e','n','u',0), - MAKE_ID ('e','n','u',0), - MAKE_ID ('e','n','u',0), - MAKE_ID ('e','n','u',0) -}; +DWORD LanguageIDs[4]; int (*I_GetTime) (bool saveMS); int (*I_WaitForTic) (int); @@ -326,6 +320,13 @@ void I_WaitVBL (int count) // void SetLanguageIDs () { + size_t langlen = strlen(language); + + DWORD lang = (langlen < 2 || langlen > 3) ? + MAKE_ID('e','n','u','0') : + MAKE_ID(language[0],language[1],language[2],'0'); + + LanguageIDs[3] = LanguageIDs[2] = LanguageIDs[1] = LanguageIDs[0] = lang; } // From 0be30c782cab1cf2f8ab18db1e96f2d8eea8fa3d Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Wed, 25 Jun 2014 20:11:05 +0300 Subject: [PATCH 2/3] Fix LZMA compilation on GCC with position-independent code (PIC) generation enabled EBX register is used Global Offset Table in PIC http://www.greyhat.ch/lab/downloads/pic.html --- lzma/C/CpuArch.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lzma/C/CpuArch.c b/lzma/C/CpuArch.c index 36e7680d9..425d18923 100644 --- a/lzma/C/CpuArch.c +++ b/lzma/C/CpuArch.c @@ -70,8 +70,24 @@ static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d) *c = c2; *d = d2; + #elif __PIC__ + + /* GCC or Clang WITH position-independent code generation */ + + __asm__ __volatile__ ( + "xchgl %%ebx, %1\n" + "cpuid\n" + "xchgl %%ebx, %1\n" + : "=a" (*a) , + "=r" (*b) , + "=c" (*c) , + "=d" (*d) + : "0" (function)) ; + #else + /* GCC or Clang WITHOUT position-independent code generation */ + __asm__ __volatile__ ( "cpuid" : "=a" (*a) , From 270541f9422038c829f673de30a0b4e4562d05f5 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 26 Jun 2014 09:43:51 +0200 Subject: [PATCH 3/3] fixed compilation with latest LZMA SDK on Windows. LZMA SDK recently added an #include 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. --- src/files.cpp | 25 +++++++++++++++++----- src/files.h | 5 +++-- src/resourcefiles/file_7z.cpp | 6 ++++-- tools/zipdir/zipdir.c | 40 +++++++++++++++++------------------ 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/files.cpp b/src/files.cpp index d7dfc2cbe..981b351a9 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -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; diff --git a/src/files.h b/src/files.h index ebe9665a4..f7d061c8e 100644 --- a/src/files.h +++ b/src/files.h @@ -4,7 +4,6 @@ #include #include #include "bzlib.h" -#include "LzmaDec.h" #include "doomtype.h" #include "m_swap.h" @@ -257,6 +256,8 @@ private: // Wraps around a FileReader to decompress a lzma stream class FileReaderLZMA : public FileReaderBase { + struct StreamPointer; + public: FileReaderLZMA (FileReader &file, size_t uncompressed_size, bool zip); ~FileReaderLZMA (); @@ -308,7 +309,7 @@ private: FileReader &File; bool SawEOF; - CLzmaDec Stream; + StreamPointer *Streamp; // anonymous pointer to LKZA decoder struct - to avoid including the LZMA headers globally size_t Size; size_t InPos, InSize; size_t OutProcessed; diff --git a/src/resourcefiles/file_7z.cpp b/src/resourcefiles/file_7z.cpp index 53653bb59..c3845d8cc 100644 --- a/src/resourcefiles/file_7z.cpp +++ b/src/resourcefiles/file_7z.cpp @@ -32,6 +32,10 @@ ** ** */ +#define USE_WINDOWS_DWORD + +#include "7z.h" +#include "7zCrc.h" #include "resourcefile.h" #include "cmdlib.h" @@ -41,8 +45,6 @@ #include "i_system.h" #include "w_wad.h" -#include "7z.h" -#include "7zCrc.h" //----------------------------------------------------------------------- diff --git a/tools/zipdir/zipdir.c b/tools/zipdir/zipdir.c index 9b521bedf..1479952e0 100644 --- a/tools/zipdir/zipdir.c +++ b/tools/zipdir/zipdir.c @@ -129,7 +129,7 @@ typedef struct compressor_s int method; } compressor_t; -typedef unsigned int DWORD; +typedef unsigned int UINT32; typedef unsigned short WORD; typedef unsigned char BYTE; @@ -139,49 +139,49 @@ typedef unsigned char BYTE; //#pragma pack(push,1) typedef struct { - DWORD Magic; // 0 + UINT32 Magic; // 0 BYTE VersionToExtract[2]; // 4 WORD Flags; // 6 WORD Method; // 8 WORD ModTime; // 10 WORD ModDate; // 12 - DWORD CRC32; // 14 - DWORD CompressedSize; // 18 - DWORD UncompressedSize; // 22 + UINT32 CRC32; // 14 + UINT32 CompressedSize; // 18 + UINT32 UncompressedSize; // 22 WORD NameLength; // 26 WORD ExtraLength; // 28 } LocalFileHeader; typedef struct { - DWORD Magic; + UINT32 Magic; BYTE VersionMadeBy[2]; BYTE VersionToExtract[2]; WORD Flags; WORD Method; WORD ModTime; WORD ModDate; - DWORD CRC32; - DWORD CompressedSize; - DWORD UncompressedSize; + UINT32 CRC32; + UINT32 CompressedSize; + UINT32 UncompressedSize; WORD NameLength; WORD ExtraLength; WORD CommentLength; WORD StartingDiskNumber; WORD InternalAttributes; - DWORD ExternalAttributes; - DWORD LocalHeaderOffset; + UINT32 ExternalAttributes; + UINT32 LocalHeaderOffset; } CentralDirectoryEntry; typedef struct { - DWORD Magic; + UINT32 Magic; WORD DiskNumber; WORD FirstDisk; WORD NumEntries; WORD NumEntriesOnAllDisks; - DWORD DirectorySize; - DWORD DirectoryOffset; + UINT32 DirectorySize; + UINT32 DirectoryOffset; WORD ZipCommentLength; } EndOfCentralDirectory; //#pragma pack(pop) @@ -1373,7 +1373,7 @@ BYTE *find_central_dir(FILE *fin) back_read = 4; while (back_read < max_back) { - DWORD read_size, read_pos; + UINT32 read_size, read_pos; int i; if (back_read + BUFREADCOMMENT > max_back) back_read = max_back; @@ -1420,12 +1420,12 @@ BYTE *find_central_dir(FILE *fin) free(dir); return NULL; } - if (*(DWORD *)dir != ZIP_CENTRALFILE) + if (*(UINT32 *)dir != ZIP_CENTRALFILE) { free(dir); return NULL; } - *(DWORD *)(dir + LittleLong(eod.DirectorySize)) = ZIP_ENDOFDIR; + *(UINT32 *)(dir + LittleLong(eod.DirectorySize)) = ZIP_ENDOFDIR; return dir; } @@ -1444,7 +1444,7 @@ CentralDirectoryEntry *find_file_in_zip(BYTE *dir, const char *path, unsigned in CentralDirectoryEntry *ent; int flags; - while (*(DWORD *)dir == ZIP_CENTRALFILE) + while (*(UINT32 *)dir == ZIP_CENTRALFILE) { ent = (CentralDirectoryEntry *)dir; if (pathlen == LittleShort(ent->NameLength) && @@ -1455,7 +1455,7 @@ CentralDirectoryEntry *find_file_in_zip(BYTE *dir, const char *path, unsigned in } dir += sizeof(*ent) + LittleShort(ent->NameLength) + LittleShort(ent->ExtraLength) + LittleShort(ent->CommentLength); } - if (*(DWORD *)dir != ZIP_CENTRALFILE) + if (*(UINT32 *)dir != ZIP_CENTRALFILE) { return NULL; } @@ -1495,7 +1495,7 @@ int copy_zip_file(FILE *zip, file_entry_t *file, FILE *ozip, CentralDirectoryEnt { LocalFileHeader lfh; BYTE *buf; - DWORD buf_size; + UINT32 buf_size; if (fseek(ozip, LittleLong(ent->LocalHeaderOffset), SEEK_SET) != 0) {