Fix for nvault not loading on some Linux servers - nvault no longer uses exceptions, so libstdc++ is no longer needed

This commit is contained in:
Steve Dudenhoeffer 2008-03-04 19:06:39 +00:00
parent b0286c9c4d
commit 69a8a86ff6
8 changed files with 292 additions and 209 deletions

View File

@ -14,51 +14,66 @@ bool BinaryWriter::WriteAddr(void *buffer, size_t size)
return true;
}
void BinaryWriter::WriteUInt32(uint32_t num)
bool BinaryWriter::WriteUInt32(uint32_t num)
{
if ( !WriteAddr(&num, sizeof(uint32_t)) )
throw -1;
return false;
return true;
}
void BinaryWriter::WriteInt32(int32_t num)
bool BinaryWriter::WriteInt32(int32_t num)
{
if ( !WriteAddr(&num, sizeof(int32_t)) )
throw -1;
return false;
return true;
}
void BinaryWriter::WriteUInt16(uint16_t num)
bool BinaryWriter::WriteUInt16(uint16_t num)
{
if ( !WriteAddr(&num, sizeof(uint16_t)) )
throw -1;
return false;
return true;
}
void BinaryWriter::WriteInt16(int16_t num)
bool BinaryWriter::WriteInt16(int16_t num)
{
if ( !WriteAddr(&num, sizeof(int16_t)) )
throw -1;
return false;
return true;
}
void BinaryWriter::WriteUInt8(uint8_t num)
bool BinaryWriter::WriteUInt8(uint8_t num)
{
if ( !WriteAddr(&num, sizeof(uint8_t)) )
throw -1;
return false;
return true;
}
void BinaryWriter::WriteInt8(int8_t num)
bool BinaryWriter::WriteInt8(int8_t num)
{
if ( !WriteAddr(&num, sizeof(int8_t)) )
throw -1;
return false;
return true;
}
void BinaryWriter::WriteChars(const char buffer[], size_t chars)
bool BinaryWriter::WriteChars(const char buffer[], size_t chars)
{
if (!chars)
return;
return true;
if (fwrite(buffer, sizeof(char), chars, m_Fp) != chars)
throw -1;
return false;
return true;
}
BinaryReader::BinaryReader(FILE *fp)
{
m_Fp = fp;
@ -71,74 +86,62 @@ bool BinaryReader::ReadAddr(void *buffer, size_t size)
return true;
}
uint32_t BinaryReader::ReadUInt32()
bool BinaryReader::ReadUInt32(uint32_t& num)
{
uint32_t num;
if ( !ReadAddr(&num, sizeof(uint32_t)) )
throw -1;
return false;
return num;
return true;
}
int32_t BinaryReader::ReadInt32()
bool BinaryReader::ReadInt32(int32_t& num)
{
int32_t num;
if ( !ReadAddr(&num, sizeof(int32_t)) )
throw -1;
return false;
return num;
return true;
}
uint16_t BinaryReader::ReadUInt16()
bool BinaryReader::ReadUInt16(uint16_t& num)
{
uint16_t num;
if ( !ReadAddr(&num, sizeof(uint16_t)) )
throw -1;
return false;
return num;
return true;
}
int16_t BinaryReader::ReadInt16()
bool BinaryReader::ReadInt16(int16_t& num)
{
int16_t num;
if ( !ReadAddr(&num, sizeof(int16_t)) )
throw -1;
return false;
return num;
return true;
}
uint8_t BinaryReader::ReadUInt8()
bool BinaryReader::ReadUInt8(uint8_t& num)
{
uint8_t num;
if ( !ReadAddr(&num, sizeof(uint8_t)) )
throw -1;
return false;
return num;
return true;
}
int8_t BinaryReader::ReadInt8()
bool BinaryReader::ReadInt8(int8_t& num)
{
int8_t num;
if ( !ReadAddr(&num, sizeof(int8_t)) )
throw -1;
return false;
return num;
return true;
}
char *BinaryReader::ReadChars(char buffer[], size_t chars)
bool BinaryReader::ReadChars(char buffer[], size_t chars)
{
if (!chars)
return buffer;
return true;
if (fread(buffer, sizeof(char), chars, m_Fp) != chars)
throw -1;
return false;
return buffer;
return true;
}

View File

