Merge changes from the witness.
This commit is contained in:
@ -78,8 +78,8 @@ namespace nv
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool find(const T & element, const T * restrict ptr, uint count, uint * index) {
|
||||
for (uint i = 0; i < count; i++) {
|
||||
bool find(const T & element, const T * restrict ptr, uint begin, uint end, uint * index) {
|
||||
for (uint i = begin; i < end; i++) {
|
||||
if (ptr[i] == element) {
|
||||
if (index != NULL) *index = i;
|
||||
return true;
|
||||
@ -257,15 +257,15 @@ namespace nv
|
||||
}
|
||||
|
||||
/// Return true if element found.
|
||||
NV_FORCEINLINE bool find(const T & element, uint * index) const
|
||||
NV_FORCEINLINE bool find(const T & element, uint * indexPtr) const
|
||||
{
|
||||
return find(element, 0, m_size, index);
|
||||
return find(element, 0, m_size, indexPtr);
|
||||
}
|
||||
|
||||
/// Return true if element found within the given range.
|
||||
NV_FORCEINLINE bool find(const T & element, uint first, uint count, uint * index) const
|
||||
NV_FORCEINLINE bool find(const T & element, uint begin, uint end, uint * indexPtr) const
|
||||
{
|
||||
return ::nv::find(element, m_buffer + first, count, index);
|
||||
return ::nv::find(element, m_buffer, begin, end, indexPtr);
|
||||
}
|
||||
|
||||
/// Remove the element at the given index. This is an expensive operation!
|
||||
|
@ -448,19 +448,6 @@ namespace
|
||||
/** Win32 assert handler. */
|
||||
struct Win32AssertHandler : public AssertHandler
|
||||
{
|
||||
// Code from Daniel Vogel.
|
||||
static bool isDebuggerPresent()
|
||||
{
|
||||
HINSTANCE kernel32 = GetModuleHandle("kernel32.dll");
|
||||
if (kernel32) {
|
||||
FARPROC IsDebuggerPresent = GetProcAddress(kernel32, "IsDebuggerPresent");
|
||||
if (IsDebuggerPresent != NULL && IsDebuggerPresent()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Flush the message queue. This is necessary for the message box to show up.
|
||||
static void flushMessageQueue()
|
||||
{
|
||||
@ -487,7 +474,7 @@ namespace
|
||||
nvDebug( error_string.str() );
|
||||
}
|
||||
|
||||
if (isDebuggerPresent()) {
|
||||
if (debug::isDebuggerPresent()) {
|
||||
return NV_ABORT_DEBUG;
|
||||
}
|
||||
|
||||
@ -522,15 +509,6 @@ namespace
|
||||
/** Xbox360 assert handler. */
|
||||
struct Xbox360AssertHandler : public AssertHandler
|
||||
{
|
||||
static bool isDebuggerPresent()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
return DmIsDebuggerPresent() == TRUE;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Assert handler method.
|
||||
virtual int assertion( const char * exp, const char * file, int line, const char * func/*=NULL*/ )
|
||||
{
|
||||
@ -546,7 +524,7 @@ namespace
|
||||
nvDebug( error_string.str() );
|
||||
}
|
||||
|
||||
if (isDebuggerPresent()) {
|
||||
if (debug::isDebuggerPresent()) {
|
||||
return NV_ABORT_DEBUG;
|
||||
}
|
||||
|
||||
@ -563,26 +541,6 @@ namespace
|
||||
/** Unix assert handler. */
|
||||
struct UnixAssertHandler : public AssertHandler
|
||||
{
|
||||
bool isDebuggerPresent()
|
||||
{
|
||||
#if NV_OS_DARWIN
|
||||
int mib[4];
|
||||
struct kinfo_proc info;
|
||||
size_t size;
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_PID;
|
||||
mib[3] = getpid();
|
||||
size = sizeof(info);
|
||||
info.kp_proc.p_flag = 0;
|
||||
sysctl(mib,4,&info,&size,NULL,0);
|
||||
return ((info.kp_proc.p_flag & P_TRACED) == P_TRACED);
|
||||
#else
|
||||
// if ppid != sid, some process spawned our app, probably a debugger.
|
||||
return getsid(getpid()) != getppid();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Assert handler method.
|
||||
virtual int assertion(const char * exp, const char * file, int line, const char * func)
|
||||
{
|
||||
@ -594,7 +552,7 @@ namespace
|
||||
}
|
||||
|
||||
#if _DEBUG
|
||||
if (isDebuggerPresent()) {
|
||||
if (debug::isDebuggerPresent()) {
|
||||
return NV_ABORT_DEBUG;
|
||||
}
|
||||
#endif
|
||||
@ -702,7 +660,10 @@ void debug::enableSigHandler()
|
||||
// SYMOPT_DEFERRED_LOADS make us not take a ton of time unless we actual log traces
|
||||
SymSetOptions(SYMOPT_DEFERRED_LOADS|SYMOPT_FAIL_CRITICAL_ERRORS|SYMOPT_LOAD_LINES|SYMOPT_UNDNAME);
|
||||
|
||||
SymInitialize(GetCurrentProcess(), NULL, TRUE);
|
||||
if (!SymInitialize(GetCurrentProcess(), NULL, TRUE)) {
|
||||
DWORD error = GetLastError();
|
||||
nvDebug("SymInitialize returned error : %d\n", error);
|
||||
}
|
||||
|
||||
#elif !NV_OS_WIN32 && defined(HAVE_SIGNAL_H)
|
||||
|
||||
@ -743,3 +704,38 @@ void debug::disableSigHandler()
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool debug::isDebuggerPresent()
|
||||
{
|
||||
#if NV_OS_WIN32
|
||||
HINSTANCE kernel32 = GetModuleHandle("kernel32.dll");
|
||||
if (kernel32) {
|
||||
FARPROC IsDebuggerPresent = GetProcAddress(kernel32, "IsDebuggerPresent");
|
||||
if (IsDebuggerPresent != NULL && IsDebuggerPresent()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#elif NV_OS_XBOX
|
||||
#ifdef _DEBUG
|
||||
return DmIsDebuggerPresent() == TRUE;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
#elif NV_OS_DARWIN
|
||||
int mib[4];
|
||||
struct kinfo_proc info;
|
||||
size_t size;
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_PID;
|
||||
mib[3] = getpid();
|
||||
size = sizeof(info);
|
||||
info.kp_proc.p_flag = 0;
|
||||
sysctl(mib,4,&info,&size,NULL,0);
|
||||
return ((info.kp_proc.p_flag & P_TRACED) == P_TRACED);
|
||||
#else
|
||||
// if ppid != sid, some process spawned our app, probably a debugger.
|
||||
return getsid(getpid()) != getppid();
|
||||
#endif
|
||||
}
|
||||
|
@ -10,6 +10,9 @@
|
||||
# include <stdarg.h> // va_list
|
||||
#endif
|
||||
|
||||
// Make sure we are using our assert.
|
||||
#undef assert
|
||||
|
||||
#define NV_ABORT_DEBUG 1
|
||||
#define NV_ABORT_IGNORE 2
|
||||
#define NV_ABORT_EXIT 3
|
||||
@ -116,12 +119,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
#if __cplusplus > 199711L
|
||||
#define nvStaticCheck(x) static_assert(x)
|
||||
#else
|
||||
#define nvStaticCheck(x) typedef char NV_DO_STRING_JOIN2(__static_assert_,__LINE__)[(x)]
|
||||
#endif
|
||||
|
||||
NVCORE_API int nvAbort(const char *exp, const char *file, int line, const char * func = NULL);
|
||||
NVCORE_API void NV_CDECL nvDebugPrint( const char *msg, ... ) __attribute__((format (printf, 1, 2)));
|
||||
|
||||
@ -166,6 +163,8 @@ namespace nv
|
||||
|
||||
NVCORE_API void enableSigHandler();
|
||||
NVCORE_API void disableSigHandler();
|
||||
|
||||
NVCORE_API bool isDebuggerPresent();
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
|
@ -2,7 +2,7 @@
|
||||
#error "Do not include this file directly."
|
||||
#endif
|
||||
|
||||
//#include <stdint.h> // uint8_t, int8_t, ...
|
||||
#include <stdint.h> // uint8_t, int8_t, ... uintptr_t
|
||||
#include <cstddef> // operator new, size_t, NULL
|
||||
|
||||
// Function linkage
|
||||
@ -67,4 +67,4 @@ typedef int64_t int64;
|
||||
|
||||
// Aliases
|
||||
typedef uint32 uint;
|
||||
*/
|
||||
*/
|
||||
|
@ -12,10 +12,10 @@
|
||||
#include <new> // new and delete
|
||||
|
||||
|
||||
#if NV_CC_GNUC
|
||||
# define NV_ALIGN_16 __attribute__ ((__aligned__ (16)))
|
||||
#else
|
||||
# define NV_ALIGN_16 __declspec(align(16))
|
||||
#if NV_CC_GNUC
|
||||
# define NV_ALIGN_16 __attribute__ ((__aligned__ (16)))
|
||||
#else
|
||||
# define NV_ALIGN_16 __declspec(align(16))
|
||||
#endif
|
||||
|
||||
|
||||
@ -43,15 +43,15 @@ extern "C" {
|
||||
namespace nv {
|
||||
|
||||
// C++ helpers.
|
||||
template <typename T> T * malloc(size_t count) {
|
||||
template <typename T> NV_FORCEINLINE T * malloc(size_t count) {
|
||||
return (T *)::malloc(sizeof(T) * count);
|
||||
}
|
||||
|
||||
template <typename T> T * realloc(T * ptr, size_t count) {
|
||||
template <typename T> NV_FORCEINLINE T * realloc(T * ptr, size_t count) {
|
||||
return (T *)::realloc(ptr, sizeof(T) * count);
|
||||
}
|
||||
|
||||
template <typename T> void free(const T * ptr) {
|
||||
template <typename T> NV_FORCEINLINE void free(const T * ptr) {
|
||||
::free((void *)ptr);
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ namespace nv
|
||||
#if NV_OS_WIN32
|
||||
return _ftell_nolock(m_fp);
|
||||
#else
|
||||
return ftell(m_fp);
|
||||
return (uint)ftell(m_fp);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -85,9 +85,9 @@ namespace nv
|
||||
uint end = _ftell_nolock(m_fp);
|
||||
_fseek_nolock(m_fp, pos, SEEK_SET);
|
||||
#else
|
||||
uint pos = ftell(m_fp);
|
||||
uint pos = (uint)ftell(m_fp);
|
||||
fseek(m_fp, 0, SEEK_END);
|
||||
uint end = ftell(m_fp);
|
||||
uint end = (uint)ftell(m_fp);
|
||||
fseek(m_fp, pos, SEEK_SET);
|
||||
#endif
|
||||
return end;
|
||||
|
@ -189,7 +189,7 @@ StringBuilder::StringBuilder() : m_size(0), m_str(NULL)
|
||||
}
|
||||
|
||||
/** Preallocate space. */
|
||||
StringBuilder::StringBuilder( int size_hint ) : m_size(size_hint)
|
||||
StringBuilder::StringBuilder( uint size_hint ) : m_size(size_hint)
|
||||
{
|
||||
nvDebugCheck(m_size > 0);
|
||||
m_str = strAlloc(m_size);
|
||||
@ -203,9 +203,15 @@ StringBuilder::StringBuilder( const StringBuilder & s ) : m_size(0), m_str(NULL)
|
||||
}
|
||||
|
||||
/** Copy string. */
|
||||
StringBuilder::StringBuilder( const char * s, int extra_size_hint/*=0*/ ) : m_size(0), m_str(NULL)
|
||||
StringBuilder::StringBuilder(const char * s) : m_size(0), m_str(NULL)
|
||||
{
|
||||
copy(s, extra_size_hint);
|
||||
copy(s);
|
||||
}
|
||||
|
||||
/** Copy string. */
|
||||
StringBuilder::StringBuilder(const char * s, uint len) : m_size(0), m_str(NULL)
|
||||
{
|
||||
copy(s, len);
|
||||
}
|
||||
|
||||
/** Delete the string. */
|
||||
@ -396,15 +402,25 @@ StringBuilder & StringBuilder::reserve( uint size_hint )
|
||||
|
||||
|
||||
/** Copy a string safely. */
|
||||
StringBuilder & StringBuilder::copy( const char * s, int extra_size/*=0*/ )
|
||||
StringBuilder & StringBuilder::copy(const char * s)
|
||||
{
|
||||
nvCheck( s != NULL );
|
||||
const uint str_size = uint(strlen( s )) + 1;
|
||||
reserve(str_size + extra_size);
|
||||
reserve(str_size);
|
||||
memcpy(m_str, s, str_size);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Copy a string safely. */
|
||||
StringBuilder & StringBuilder::copy(const char * s, uint len)
|
||||
{
|
||||
nvCheck( s != NULL );
|
||||
const uint str_size = len + 1;
|
||||
reserve(str_size);
|
||||
strCpy(m_str, str_size, s, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/** Copy an StringBuilder. */
|
||||
StringBuilder & StringBuilder::copy( const StringBuilder & s )
|
||||
|
@ -59,9 +59,10 @@ namespace nv
|
||||
public:
|
||||
|
||||
StringBuilder();
|
||||
explicit StringBuilder( int size_hint );
|
||||
StringBuilder( const char * str, int extra_size_hint = 0);
|
||||
StringBuilder( const StringBuilder & );
|
||||
explicit StringBuilder( uint size_hint );
|
||||
StringBuilder(const char * str);
|
||||
StringBuilder(const char * str, uint len);
|
||||
StringBuilder(const StringBuilder & other);
|
||||
|
||||
~StringBuilder();
|
||||
|
||||
@ -75,9 +76,10 @@ namespace nv
|
||||
StringBuilder & number( int i, int base = 10 );
|
||||
StringBuilder & number( uint i, int base = 10 );
|
||||
|
||||
StringBuilder & reserve( uint size_hint );
|
||||
StringBuilder & copy( const char * str, int extra_size/*=0*/ );
|
||||
StringBuilder & copy( const StringBuilder & str );
|
||||
StringBuilder & reserve(uint size_hint);
|
||||
StringBuilder & copy(const char * str);
|
||||
StringBuilder & copy(const char * str, uint len);
|
||||
StringBuilder & copy(const StringBuilder & str);
|
||||
|
||||
StringBuilder & toLower();
|
||||
StringBuilder & toUpper();
|
||||
@ -145,7 +147,7 @@ namespace nv
|
||||
public:
|
||||
Path() : StringBuilder() {}
|
||||
explicit Path(int size_hint) : StringBuilder(size_hint) {}
|
||||
Path(const char * str, int extra_size_hint = 0) : StringBuilder(str, extra_size_hint) {}
|
||||
Path(const char * str) : StringBuilder(str) {}
|
||||
Path(const Path & path) : StringBuilder(path) {}
|
||||
|
||||
const char * fileName() const;
|
||||
|
@ -7,9 +7,76 @@
|
||||
#include "nvcore.h"
|
||||
#include "Debug.h" // nvDebugCheck
|
||||
|
||||
// Just in case. Grrr.
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
namespace nv
|
||||
{
|
||||
// Less error prone than casting. From CB:
|
||||
// http://cbloomrants.blogspot.com/2011/06/06-17-11-c-casting-is-devil.html
|
||||
inline int8 asSigned(uint8 x) { return (int8) x; }
|
||||
inline int16 asSigned(uint16 x) { return (int16) x; }
|
||||
inline int32 asSigned(uint32 x) { return (int32) x; }
|
||||
inline int64 asSigned(uint64 x) { return (int64) x; }
|
||||
|
||||
inline uint8 asUnsigned(int8 x) { return (uint8) x; }
|
||||
inline uint16 asUnsigned(int16 x) { return (uint16) x; }
|
||||
inline uint32 asUnsigned(int32 x) { return (uint32) x; }
|
||||
inline uint64 asUnsigned(int64 x) { return (uint64) x; }
|
||||
|
||||
/*
|
||||
template <typename T> inline int8 toI8(T x) {
|
||||
nvDebugCheck(x <= INT8_MAX);
|
||||
nvDebugCheck(x >= INT8_MIN);
|
||||
int8 y = (int8) x;
|
||||
nvDebugCheck(x == (T)y);
|
||||
return y;
|
||||
}
|
||||
|
||||
template <typename T> inline uint8 toU8(T x) {
|
||||
nvDebugCheck(x <= UINT8_MAX);
|
||||
nvDebugCheck(x >= 0);
|
||||
return (uint8) x;
|
||||
}
|
||||
|
||||
template <typename T> inline int16 toI16(T x) {
|
||||
nvDebugCheck(x <= INT16_MAX);
|
||||
nvDebugCheck(x >= INT16_MIN);
|
||||
return (int16) x;
|
||||
}
|
||||
|
||||
template <typename T> inline uint16 toU16(T x) {
|
||||
nvDebugCheck(x <= UINT16_MAX);
|
||||
nvDebugCheck(x >= 0);
|
||||
return (uint16) x;
|
||||
}
|
||||
|
||||
template <typename T> inline int32 toI32(T x) {
|
||||
nvDebugCheck(x <= INT32_MAX);
|
||||
nvDebugCheck(x >= INT32_MIN);
|
||||
return (int32) x;
|
||||
}
|
||||
|
||||
template <typename T> inline uint32 toU32(T x) {
|
||||
nvDebugCheck(x <= UINT32_MAX);
|
||||
nvDebugCheck(x >= 0);
|
||||
return (uint32) x;
|
||||
}
|
||||
|
||||
template <typename T> inline int64 toI64(T x) {
|
||||
nvDebugCheck(x <= INT64_MAX);
|
||||
nvDebugCheck(x >= INT64_MIN);
|
||||
return (int64) x;
|
||||
}
|
||||
|
||||
template <typename T> inline uint64 toU64(T x) {
|
||||
nvDebugCheck(x <= UINT64_MAX);
|
||||
nvDebugCheck(x >= 0);
|
||||
return (uint64) x;
|
||||
}
|
||||
*/
|
||||
|
||||
/// Swap two values.
|
||||
template <typename T>
|
||||
inline void swap(T & a, T & b)
|
||||
|
@ -4,9 +4,6 @@
|
||||
#ifndef NV_CORE_H
|
||||
#define NV_CORE_H
|
||||
|
||||
// cmake config
|
||||
#include <nvconfig.h>
|
||||
|
||||
// Function linkage
|
||||
#if NVCORE_SHARED
|
||||
#ifdef NVCORE_EXPORTS
|
||||
@ -91,7 +88,11 @@
|
||||
// @@ NV_CC_MSVC7
|
||||
// @@ NV_CC_MSVC8
|
||||
|
||||
#if defined POSH_COMPILER_GCC
|
||||
#if defined POSH_COMPILER_CLANG
|
||||
# define NV_CC_CLANG 1
|
||||
# define NV_CC_GCC 1 // Clang is compatible with GCC.
|
||||
# define NV_CC_STRING "clang"
|
||||
#elif defined POSH_COMPILER_GCC
|
||||
# define NV_CC_GNUC 1
|
||||
# define NV_CC_STRING "gcc"
|
||||
#elif defined POSH_COMPILER_MSVC
|
||||
@ -108,6 +109,18 @@
|
||||
#define NV_ENDIAN_STRING POSH_ENDIAN_STRING
|
||||
|
||||
|
||||
// Define the right printf prefix for size_t arguments:
|
||||
#if POSH_64BIT_POINTER
|
||||
# define NV_SIZET_PRINTF_PREFIX POSH_I64_PRINTF_PREFIX
|
||||
#else
|
||||
# define NV_SIZET_PRINTF_PREFIX
|
||||
#endif
|
||||
|
||||
|
||||
// cmake config
|
||||
#include "nvconfig.h"
|
||||
|
||||
|
||||
// Type definitions:
|
||||
typedef posh_u8_t uint8;
|
||||
typedef posh_i8_t int8;
|
||||
@ -144,6 +157,8 @@ typedef uint32 uint;
|
||||
private: \
|
||||
void *operator new(size_t size); \
|
||||
void *operator new[](size_t size);
|
||||
//static void *operator new(size_t size); \
|
||||
//static void *operator new[](size_t size);
|
||||
|
||||
// String concatenation macros.
|
||||
#define NV_STRING_JOIN2(arg1, arg2) NV_DO_STRING_JOIN2(arg1, arg2)
|
||||
@ -153,6 +168,25 @@ typedef uint32 uint;
|
||||
#define NV_STRING2(x) #x
|
||||
#define NV_STRING(x) NV_STRING2(x)
|
||||
|
||||
|
||||
#if __cplusplus > 199711L
|
||||
#define nvStaticCheck(x) static_assert(x)
|
||||
#else
|
||||
#define nvStaticCheck(x) typedef char NV_STRING_JOIN2(__static_assert_,__LINE__)[(x)]
|
||||
#endif
|
||||
#define NV_COMPILER_CHECK(x) nvStaticCheck(x) // I like this name best.
|
||||
|
||||
// Make sure type definitions are fine.
|
||||
NV_COMPILER_CHECK(sizeof(int8) == 1);
|
||||
NV_COMPILER_CHECK(sizeof(uint8) == 1);
|
||||
NV_COMPILER_CHECK(sizeof(int16) == 2);
|
||||
NV_COMPILER_CHECK(sizeof(uint16) == 2);
|
||||
NV_COMPILER_CHECK(sizeof(int32) == 4);
|
||||
NV_COMPILER_CHECK(sizeof(uint32) == 4);
|
||||
NV_COMPILER_CHECK(sizeof(int32) == 4);
|
||||
NV_COMPILER_CHECK(sizeof(uint32) == 4);
|
||||
|
||||
|
||||
#define NV_ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
#if 1
|
||||
@ -180,6 +214,7 @@ typedef uint32 uint;
|
||||
|
||||
// Null index. @@ Move this somewhere else... it's only used by nvmesh.
|
||||
//const unsigned int NIL = unsigned int(~0);
|
||||
//#define NIL uint(~0)
|
||||
|
||||
// Null pointer.
|
||||
#ifndef NULL
|
||||
|
Reference in New Issue
Block a user