backend update from Raze

* moving large allocations off the stack
* use proper printf formatters for size_t and ptrdiff_t.
* adding some missing 'noexcept'.
This commit is contained in:
Christoph Oelckers 2024-01-06 15:24:10 +01:00
commit 83aa9388ca
29 changed files with 117 additions and 109 deletions

View file

@ -154,20 +154,20 @@ protected:
std::vector<LumpRecord> FileInfo;
std::vector<uint32_t> Hashes; // one allocation for all hash lists.
uint32_t *FirstLumpIndex; // [RH] Hashing stuff moved out of lumpinfo structure
uint32_t *NextLumpIndex;
uint32_t *FirstLumpIndex = nullptr; // [RH] Hashing stuff moved out of lumpinfo structure
uint32_t *NextLumpIndex = nullptr;
uint32_t *FirstLumpIndex_FullName; // The same information for fully qualified paths from .zips
uint32_t *NextLumpIndex_FullName;
uint32_t *FirstLumpIndex_FullName = nullptr; // The same information for fully qualified paths from .zips
uint32_t *NextLumpIndex_FullName = nullptr;
uint32_t *FirstLumpIndex_NoExt; // The same information for fully qualified paths from .zips
uint32_t *NextLumpIndex_NoExt;
uint32_t *FirstLumpIndex_NoExt = nullptr; // The same information for fully qualified paths from .zips
uint32_t *NextLumpIndex_NoExt = nullptr;
uint32_t* FirstLumpIndex_ResId; // The same information for fully qualified paths from .zips
uint32_t* NextLumpIndex_ResId;
uint32_t* FirstLumpIndex_ResId = nullptr; // The same information for fully qualified paths from .zips
uint32_t* NextLumpIndex_ResId = nullptr;
uint32_t NumEntries = 0; // Not necessarily the same as FileInfo.Size()
uint32_t NumWads;
uint32_t NumWads = 0;
int IwadIndex = -1;
int MaxIwadIndex = -1;

View file

@ -177,7 +177,7 @@ public:
int GetEntryNamespace(uint32_t entry)
{
return (entry < NumLumps) ? Entries[entry].Namespace : ns_hidden;
return (entry < NumLumps) ? Entries[entry].Namespace : (int)ns_hidden;
}
int GetEntryResourceID(uint32_t entry)

View file

@ -45,6 +45,7 @@
#include <stdlib.h>
#include <assert.h>
#include <memory>
#include "ancientzip.h"
namespace FileSys {
@ -342,10 +343,19 @@ int FZipExploder::Explode(unsigned char *out, unsigned int outsize,
int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader &_In, unsigned int InLeft)
{
// don't allocate this on the stack, it's a bit on the large side.
struct work
{
unsigned char ReadBuf[256];
unsigned short Parent[HSIZE];
unsigned char Value[HSIZE], Stack[HSIZE];
};
auto s = std::make_unique<work>();
unsigned char* ReadBuf = s->ReadBuf;
unsigned short* Parent = s->Parent;
unsigned char* Value = s->Value, * Stack = s->Stack;
FileReader *In = &_In;
unsigned char ReadBuf[256];
unsigned short Parent[HSIZE];
unsigned char Value[HSIZE], Stack[HSIZE];
unsigned char *newstr;
int len;
int KwKwK, codesize = 9; /* start at 9 bits/code */

View file

@ -40,6 +40,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <inttypes.h>
#include "resourcefile.h"
#include "fs_filesystem.h"
@ -415,7 +416,7 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
snprintf(cksumout + (j * 2), 3, "%02X", cksum[j]);
}
fprintf(hashfile, "file: %s, hash: %s, size: %d\n", filename, cksumout, (int)filereader.GetLength());
fprintf(hashfile, "file: %s, hash: %s, size: %td\n", filename, cksumout, filereader.GetLength());
}
else
@ -434,7 +435,7 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf
snprintf(cksumout + (j * 2), 3, "%02X", cksum[j]);
}
fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %llu\n", filename, resfile->getName(i), cksumout, (uint64_t)resfile->Length(i));
fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %zu\n", filename, resfile->getName(i), cksumout, (uint64_t)resfile->Length(i));
}
}
}
@ -1272,7 +1273,7 @@ void FileSystem::ReadFile (int lump, void *dest)
if (numread != size)
{
throw FileSystemException("W_ReadFile: only read %ld of %ld on '%s'\n",
throw FileSystemException("W_ReadFile: only read %td of %td on '%s'\n",
numread, size, FileInfo[lump].LongName);
}
}

View file

@ -8,7 +8,7 @@ class StringPool
friend class FileSystem;
friend class FResourceFile;
private:
StringPool(bool _shared, size_t blocksize = 10*1024) : TopBlock(nullptr), FreeBlocks(nullptr), BlockSize(blocksize), shared(_shared) {}
StringPool(bool _shared, size_t blocksize = 10*1024) : TopBlock(nullptr), BlockSize(blocksize), shared(_shared) {}
public:
~StringPool();
const char* Strdup(const char*);
@ -20,7 +20,6 @@ protected:
Block *AddBlock(size_t size);
Block *TopBlock;
Block *FreeBlocks;
size_t BlockSize;
public:
bool shared;