From 11810e05e40e24de14a3f0213f978853ba632e9f Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Fri, 9 Mar 2012 09:39:48 +0000 Subject: Using the _DEBUG macro for *nix debug builds as well; trying to force 8-byte alignment on critical sections ( http://forum.mc-server.org/showthread.php?tid=384 ) git-svn-id: http://mc-server.googlecode.com/svn/trunk@387 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- GNUmakefile | 4 +- WebServer/Globals.h | 96 +---------------------------------------------- makefile.debug | 4 +- source/Globals.h | 65 +++++++++++++++++++++++--------- source/NBT.cpp | 4 +- source/NBT.h | 4 +- source/WorldStorage.h | 2 +- source/cCriticalSection.h | 6 +-- source/main.cpp | 4 +- 9 files changed, 62 insertions(+), 127 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 5353f19a0..25dd2b1b3 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -30,8 +30,8 @@ CCE_OPTIONS = -s -x c -O3 LNK_OPTIONS = -lstdc++ -pthread -O3 BUILDDIR = build/release/ else -CC_OPTIONS = -s -ggdb -CCE_OPTIONS = -s -x c -ggdb +CC_OPTIONS = -s -ggdb -D_DEBUG +CCE_OPTIONS = -s -x c -ggdb -D_DEBUG LNK_OPTIONS = -lstdc++ -pthread -ggdb BUILDDIR = build/debug/ endif diff --git a/WebServer/Globals.h b/WebServer/Globals.h index 2ef0b70ac..fd31ba703 100644 --- a/WebServer/Globals.h +++ b/WebServer/Globals.h @@ -8,101 +8,7 @@ -// Compiler-dependent stuff: -#ifndef _MSC_VER - // Non-MS compilers don't know the override keyword - #define override -#else - // MSVC produces warning C4481 on the override keyword usage, so disable the warning altogether - #pragma warning(disable:4481) -#endif // _MSC_VER - - - - - -// A macro to disallow the copy constructor and operator= functions -// This should be used in the private: declarations for any class that shouldn't allow copying itself -#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName &); \ - void operator=(const TypeName &) - - - - - -// OS-dependent stuff: -#ifdef _WIN32 - #define WIN32_LEAN_AND_MEAN - #include - #include -#else - #include - #include // for mkdir - #include - #include - #include - #include - #include - #include - #include - #include - #include - - #include - #include - #include - #include - #include - #include - #include -#endif - - - - - -// CRT stuff: -#include -#include -#include - - - - - -// STL stuff: -#include -#include -#include -#include -#include -#include - - - - - -// Common headers: -#include "../source/StringUtils.h" -#include "../source/cCriticalSection.h" -#include "../source/cMCLogger.h" - - - - - -// Common definitions: - -/// Evaluates to the number of elements in an array (compile-time!) -#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X))) - -// sprintf_s is the preferred call in MSVC ("secure"); make it *nix-compatible: -#ifndef _WIN32 - #define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__ ) - #define vsnprintf_s(buffer, buffer_size, maxcount, stringbuffer, ...) (vsnprintf(buffer, maxcount, stringbuffer, __VA_ARGS__)) -#endif // _WIN32 - +#include "../source/Globals.h" diff --git a/makefile.debug b/makefile.debug index e7d8b90d3..898c23c5d 100644 --- a/makefile.debug +++ b/makefile.debug @@ -10,8 +10,8 @@ # _X: These settings produce a debug build, with gdb symbols: -CC_OPTIONS = -s -ggdb -CCE_OPTIONS = -s -x c -ggdb +CC_OPTIONS = -s -ggdb -D_DEBUG +CCE_OPTIONS = -s -x c -ggdb -D_DEBUG LNK_OPTIONS = -lstdc++ -pthread -ggdb diff --git a/source/Globals.h b/source/Globals.h index 0d6694e11..6291c51e8 100644 --- a/source/Globals.h +++ b/source/Globals.h @@ -9,18 +9,57 @@ // Compiler-dependent stuff: -#ifndef _MSC_VER - // Non-MS compilers don't know the override keyword - #define override - #define abstract - #define stricmp strcasecmp -#else +#if defined(_MSC_VER) // MSVC produces warning C4481 on the override keyword usage, so disable the warning altogether #pragma warning(disable:4481) // Disable some warnings that we don't care about: #pragma warning(disable:4100) -#endif // _MSC_VER + + #define OBSOLETE __declspec(deprecated) + + // No alignment needed in MSVC + #define ALIGN_8 + #define ALIGN_16 + +#elif defined(__GNUC__) + + // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? + #define abstract + + // TODO: Can GCC mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) + #define override + + #define OBSOLETE __attribute__((deprecated)) + + #define ALIGN_8 __attribute__((aligned(8))) + #define ALIGN_16 __attribute__((aligned(16))) + + // Some portability macros :) + #define stricmp strcasecmp + +#else + + #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" + + /* + // Copy and uncomment this into another #elif section based on your compiler identification + + // Explicitly mark classes as abstract (no instances can be created) + #define abstract + + // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class) + #define override + + // Mark functions as obsolete, so that their usage results in a compile-time warning + #define OBSOLETE + + // Mark types / variables for alignment. Do the platforms need it? + #define ALIGN_8 + #define ALIGN_16 + */ + +#endif @@ -40,7 +79,7 @@ #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include - #include + #include #else #include #include // for mkdir @@ -112,16 +151,6 @@ /// Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it, "(32 KiB)" ) #define KiB * 1024 -#ifdef _MSC_VER - #define OBSOLETE __declspec(deprecated) - #define ABSTRACT abstract -#else - // TODO: how do other compilers mark functions as obsolete, so that their usage results in a compile-time warning? - #define OBSOLETE - // TODO: Can other compilers explicitly mark classes as abstract (no instances can be created)? - #define ABSTRACT -#endif - /// Faster than (int)floorf((float)x / (float)div) #define FAST_FLOOR_DIV( x, div ) ( (x) < 0 ? (((int)x / div) - 1) : ((int)x / div) ) diff --git a/source/NBT.cpp b/source/NBT.cpp index c600a1868..928ef8080 100644 --- a/source/NBT.cpp +++ b/source/NBT.cpp @@ -622,7 +622,7 @@ cNBTTree * cNBTParser::Parse(const char * a_Data, int a_Length) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Dumping the NBT tree (debug-only) -#ifdef _DEBUG +#if (defined(_DEBUG) && defined(_WIN32)) #define CASE_SIMPLE_TAG(TYPE,FMT) \ case cNBTTag::TAG_##TYPE: \ @@ -696,7 +696,7 @@ void DumpTree(const cNBTTree * a_Tree, int a_Level) #undef CASE_SIMPLE_TAG -#endif // _DEBUG +#endif // (_DEBUG && _WIN32) diff --git a/source/NBT.h b/source/NBT.h index a05e574de..75ff6e361 100644 --- a/source/NBT.h +++ b/source/NBT.h @@ -203,9 +203,9 @@ public: /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Dumping the tree (DEBUG-only) -#ifdef _DEBUG +#if (defined(_DEBUG) && defined(_WIN32)) void DumpTree(const cNBTTree * a_Tree, int a_Level = 0); -#endif // _DEBUG +#endif // (_DEBUG && _WIN32) diff --git a/source/WorldStorage.h b/source/WorldStorage.h index 689d5f1ef..0845a7ce7 100644 --- a/source/WorldStorage.h +++ b/source/WorldStorage.h @@ -31,7 +31,7 @@ class cBlockEntity; /// Interface that all the world storage schemas need to implement -class cWSSchema ABSTRACT +class cWSSchema abstract { public: cWSSchema(cWorld * a_World) : m_World(a_World) {} diff --git a/source/cCriticalSection.h b/source/cCriticalSection.h index 414c970f7..0a149a95a 100644 --- a/source/cCriticalSection.h +++ b/source/cCriticalSection.h @@ -19,10 +19,10 @@ private: #ifdef _WIN32 CRITICAL_SECTION m_CriticalSection; #else // _WIN32 - void* m_CriticalSectionPtr; // Pointer to a CRITICAL_SECTION object - void* m_Attributes; + void* m_CriticalSectionPtr ALIGN_8; // Pointer to a CRITICAL_SECTION object + void* m_Attributes ALIGN_8; #endif // else _WIN32 -}; +} ALIGN_8; diff --git a/source/main.cpp b/source/main.cpp index f19a88210..1d245ae0b 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -158,14 +158,14 @@ int main( int argc, char **argv ) #endif // _WIN32 && !_WIN64 // End of dump-file magic - #ifdef _DEBUG + #if defined(_DEBUG) && defined(_MSC_VER) _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // _X: The simple built-in CRT leak finder - simply break when allocating the Nth block ({N} is listed in the leak output) // Only useful when the leak is in the same sequence all the time // _CrtSetBreakAlloc(85950); - #endif + #endif // _DEBUG && _MSC_VER #ifndef _DEBUG std::signal(SIGSEGV, ShowCrashReport); -- cgit v1.2.3