From 0103839d01b8762a836265695cee4efbecc057da Mon Sep 17 00:00:00 2001 From: Andreas Monzner Date: Thu, 17 Aug 2006 11:36:03 +0000 Subject: [PATCH] cleanup --- lib/base/eerror.h | 26 +++++------ lib/base/object.h | 108 +++++++++++++++++++++++----------------------- 2 files changed, 66 insertions(+), 68 deletions(-) diff --git a/lib/base/eerror.h b/lib/base/eerror.h index 6d38bcc7..4289ab30 100644 --- a/lib/base/eerror.h +++ b/lib/base/eerror.h @@ -23,32 +23,25 @@ #define NULL 0 #endif -#ifndef SWIG -#define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2))) -#else -#define CHECKFORMAT +#ifdef ASSERT +#undef ASSERT #endif -void CHECKFORMAT eFatal(const char*, ...); +#ifndef SWIG -enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 }; +#define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2))) -#ifndef SWIG extern Signal2 logOutput; extern int logOutputConsole; -#endif -#ifdef ASSERT -#undef ASSERT -#endif +void CHECKFORMAT eFatal(const char*, ...); +enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 }; #ifdef DEBUG void CHECKFORMAT eDebug(const char*, ...); void CHECKFORMAT eDebugNoNewLine(const char*, ...); void CHECKFORMAT eWarning(const char*, ...); -#ifndef SWIG #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); } -#endif #ifdef MEMLEAK_CHECK typedef struct @@ -134,7 +127,7 @@ void DumpUnfreed(); #endif // MEMLEAK_CHECK -#else +#else // DEBUG inline void eDebug(const char* fmt, ...) { } @@ -149,7 +142,10 @@ void DumpUnfreed(); #define ASSERT(x) do { } while (0) #endif //DEBUG -void ePythonOutput(const char *); void eWriteCrashdump(); +#endif // SWIG + +void ePythonOutput(const char *); + #endif // __E_ERROR__ diff --git a/lib/base/object.h b/lib/base/object.h index 93989a67..d0e2a65e 100644 --- a/lib/base/object.h +++ b/lib/base/object.h @@ -2,14 +2,14 @@ #define __base_object_h #include +#include +#include -// #define OBJECT_DEBUG +//#define OBJECT_DEBUG -#include #ifdef OBJECT_DEBUG -#include + #include #endif -#include typedef int RESULT; @@ -26,19 +26,45 @@ public: }; #ifndef SWIG -struct oRefCount -{ - volatile int count; - oRefCount(): count(0) { } - operator volatile int&() { return count; } - ~oRefCount() { -#ifdef OBJECT_DEBUG - if (count) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, ref); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this); -#endif - } -}; + struct oRefCount + { + volatile int count; + oRefCount(): count(0) { } + operator volatile int&() { return count; } + ~oRefCount() { + #ifdef OBJECT_DEBUG + if (count) eDebug("OBJECT_DEBUG FATAL: %p has %d references!", this, count); else eDebug("OBJECT_DEBUG refcount ok! (%p)", this); + #endif + } + }; - #if defined(__mips__) + #if defined(OBJECT_DEBUG) + extern int object_total_remaining; + #define DECLARE_REF(x) \ + private:oRefCount ref; \ + eSingleLock ref_lock; \ + public: void AddRef(); \ + void Release(); + #define DEFINE_REF(c) \ + void c::AddRef() \ + { \ + eSingleLocker l(ref_lock); \ + ++object_total_remaining; \ + ++ref; \ + eDebug("OBJECT_DEBUG " #c "+%p now %d", this, (int)ref); \ + } \ + void c::Release() \ + { \ + { \ + eSingleLocker l(ref_lock); \ + --object_total_remaining; \ + --ref; \ + eDebug("OBJECT_DEBUG " #c "-%p now %d", this, (int)ref); \ + } \ + if (!ref) \ + delete this; \ + } + #elif defined(__mips__) #define DECLARE_REF(x) \ private: oRefCount ref; \ public: void AddRef(); \ @@ -118,45 +144,21 @@ struct oRefCount eSingleLock ref_lock; \ public: void AddRef(); \ void Release(); - #ifdef OBJECT_DEBUG - extern int object_total_remaining; - #define DEFINE_REF(c) \ - void c::AddRef() \ - { \ - eSingleLocker l(ref_lock); \ - ++object_total_remaining; \ - ++ref; \ - eDebug("OBJECT_DEBUG " #c "+%p now %d", this, ref.count); \ - } \ - void c::Release() \ - { \ - { \ - eSingleLocker l(ref_lock); \ - --object_total_remaining; \ - --ref; \ - eDebug("OBJECT_DEBUG " #c "-%p now %d", this, ref); \ - } \ - if (!ref) \ - delete this; \ - } - #error fix locking for debug - #else - #define DEFINE_REF(c) \ - void c::AddRef() \ + #define DEFINE_REF(c) \ + void c::AddRef() \ + { \ + eSingleLocker l(ref_lock); \ + ++ref; \ + } \ + void c::Release() \ + { \ { \ eSingleLocker l(ref_lock); \ - ++ref; \ + --ref; \ } \ - void c::Release() \ - { \ - { \ - eSingleLocker l(ref_lock); \ - --ref; \ - } \ - if (!ref) \ - delete this; \ - } - #endif + if (!ref) \ + delete this; \ + } #endif #else // SWIG #define DECLARE_REF(x) \ @@ -168,4 +170,4 @@ struct oRefCount }; #endif // SWIG -#endif +#endif // __base_object_h -- 2.30.2