@ -11,13 +11,13 @@ public:
BinaryReader(FILE *fp);
//~BinaryReader();
public:
uint32_t ReadUInt32();
int32_t ReadInt32();
uint16_t ReadUInt16();
int16_t ReadInt16();
uint8_t ReadUInt8();
int8_t ReadInt8();
char *ReadChars(char buffer[], size_t chars);
bool ReadUInt32(uint32_t& num);
bool ReadInt32(int32_t& num);
bool ReadUInt16(uint16_t& num);
bool ReadInt16(int16_t& num);
bool ReadUInt8(uint8_t& num);
bool ReadInt8(int8_t& num);
bool ReadChars(char buffer[], size_t chars);
private:
bool ReadAddr(void *buffer, size_t size);
private:
@ -31,13 +31,13 @@ public:
BinaryWriter(FILE *fp);
public:
void SetFilePtr(FILE *fp) { m_Fp = fp; }
void WriteUInt32(uint32_t num);
void WriteInt32(int32_t num);
void WriteUInt16(uint16_t num);
void WriteInt16(int16_t num);
void WriteUInt8(uint8_t num);
void WriteInt8(int8_t num);
void WriteChars(const char buffer[], size_t chars);
bool WriteUInt32(uint32_t num);
bool WriteInt32(int32_t num);
bool WriteUInt16(uint16_t num);
bool WriteInt16(int16_t num);
bool WriteUInt8(uint8_t num);
bool WriteInt8(int8_t num);
bool WriteChars(const char buffer[], size_t chars);
private:
bool WriteAddr(void *buffer, size_t size);
private:

View File

@ -34,63 +34,87 @@ int Journal::Replay(VaultMap *pMap)
time_t stamp;
JOp op;
int ops = 0;
uint8_t temp8;
try
uint32_t itemp;
// try
// {
do
{
do
{
op = static_cast<JOp>(br.ReadUInt8());
if (op == Journal_Clear)
{
pMap->Clear();
} else if (op == Journal_Prune) {
time_t start;
time_t end;
start = static_cast<time_t>(br.ReadUInt32());
end = static_cast<time_t>(br.ReadUInt32());
pMap->Prune(start, end);
} else if (op == Journal_Insert) {
stamp = static_cast<time_t>(br.ReadUInt32());
len8 = br.ReadUInt8();
key = new char[len8+1];
br.ReadChars(key, len8);
len16 = br.ReadUInt16();
val = new char[len16+1];
br.ReadChars(val, len16);
key[len8] = '\0';
val[len16] = '\0';
sKey.assign(key);
sVal.assign(val);
pMap->Insert(sKey, sVal, stamp);
//clean up
delete [] key;
key = NULL;
delete [] val;
val = NULL;
} else if (op == Journal_Remove) {
len8 = br.ReadUInt8();
key = new char[len8+1];
br.ReadChars(key, len8);
key[len8] = '\0';
sKey.assign(key);
pMap->Remove(sKey);
}
ops++;
} while (op < Journal_TotalOps && op);
} catch (...) {
//journal is done
if (key)
if (!br.ReadUInt8(temp8)) goto fail;
op = static_cast<JOp>(temp8);
if (op == Journal_Clear)
{
pMap->Clear();
} else if (op == Journal_Prune) {
time_t start;
time_t end;
if (!br.ReadUInt32(itemp)) goto fail;
start = static_cast<time_t>(itemp);
if (!br.ReadUInt32(itemp)) goto fail;
end = static_cast<time_t>(itemp);
pMap->Prune(start, end);
} else if (op == Journal_Insert) {
if (!br.ReadUInt32(itemp)) goto fail;
stamp = static_cast<time_t>(itemp);
if (!br.ReadUInt8(len8)) goto fail;
key = new char[len8+1];
if (!br.ReadChars(key, len8)) goto fail;
if (!br.ReadUInt16(len16)) goto fail;
val = new char[len16+1];
if (!br.ReadChars(val, len16)) goto fail;
key[len8] = '\0';
val[len16] = '\0';
sKey.assign(key);
sVal.assign(val);
pMap->Insert(sKey, sVal, stamp);
//clean up
delete [] key;
key = NULL;
}
if (val)
{
delete [] val;
val = NULL;
}
}
} else if (op == Journal_Remove) {
if (!br.ReadUInt8(len8)) goto fail;
key = new char[len8+1];
if (!br.ReadChars(key, len8)) goto fail;
key[len8] = '\0';
sKey.assign(key);
pMap->Remove(sKey);
}
ops++;
} while (op < Journal_TotalOps && op);
goto success;
// } catch (...) {
fail:
//journal is done
if (key)
{
delete [] key;
key = NULL;
}
if (val)
{
delete [] val;
val = NULL;
}
// }
success:
fclose(m_fp);
return ops;
@ -112,73 +136,81 @@ bool Journal::End()
bool Journal::Write_Clear()
{
try
{
WriteOp(Journal_Clear);
// try
// {
if (!WriteOp(Journal_Clear)) goto fail;
return true;
} catch (...) {
// } catch (...) {
fail:
return false;
}
// }
}
bool Journal::Write_Insert(const char *key, const char *val, time_t stamp)
{
try
{
WriteOp(Journal_Insert);
WriteInt32(static_cast<int32_t>(stamp));
WriteString(key, Encode_Small);
WriteString(val, Encode_Medium);
// try
// {
if (!WriteOp(Journal_Insert)) goto fail;
if (!WriteInt32(static_cast<int32_t>(stamp))) goto fail;
if (!WriteString(key, Encode_Small)) goto fail;
if (!WriteString(val, Encode_Medium)) goto fail;
return true;
} catch (...) {
// } catch (...) {
fail:
return false;
}
// }
}
bool Journal::Write_Prune(time_t start, time_t end)
{
try
{
WriteOp(Journal_Prune);
WriteInt32(static_cast<int32_t>(start));
WriteInt32(static_cast<int32_t>(end));
// try
// {
if (!WriteOp(Journal_Prune)) goto fail;
if (!WriteInt32(static_cast<int32_t>(start))) goto fail;
if (!WriteInt32(static_cast<int32_t>(end))) goto fail;
return true;
} catch (...) {
// } catch (...) {
fail:
return false;
}
// }
}
bool Journal::Write_Remove(const char *key)
{
try
{
WriteOp(Journal_Remove);
WriteString(key, Encode_Small);
// try
// {
if (!WriteOp(Journal_Remove)) goto fail;
if (!WriteString(key, Encode_Small)) goto fail;
return true;
} catch (...) {
// } catch (...) {
fail:
return false;
}
// }
}
void Journal::WriteInt32(int num)
bool Journal::WriteInt32(int num)
{
m_Bw.WriteInt32(num);
return m_Bw.WriteInt32(num);
}
void Journal::WriteOp(JOp op)
bool Journal::WriteOp(JOp op)
{
m_Bw.WriteUInt8(static_cast<uint8_t>(op));
return m_Bw.WriteUInt8(static_cast<uint8_t>(op));
}
void Journal::WriteString(const char *str, Encode enc)
bool Journal::WriteString(const char *str, Encode enc)
{
size_t len = strlen(str);
if (enc == Encode_Small)
{
m_Bw.WriteUInt8(static_cast<uint8_t>(len));
if (!m_Bw.WriteUInt8(static_cast<uint8_t>(len))) return false;
} else if (enc == Encode_Medium) {
m_Bw.WriteUInt16(static_cast<uint16_t>(len));
if (!m_Bw.WriteUInt16(static_cast<uint16_t>(len))) return false;
}
m_Bw.WriteChars(str, len);
return m_Bw.WriteChars(str, len);
}

