Skip to content

Commit

Permalink
v0.84
Browse files Browse the repository at this point in the history
Synchronized to v0.84 release
  • Loading branch information
ffulin committed Jul 29, 2015
1 parent 6502dd4 commit 51a956f
Show file tree
Hide file tree
Showing 114 changed files with 3,273 additions and 520 deletions.
2 changes: 1 addition & 1 deletion Code/Core/Core.bff
Expand Up @@ -9,7 +9,7 @@
//--------------------------------------------------------------------------
VCXProject( '$ProjectName$-proj' )
{
.ProjectOutput = '$ProjectPath$\$ProjectName$.vcxproj'
.ProjectOutput = '../tmp/VisualStudio/Projects/$ProjectName$.vcxproj'
.ProjectInputPaths = '$ProjectPath$\'
.ProjectBasePath = '$ProjectPath$\'

Expand Down
4 changes: 2 additions & 2 deletions Code/Core/CoreTest/CoreTest.bff
Expand Up @@ -8,11 +8,11 @@
//--------------------------------------------------------------------------
VCXProject( '$ProjectName$-proj' )
{
.ProjectOutput = '$ProjectPath$\$ProjectName$.vcxproj'
.ProjectOutput = '../tmp/VisualStudio/Projects/$ProjectName$.vcxproj'
.ProjectInputPaths = '$ProjectPath$\'
.ProjectBasePath = '$ProjectPath$\'

.LocalDebuggerCommand = '^$(SolutionDir)..\..\..\tmp\^$(Configuration)\Core\CoreTest\CoreTest.exe'
.LocalDebuggerCommand = '^$(SolutionDir)..\^$(Configuration)\Core\CoreTest\CoreTest.exe'
}

// Unity
Expand Down
1 change: 1 addition & 0 deletions Code/Core/CoreTest/TestMain.cpp
Expand Up @@ -15,6 +15,7 @@ int main(int , char * [])
// Tests to run
REGISTER_TESTGROUP( TestAtomic )
REGISTER_TESTGROUP( TestAString )
REGISTER_TESTGROUP( TestEnv )
REGISTER_TESTGROUP( TestFileIO )
REGISTER_TESTGROUP( TestHash )
REGISTER_TESTGROUP( TestMemPoolBlock )
Expand Down
52 changes: 52 additions & 0 deletions Code/Core/CoreTest/Tests/TestEnv.cpp
@@ -0,0 +1,52 @@
// TestEnv.cpp
//------------------------------------------------------------------------------

// Includes
//------------------------------------------------------------------------------
#include "TestFramework/UnitTest.h"

// Core
#include <Core/Env/Env.h>
#include <Core/Strings/AStackString.h>

// TestEnv
//------------------------------------------------------------------------------
class TestEnv : public UnitTest
{
private:
DECLARE_TESTS

void GetCommandLine() const;
void GetExePath() const;
};

// Register Tests
//------------------------------------------------------------------------------
REGISTER_TESTS_BEGIN( TestEnv )
REGISTER_TEST( GetCommandLine )
REGISTER_TEST( GetExePath )
REGISTER_TESTS_END

// GetCommandLine
//------------------------------------------------------------------------------
void TestEnv::GetCommandLine() const
{
AStackString<> cmdLine;
Env::GetCmdLine( cmdLine );
TEST_ASSERT( cmdLine.FindI( "CoreTest" ) );
}

// GetExePath
//------------------------------------------------------------------------------
void TestEnv::GetExePath() const
{
AStackString<> cmdLine;
Env::GetExePath( cmdLine );
#if defined( __WINDOWS__ )
TEST_ASSERT( cmdLine.EndsWithI( "CoreTest.exe" ) );
#else
TEST_ASSERT( cmdLine.EndsWithI( "CoreTest" ) );
#endif
}

//------------------------------------------------------------------------------
21 changes: 11 additions & 10 deletions Code/Core/CoreTest/Tests/TestTCPConnectionPool.cpp
Expand Up @@ -160,16 +160,6 @@ void TestTestTCPConnectionPool::TestConnectionCount() const
//------------------------------------------------------------------------------
void TestTestTCPConnectionPool::TestDataTransfer() const
{
const uint16_t testPort( TEST_PORT );

// a big piece of data, initialized to some known pattern
#define maxDataSize size_t( 1024 * 1024 * 10 )
AutoPtr< char > data( (char *)ALLOC( maxDataSize ) );
for ( size_t i=0; i< maxDataSize; ++i )
{
data.Get()[ i ] = (char)i;
}

// a special server which will assert that it receives some expected data
class TestServer : public TCPConnectionPool
{
Expand All @@ -186,6 +176,17 @@ void TestTestTCPConnectionPool::TestDataTransfer() const
bool m_ReceivedOK;
size_t m_DataSize;
};

const uint16_t testPort( TEST_PORT );

// a big piece of data, initialized to some known pattern
#define maxDataSize size_t( 1024 * 1024 * 10 )
AutoPtr< char > data( (char *)ALLOC( maxDataSize ) );
for ( size_t i=0; i< maxDataSize; ++i )
{
data.Get()[ i ] = (char)i;
}

TestServer server;
TEST_ASSERT( server.Listen( testPort ) );

Expand Down
64 changes: 51 additions & 13 deletions Code/Core/Env/Env.cpp
Expand Up @@ -17,10 +17,23 @@

#if defined( __LINUX__ ) || defined( __APPLE__ )
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif

#if defined( __LINUX__ )
#include <linux/limits.h>
#endif

#if defined( __APPLE__ )
extern "C"
{
int *_NSGetArgc(void);
char ***_NSGetArgv(void);
};
#endif

// GetNumProcessors
//------------------------------------------------------------------------------
/*static*/ uint32_t Env::GetNumProcessors()
Expand Down Expand Up @@ -96,18 +109,42 @@

// GetCmdLine
//------------------------------------------------------------------------------
/*static*/ const char * Env::GetCmdLine()
/*static*/ void Env::GetCmdLine( AString & cmdLine )
{
#if defined( __WINDOWS__ )
return ::GetCommandLine();
cmdLine = ::GetCommandLine();
#elif defined( __APPLE__ )
ASSERT( false ); // TODO:MAC Implement GetCmdLine
return nullptr;
#elif defined( __LINUX__ )
ASSERT( false ); // TODO:LINUX Implement GetCmdLine
return nullptr;
int argc = *_NSGetArgc();
const char ** argv = const_cast< const char ** >( *_NSGetArgv() );
for ( int i=0; i<argc; ++i )
{
if ( i > 0 )
{
cmdLine += ' ';
}
cmdLine += argv[i];
}
#else
#error Unknown platform
FILE* f = fopen( "/proc/self/cmdline", "rb" );
VERIFY( f != 0 );
char buffer[ 4096 ];
for (;;)
{
int size = fread( buffer, 1, 4096, f );
if ( size == 0 )
{
break;
}

// Append
for ( int i=0; i<size; ++i )
{
const char c = buffer[ i ];
cmdLine += ( c ? c : ' ' ); // convert nulls in between args back into spaces
}
}
VERIFY( fclose( f ) == 0 );

#endif
}

Expand All @@ -121,11 +158,12 @@ void Env::GetExePath( AString & output )
GetModuleFileNameA( hModule, path, MAX_PATH );
output = path;
#elif defined( __APPLE__ )
ASSERT( false ); // TODO:MAC Implement GetExePath
#elif defined( __LINUX__ )
ASSERT( false ); // TODO:LINUX Implement GetExePath
#else
#error Unknown platform
const char ** argv = const_cast< const char ** >( *_NSGetArgv() );
output = argv[0];
#else
char path[ PATH_MAX ];
VERIFY( readlink( "/proc/self/exe", path, PATH_MAX ) != -1 );
output = path;
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Code/Core/Env/Env.h
Expand Up @@ -33,7 +33,7 @@ class Env
static uint32_t GetNumProcessors();

static bool GetEnvVariable( const char * envVarName, AString & envVarValue );
static const char * GetCmdLine();
static void GetCmdLine( AString & cmdLine );
static void GetExePath( AString & path );

static uint32_t GetLastErr();
Expand Down
2 changes: 1 addition & 1 deletion Code/Core/Math/Random.h
Expand Up @@ -19,7 +19,7 @@ class Random
Random();

// seed with a specific value
inline Random( uint32_t seed ) : m_Seed( seed ) {}
explicit inline Random( uint32_t seed ) : m_Seed( seed ) {}

// random number from 0 to RAND_MAX
uint32_t GetRand();
Expand Down
16 changes: 12 additions & 4 deletions Code/Core/Mem/MemPoolBlock.cpp
Expand Up @@ -30,7 +30,9 @@ MemPoolBlock::MemPoolBlock( size_t blockSize, size_t blockAlignment )
MemPoolBlock::~MemPoolBlock()
{
// Ensure no memory leaks
ASSERT( m_NumAllocations == 0 );
#ifdef DEBUG
ASSERT( m_NumAllocations == 0 );
#endif

// free pages
void ** end = m_Pages.End();
Expand All @@ -54,7 +56,9 @@ void * MemPoolBlock::Alloc( size_t size )
ASSERT( m_FreeBlockChain );
}

m_NumAllocations++;
#ifdef DEBUG
m_NumAllocations++;
#endif

// Take first block from free chain
FreeBlock * block = m_FreeBlockChain;
Expand All @@ -66,14 +70,18 @@ void * MemPoolBlock::Alloc( size_t size )
//------------------------------------------------------------------------------
void MemPoolBlock::Free( void * ptr )
{
ASSERT( m_NumAllocations > 0 );
#ifdef DEBUG
ASSERT( m_NumAllocations > 0 );
#endif

// Insert free block into head of chain
FreeBlock * freeBlock = reinterpret_cast< FreeBlock * >( ptr );
freeBlock->m_Next = m_FreeBlockChain;
m_FreeBlockChain = freeBlock;

--m_NumAllocations;
#ifdef DEBUG
--m_NumAllocations;
#endif
}

// AlocPage
Expand Down
4 changes: 3 additions & 1 deletion Code/Core/Mem/MemPoolBlock.h
Expand Up @@ -31,7 +31,9 @@ class MemPoolBlock
FreeBlock * m_FreeBlockChain;

// total number of active allocations
uint32_t m_NumAllocations;
#ifdef DEBUG
uint32_t m_NumAllocations;
#endif

// internal control params
size_t m_BlockSize;
Expand Down
2 changes: 1 addition & 1 deletion Code/Core/Mem/MemTracker.cpp
Expand Up @@ -23,7 +23,7 @@
//------------------------------------------------------------------------------
/*static*/ uint32_t MemTracker::s_Id( 0 );
/*static*/ bool MemTracker::s_Enabled( true );
/*static*/ bool MemTracker::s_Initialized( false );
/*static*/ volatile bool MemTracker::s_Initialized( false );
/*static*/ uint32_t MemTracker::s_AllocationCount( 0 );
/*static*/ uint64_t MemTracker::s_Mutex[];
/*static*/ MemTracker::Allocation ** MemTracker::s_AllocationHashTable = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions Code/Core/Mem/MemTracker.h
Expand Up @@ -7,7 +7,7 @@
// Enabled in DEBUG only
//------------------------------------------------------------------------------
#ifdef DEBUG
#if !defined( __APPLE__ ) // TODO:MAC Fix MemTracker
#if !defined( __APPLE__ ) && !defined( __LINUX__ )// TODO:MAC TODO:LINUX Fix MemTracker
#define MEMTRACKER_ENABLED
#endif
#endif
Expand Down Expand Up @@ -63,7 +63,7 @@

static uint32_t s_Id;
static bool s_Enabled;
static bool s_Initialized;
static volatile bool s_Initialized;
static uint32_t s_AllocationCount;
static Allocation * s_LastAllocation;
static uint64_t s_Mutex[ sizeof( Mutex ) / sizeof( uint64_t ) ];
Expand Down
5 changes: 3 additions & 2 deletions Code/Core/Reflection/MetaData/MetaData.cpp
Expand Up @@ -52,10 +52,11 @@ IMetaData & MetaNone()
{
// We have to return by reference to be able to implement the chainign + operator
// but everything is managed as a ptr internally so this is ok
PRAGMA_DISABLE_PUSH_MSVC( 6011 ); // null deref is deliberate
IMetaData * md = nullptr;
return *md;
PRAGMA_DISABLE_PUSH_MSVC( 6011 ); // null deref is deliberate
IMetaData& mdRef = *md;
PRAGMA_DISABLE_POP_MSVC
return mdRef;
}

// Basic MetaData Types
Expand Down
2 changes: 1 addition & 1 deletion Code/Core/Reflection/RefObject.cpp
Expand Up @@ -35,7 +35,7 @@ void RefObject_ReflectionInfo_Bind()
}
src = src->GetSuperClass();
}
return nullptr;
return false;
}

