7 #include <libsig_comp.h>
9 // to use memleak check change the following in configure.ac
10 // * add -DMEMLEAK_CHECK and -rdynamic to CPP_FLAGS
13 #define BACKTRACE_DEPTH 5
15 #include <lib/base/elock.h>
25 void *backtrace[BACKTRACE_DEPTH];
26 unsigned char btcount;
31 typedef std::map<unsigned int, ALLOC_INFO> AllocList;
33 extern AllocList *allocList;
34 extern pthread_mutex_t memLock;
36 static inline void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum, unsigned int type)
41 allocList = new(AllocList);
48 info.btcount = 0; //backtrace( info.backtrace, BACKTRACE_DEPTH );
49 singleLock s(memLock);
50 (*allocList)[addr]=info;
53 static inline void RemoveTrack(unsigned int addr, unsigned int type)
57 AllocList::iterator i;
58 singleLock s(memLock);
59 i = allocList->find(addr);
60 if ( i != allocList->end() )
62 if ( i->second.type != type )
69 inline void * operator new(size_t size, const char *file, int line)
71 void *ptr = (void *)malloc(size);
72 AddTrack((unsigned int)ptr, size, file, line, 1);
76 inline void operator delete(void *p)
78 RemoveTrack((unsigned int)p,1);
82 inline void * operator new[](size_t size, const char *file, int line)
84 void *ptr = (void *)malloc(size);
85 AddTrack((unsigned int)ptr, size, file, line, 2);
89 inline void operator delete[](void *p)
91 RemoveTrack((unsigned int)p, 2);
96 #define new new(__FILE__, __LINE__)
98 #endif // MEMLEAK_CHECK
110 #define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2)))
112 extern SigC::Connection logConnection;
113 extern Signal2<void, int, const std::string&> logOutput;
114 extern int logOutputConsole;
116 void CHECKFORMAT eFatal(const char*, ...);
117 enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 };
120 void CHECKFORMAT eDebug(const char*, ...);
121 void CHECKFORMAT eDebugNoNewLine(const char*, ...);
122 void CHECKFORMAT eWarning(const char*, ...);
123 #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
125 inline void eDebug(const char* fmt, ...)
129 inline void eDebugNoNewLine(const char* fmt, ...)
133 inline void eWarning(const char* fmt, ...)
136 #define ASSERT(x) do { } while (0)
139 void eWriteCrashdump();
143 void ePythonOutput(const char *);
145 #endif // __E_ERROR__