View File

@ -39,9 +39,9 @@ public:
bool Write_Insert(const char *key, const char *val, time_t stamp);
bool Write_Remove(const char *key);
private:
void WriteOp(JOp op);
void WriteInt32(int num);
void WriteString(const char *str, Encode enc);
bool WriteOp(JOp op);
bool WriteInt32(int num);
bool WriteString(const char *str, Encode enc);
private:
String m_File;
FILE *m_fp;

View File

@ -8,7 +8,7 @@ MM_ROOT = ../../metamod/metamod
OPT_FLAGS = -O3 -funroll-loops -s -pipe -fno-strict-aliasing -fomit-frame-pointer
DEBUG_FLAGS = -g -ggdb3
CPP = gcc-3.3
CPP = gcc-4.1
NAME = nvault
BIN_SUFFIX_32 = amxx_i386.so
@ -16,7 +16,8 @@ BIN_SUFFIX_64 = amxx_amd64.so
OBJECTS = sdk/amxxmodule.cpp amxxapi.cpp Binary.cpp Journal.cpp NVault.cpp
LINK = /lib/libgcc_eh-3.3.a /lib/libstdc++-3.3-pic.a
#LINK = /lib/libgcc_eh.a /lib/libstdc++-3.4.a
LINK =
INCLUDE = -I. -I$(HLSDK) -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/game_shared \
-I$(MM_ROOT) -I$(HLSDK)/common -Isdk
@ -35,7 +36,7 @@ else
CFLAGS = $(OPT_FLAGS)
endif
CFLAGS += -DNDEBUG -fPIC -Wall -Werror -fexceptions -DHAVE_STDINT_H -fno-rtti -static-libgcc
CFLAGS += -DNDEBUG -fPIC -Wall -Werror -DHAVE_STDINT_H -fno-rtti -static-libgcc -fno-exceptions
ifeq "$(AMD64)" "true"
BINARY = $(NAME)_$(BIN_SUFFIX_64)

View File

