Merge changes from the-witness.
This commit is contained in:
@ -446,6 +446,14 @@ namespace nv
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Release ownership of allocated memory and returns pointer to it.
|
||||
T * release() {
|
||||
T * tmp = m_buffer;
|
||||
m_buffer = NULL;
|
||||
m_size = 0;
|
||||
m_buffer_size = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/// Array serialization.
|
||||
friend Stream & operator<< ( Stream & s, Array<T> & p )
|
||||
|
@ -199,65 +199,65 @@ namespace
|
||||
|
||||
nvDebug( "\nDumping stacktrace:\n" );
|
||||
|
||||
// Resolve PC to function names
|
||||
for (int i = start; i < size; i++)
|
||||
{
|
||||
// Check for end of stack walk
|
||||
DWORD64 ip = (DWORD64)trace[i];
|
||||
if (ip == NULL)
|
||||
break;
|
||||
// Resolve PC to function names
|
||||
for (int i = start; i < size; i++)
|
||||
{
|
||||
// Check for end of stack walk
|
||||
DWORD64 ip = (DWORD64)trace[i];
|
||||
if (ip == NULL)
|
||||
break;
|
||||
|
||||
// Get function name
|
||||
#define MAX_STRING_LEN (512)
|
||||
unsigned char byBuffer[sizeof(IMAGEHLP_SYMBOL64) + MAX_STRING_LEN] = { 0 };
|
||||
IMAGEHLP_SYMBOL64 * pSymbol = (IMAGEHLP_SYMBOL64*)byBuffer;
|
||||
pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
||||
pSymbol->MaxNameLength = MAX_STRING_LEN;
|
||||
// Get function name
|
||||
#define MAX_STRING_LEN (512)
|
||||
unsigned char byBuffer[sizeof(IMAGEHLP_SYMBOL64) + MAX_STRING_LEN] = { 0 };
|
||||
IMAGEHLP_SYMBOL64 * pSymbol = (IMAGEHLP_SYMBOL64*)byBuffer;
|
||||
pSymbol->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64);
|
||||
pSymbol->MaxNameLength = MAX_STRING_LEN;
|
||||
|
||||
DWORD64 dwDisplacement;
|
||||
DWORD64 dwDisplacement;
|
||||
|
||||
if (SymGetSymFromAddr64(hProcess, ip, &dwDisplacement, pSymbol))
|
||||
{
|
||||
pSymbol->Name[MAX_STRING_LEN-1] = 0;
|
||||
|
||||
/*
|
||||
// Make the symbol readable for humans
|
||||
UnDecorateSymbolName( pSym->Name, lpszNonUnicodeUnDSymbol, BUFFERSIZE,
|
||||
UNDNAME_COMPLETE |
|
||||
UNDNAME_NO_THISTYPE |
|
||||
UNDNAME_NO_SPECIAL_SYMS |
|
||||
UNDNAME_NO_MEMBER_TYPE |
|
||||
UNDNAME_NO_MS_KEYWORDS |
|
||||
UNDNAME_NO_ACCESS_SPECIFIERS );
|
||||
*/
|
||||
|
||||
// pSymbol->Name
|
||||
const char * pFunc = pSymbol->Name;
|
||||
|
||||
// Get file/line number
|
||||
IMAGEHLP_LINE64 theLine = { 0 };
|
||||
theLine.SizeOfStruct = sizeof(theLine);
|
||||
|
||||
if (SymGetSymFromAddr64(hProcess, ip, &dwDisplacement, pSymbol))
|
||||
{
|
||||
pSymbol->Name[MAX_STRING_LEN-1] = 0;
|
||||
|
||||
/*
|
||||
// Make the symbol readable for humans
|
||||
UnDecorateSymbolName( pSym->Name, lpszNonUnicodeUnDSymbol, BUFFERSIZE,
|
||||
UNDNAME_COMPLETE |
|
||||
UNDNAME_NO_THISTYPE |
|
||||
UNDNAME_NO_SPECIAL_SYMS |
|
||||
UNDNAME_NO_MEMBER_TYPE |
|
||||
UNDNAME_NO_MS_KEYWORDS |
|
||||
UNDNAME_NO_ACCESS_SPECIFIERS );
|
||||
*/
|
||||
|
||||
// pSymbol->Name
|
||||
const char * pFunc = pSymbol->Name;
|
||||
|
||||
// Get file/line number
|
||||
IMAGEHLP_LINE64 theLine = { 0 };
|
||||
theLine.SizeOfStruct = sizeof(theLine);
|
||||
|
||||
DWORD dwDisplacement;
|
||||
if (!SymGetLineFromAddr64(hProcess, ip, &dwDisplacement, &theLine))
|
||||
{
|
||||
nvDebug("unknown(%08X) : %s\n", (uint32)ip, pFunc);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
const char* pFile = strrchr(theLine.FileName, '\\');
|
||||
if ( pFile == NULL ) pFile = theLine.FileName;
|
||||
else pFile++;
|
||||
*/
|
||||
const char * pFile = theLine.FileName;
|
||||
|
||||
int line = theLine.LineNumber;
|
||||
|
||||
nvDebug("%s(%d) : %s\n", pFile, line, pFunc);
|
||||
}
|
||||
DWORD dwDisplacement;
|
||||
if (!SymGetLineFromAddr64(hProcess, ip, &dwDisplacement, &theLine))
|
||||
{
|
||||
nvDebug("unknown(%08X) : %s\n", (uint32)ip, pFunc);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
const char* pFile = strrchr(theLine.FileName, '\\');
|
||||
if ( pFile == NULL ) pFile = theLine.FileName;
|
||||
else pFile++;
|
||||
*/
|
||||
const char * pFile = theLine.FileName;
|
||||
|
||||
int line = theLine.LineNumber;
|
||||
|
||||
nvDebug("%s(%d) : %s\n", pFile, line, pFunc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,6 +400,66 @@ namespace nv
|
||||
}
|
||||
#endif
|
||||
|
||||
// These two functions are not tested:
|
||||
|
||||
// By default we serialize the key-value pairs compactly.
|
||||
friend Stream & operator<< (Stream & s, HashMap<T, U, H, E> & map)
|
||||
{
|
||||
int entry_count = map.entry_count;
|
||||
s << entry_count;
|
||||
|
||||
if (s.isLoading()) {
|
||||
map.clear();
|
||||
map.entry_count = entry_count;
|
||||
map.size_mask = nextPowerOfTwo(entry_count) - 1;
|
||||
map.table = malloc<Entry>(map.size_mask + 1);
|
||||
|
||||
for (int i = 0; i <= map.size_mask; i++) {
|
||||
map.table[i].next_in_chain = -2; // mark empty
|
||||
}
|
||||
|
||||
T key;
|
||||
U value;
|
||||
for (int i = 0; i < entry_count; i++) {
|
||||
s << key << value;
|
||||
map.add(key, value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach(i, map) {
|
||||
s << map[i].key << map[i].value;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// This requires more storage, but saves us from rehashing the elements.
|
||||
friend Stream & rawSerialize(Stream & s, HashMap<T, U, H, E> & map)
|
||||
{
|
||||
if (s.isLoading()) {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
s << map.size_mask;
|
||||
|
||||
if (map.size_mask != -1) {
|
||||
s << map.entry_count;
|
||||
|
||||
if (s.isLoading()) {
|
||||
map.table = new Entry[map.size_mask+1];
|
||||
}
|
||||
|
||||
for (int i = 0; i <= map.size_mask; i++) {
|
||||
Entry & e = map.table[i];
|
||||
s << e.next_in_chain << e.hash_value;
|
||||
s << e.key;
|
||||
s << e.value;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "nvcore.h"
|
||||
#include "Stream.h"
|
||||
#include "Array.h"
|
||||
|
||||
#include <stdio.h> // fopen
|
||||
#include <string.h> // memcpy
|
||||
@ -308,6 +309,38 @@ namespace nv
|
||||
};
|
||||
|
||||
|
||||
/// Buffer output stream.
|
||||
class NVCORE_CLASS BufferOutputStream : public Stream
|
||||
{
|
||||
NV_FORBID_COPY(BufferOutputStream);
|
||||
public:
|
||||
|
||||
BufferOutputStream(Array<uint8> & buffer) : m_buffer(buffer) { }
|
||||
|
||||
virtual uint serialize( void * data, uint len )
|
||||
{
|
||||
nvDebugCheck(data != NULL);
|
||||
m_buffer.append((uint8 *)data, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
virtual void seek( uint pos ) { /*Not implemented*/ }
|
||||
virtual uint tell() const { return m_buffer.size(); }
|
||||
virtual uint size() const { return m_buffer.size(); }
|
||||
|
||||
virtual bool isError() const { return false; }
|
||||
virtual void clearError() {}
|
||||
|
||||
virtual bool isAtEnd() const { return true; }
|
||||
virtual bool isSeekable() const { return false; }
|
||||
virtual bool isLoading() const { return false; }
|
||||
virtual bool isSaving() const { return true; }
|
||||
|
||||
private:
|
||||
Array<uint8> & m_buffer;
|
||||
};
|
||||
|
||||
|
||||
/// Protected input stream.
|
||||
class NVCORE_CLASS ProtectedStream : public Stream
|
||||
{
|
||||
|
@ -95,21 +95,21 @@ namespace nv
|
||||
}
|
||||
|
||||
|
||||
inline uint sdbmHash(const void * data_in, uint size, uint h = 5381)
|
||||
{
|
||||
const uint8 * data = (const uint8 *) data_in;
|
||||
uint i = 0;
|
||||
while (i < size) {
|
||||
h = (h << 16) + (h << 6) - h + (uint) data[i++];
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
// Some hash functors:
|
||||
template <typename Key> struct Hash
|
||||
{
|
||||
inline uint sdbm_hash(const void * data_in, uint size, uint h = 5381) const
|
||||
{
|
||||
const uint8 * data = (const uint8 *) data_in;
|
||||
uint i = 0;
|
||||
while (i < size) {
|
||||
h = (h << 16) + (h << 6) - h + (uint) data[i++];
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
uint operator()(const Key & k) const {
|
||||
return sdbm_hash(&k, sizeof(Key));
|
||||
return sdbmHash(&k, sizeof(Key));
|
||||
}
|
||||
};
|
||||
template <> struct Hash<int>
|
||||
|
@ -153,6 +153,8 @@ typedef uint32 uint;
|
||||
#define NV_STRING2(x) #x
|
||||
#define NV_STRING(x) NV_STRING2(x)
|
||||
|
||||
#define NV_ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
#if 1
|
||||
#if NV_CC_MSVC
|
||||
#define NV_MESSAGE(x) message(__FILE__ "(" NV_STRING(__LINE__) ") : " x)
|
||||
|
Reference in New Issue
Block a user