//------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion Code/Core/Reflection/ReflectedProperty.h
Expand Up @@ -117,7 +117,7 @@ class ReflectedProperty
uint32_t m_Offset:16; // validated by MAX_OFFSET
uint32_t m_Type:8;
uint32_t m_IsArray:1;
uint32_t m_Unused:7;
//uint32_t m_Unused:7;

#if defined( REFLECTION_KEEP_STRING_NAMES )
const char * m_Name;
Expand Down
3 changes: 2 additions & 1 deletion Code/Core/Reflection/ReflectionInfo.cpp
Expand Up @@ -32,7 +32,8 @@
// CONSTRUCTOR
//------------------------------------------------------------------------------
ReflectionInfo::ReflectionInfo()
: m_Properties( 0, true )
: m_TypeNameCRC( 0 )
, m_Properties( 0, true )
, m_SuperClass( nullptr )
, m_Next( nullptr )
, m_TypeName( nullptr )
Expand Down
1 change: 0 additions & 1 deletion Code/Core/Reflection/Serialization/TextReader.h
Expand Up @@ -38,7 +38,6 @@ class TextReader
bool ReadChildren();
bool ReadProperty( PropertyType propertyType );

inline bool IsAtEnd() const { return ( m_Pos == m_End ); }
void SkipWhitespace( bool stopAtLineEnd = false );
bool GetToken( AString & token );
bool GetString( AString & string );
Expand Down
18 changes: 18 additions & 0 deletions Code/Core/Strings/AString.cpp
Expand Up @@ -513,6 +513,24 @@ void AString::ToLower()
}
}

// ToUpper
//------------------------------------------------------------------------------
void AString::ToUpper()
{
char * pos = m_Contents;
char * end = m_Contents + m_Length;
while ( pos < end )
{
char c = *pos;
if ( ( c >= 'a' ) && ( c <= 'z' ) )
{
c = 'A' + ( c - 'a' );
*pos = c;
}
pos++;
}
}

// Replace ( char *, char * )
//------------------------------------------------------------------------------
uint32_t AString::Replace( const char * from, const char * to, uint32_t maxReplaces )
Expand Down

0 comments on commit 51a956f

Please sign in to comment.