@ -45,10 +45,12 @@ NVault::NVault(const char *file)
fp = fopen(m_File.c_str(), "wb");
if (!fp)
{
throw Vault_NoFile;
this->m_Valid = false;
return;
}
}
this->m_Valid = true;
fclose(fp);
}
@ -82,20 +84,36 @@ VaultError NVault::_ReadFromFile()
String sKey;
String sVal;
try
{
int32_t magic = br.ReadUInt32();
// try
// {
uint32_t magic;
if (!br.ReadUInt32(magic)) goto fail;
if (magic != VAULT_MAGIC)
return Vault_BadFile;
int16_t version = br.ReadUInt16();
uint16_t version;
if (!br.ReadUInt16(version)) goto fail;
if (version != VAULT_VERSION)
return Vault_OldFile;
int32_t entries = br.ReadUInt32();
int32_t entries;
if (!br.ReadInt32(entries)) goto fail;
int32_t temp;
for (int32_t i=0; i<entries; i++)
{
stamp = static_cast<time_t>(br.ReadInt32());
keylen = br.ReadUInt8();
vallen = br.ReadUInt16();
if (!br.ReadInt32(temp)) goto fail;
stamp = static_cast<time_t>(temp);
if (!br.ReadUInt8(keylen)) goto fail;
if (!br.ReadUInt16(vallen)) goto fail;
if (keylen > oldkeylen)
{
if (key)
@ -110,29 +128,36 @@ VaultError NVault::_ReadFromFile()
val = new char[vallen + 1];
oldvallen = vallen;
}
br.ReadChars(key, keylen);
br.ReadChars(val, vallen);
if (!br.ReadChars(key, keylen)) goto fail;
if (!br.ReadChars(val, vallen)) goto fail;
key[keylen] = '\0';
val[vallen] = '\0';
sKey.assign(key);
sVal.assign(val);
m_Hash.Insert(sKey, sVal, stamp);
}
} catch (...) {
if (key)
{
delete [] key;
key = NULL;
}
if (val)
{
delete [] val;
val = NULL;
}
fclose(fp);
return Vault_Read;
}
// } catch (...) {
goto success;
fail:
if (key)
{
delete [] key;
key = NULL;
}
if (val)
{
delete [] val;
val = NULL;
}
fclose(fp);
return Vault_Read;
// }
success:
fclose(fp);
return Vault_Ok;
@ -149,38 +174,45 @@ bool NVault::_SaveToFile()
BinaryWriter bw(fp);
try
// try
// {
uint32_t magic = VAULT_MAGIC;
uint16_t version = VAULT_VERSION;
time_t stamp;
String key;
String val;
THash<String,String>::iterator iter = m_Hash.begin();
if (!bw.WriteUInt32(magic)) goto fail;
if (!bw.WriteUInt16(version)) goto fail;
if (!bw.WriteUInt32( m_Hash.Size() )) goto fail;
while (iter != m_Hash.end())
{
int32_t magic = VAULT_MAGIC;
int16_t version = VAULT_VERSION;
key = (*iter).key;
val = (*iter).val;
stamp = (*iter).stamp;
bw.WriteUInt32(magic);
bw.WriteUInt16(version);
bw.WriteUInt32( m_Hash.Size() );
time_t stamp;
String key;
String val;
THash<String,String>::iterator iter = m_Hash.begin();
while (iter != m_Hash.end())
{
key = (*iter).key;
val = (*iter).val;
stamp = (*iter).stamp;
bw.WriteInt32(static_cast<int32_t>(stamp));
bw.WriteUInt8( key.size() );
bw.WriteUInt16( val.size() );
bw.WriteChars( key.c_str(), key.size() );
bw.WriteChars( val.c_str(), val.size() );
iter++;
}
} catch (...) {
fclose(fp);
return false;
if (!bw.WriteInt32(static_cast<int32_t>(stamp))) goto fail;;
if (!bw.WriteUInt8( key.size() )) goto fail;
if (!bw.WriteUInt16( val.size() )) goto fail;
if (!bw.WriteChars( key.c_str(), key.size() )) goto fail;
if (!bw.WriteChars( val.c_str(), val.size() )) goto fail;
iter++;
}
goto success;
// } catch (...) {
fail:
fclose(fp);
return false;
// }
success:
fclose(fp);
return true;
@ -324,10 +356,14 @@ bool NVault::GetValue(const char *key, time_t &stamp, char buffer[], size_t len)
IVault *VaultMngr::OpenVault(const char *file)
{
NVault *pVault;
try
//try
//{
pVault = new NVault(file);
// } catch (...) {
if (!pVault->isValid())
{
pVault = new NVault(file);
} catch (...) {
delete pVault;
pVault = NULL;
}

View File

@ -57,6 +57,11 @@ private:
THash<String, String> m_Hash;
Journal *m_Journal;
bool m_Open;
bool m_Valid;
public:
bool isValid() { return m_Valid; }
};
class VaultMngr : public IVaultMngr

View File

@ -22,6 +22,12 @@ CQueue<int> g_OldVaults;
VaultMngr g_VaultMngr;
#ifndef _WIN32
extern "C" void __cxa_pure_virtual(void)
{
}
#endif
static cell nvault_open(AMX *amx, cell *params)
{
int len, id=-1;