Create FailWithMessage/AssertWithMessage
Migrate some very frequently called macros from global.h to global.cpp. This reduces Windows release executable size by 43 KB. After moving ASSERT_M and FAIL_M into void functions, these two virtuals in RageFileBasic.h won't compile as they don't return a value. This changes them to return a default value.
This commit is contained in:
+12
-4
@@ -100,12 +100,20 @@ public:
|
|||||||
virtual int GetFileSize() const = 0;
|
virtual int GetFileSize() const = 0;
|
||||||
virtual int GetFD() { return -1; }
|
virtual int GetFD() { return -1; }
|
||||||
virtual RString GetDisplayPath() const { return RString(); }
|
virtual RString GetDisplayPath() const { return RString(); }
|
||||||
virtual RageFileBasic *Copy() const { FAIL_M( "Copying unimplemented" ); }
|
virtual RageFileBasic* Copy() const
|
||||||
|
{
|
||||||
|
FAIL_M("Copying unimplemented");
|
||||||
|
return nullptr; // Return a default value - the return value is unused
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int SeekInternal( int /* iOffset */ ) { FAIL_M( "Seeking unimplemented" ); }
|
virtual int SeekInternal(int /* iOffset */)
|
||||||
virtual int ReadInternal( void *pBuffer, size_t iBytes ) = 0;
|
{
|
||||||
virtual int WriteInternal( const void *pBuffer, size_t iBytes ) = 0;
|
FAIL_M("Seeking unimplemented");
|
||||||
|
return -1; // Return a default value - the return value is unused
|
||||||
|
}
|
||||||
|
virtual int ReadInternal(void* pBuffer, size_t iBytes) = 0;
|
||||||
|
virtual int WriteInternal(const void* pBuffer, size_t iBytes) = 0;
|
||||||
virtual int FlushInternal() { return 0; }
|
virtual int FlushInternal() { return 0; }
|
||||||
|
|
||||||
void EnableReadBuffering();
|
void EnableReadBuffering();
|
||||||
|
|||||||
@@ -25,6 +25,19 @@
|
|||||||
#include "archutils/Unix/CrashHandler.h"
|
#include "archutils/Unix/CrashHandler.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void FailWithMessage(const char* message)
|
||||||
|
{
|
||||||
|
CHECKPOINT_M(message);
|
||||||
|
sm_crash(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertWithMessage(bool condition, const char* message)
|
||||||
|
{
|
||||||
|
if (unlikely(!condition)) {
|
||||||
|
FailWithMessage(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void sm_crash( const char *reason )
|
void sm_crash( const char *reason )
|
||||||
{
|
{
|
||||||
#if ( defined(_WIN32) && defined(CRASH_HANDLER) ) || defined(MACOSX) || defined(_XDBG)
|
#if ( defined(_WIN32) && defined(CRASH_HANDLER) ) || defined(MACOSX) || defined(_XDBG)
|
||||||
|
|||||||
+10
-4
@@ -66,13 +66,19 @@ void sm_crash( const char *reason = "Internal error" );
|
|||||||
*
|
*
|
||||||
* This should probably be used instead of throwing an exception in most
|
* This should probably be used instead of throwing an exception in most
|
||||||
* cases we expect never to happen (but not in cases that we do expect,
|
* cases we expect never to happen (but not in cases that we do expect,
|
||||||
* such as DSound init failure.) */
|
* such as DSound init failure.)
|
||||||
#define FAIL_M(MESSAGE) do { CHECKPOINT_M(MESSAGE); sm_crash(MESSAGE); } while(0)
|
*
|
||||||
#define ASSERT_M(COND, MESSAGE) do { if(unlikely(!(COND))) { FAIL_M(MESSAGE); } } while(0)
|
* There are macros here for legacy compatibility so we don't have
|
||||||
|
* to change or fix hundreds of calls to FAIL_M / ASSERT_M / ASSERT.
|
||||||
|
*/
|
||||||
|
void FailWithMessage(const char* message);
|
||||||
|
#define FAIL_M(MESSAGE) FailWithMessage(MESSAGE)
|
||||||
|
|
||||||
|
void AssertWithMessage(bool condition, const char* message);
|
||||||
|
#define ASSERT_M(COND, MESSAGE) AssertWithMessage((COND), MESSAGE)
|
||||||
|
|
||||||
#if !defined(CO_EXIST_WITH_MFC)
|
#if !defined(CO_EXIST_WITH_MFC)
|
||||||
#define ASSERT(COND) ASSERT_M((COND), "Assertion '" #COND "' failed")
|
#define ASSERT(COND) AssertWithMessage((COND), "Assertion '" #COND "' failed")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** @brief Use this to catch switching on invalid values */
|
/** @brief Use this to catch switching on invalid values */
|
||||||
|
|||||||
Reference in New Issue
Block a user