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);
44 info.file = strdup(fname);
48 info.btcount = 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 )
72 inline void * operator new(unsigned int size, const char *file, int line)
74 void *ptr = (void *)malloc(size);
75 AddTrack((unsigned int)ptr, size, file, line, 1);
79 inline void operator delete(void *p)
81 RemoveTrack((unsigned int)p,1);
85 inline void * operator new[](unsigned int size, const char *file, int line)
87 void *ptr = (void *)malloc(size);
88 AddTrack((unsigned int)ptr, size, file, line, 2);
92 inline void operator delete[](void *p)
94 RemoveTrack((unsigned int)p, 2);
99 #define new new(__FILE__, __LINE__)
101 #endif // MEMLEAK_CHECK
113 #define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2)))
115 extern Signal2<void, int, const std::string&> logOutput;
116 extern int logOutputConsole;
118 void CHECKFORMAT eFatal(const char*, ...);
119 enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 };
122 void CHECKFORMAT eDebug(const char*, ...);
123 void CHECKFORMAT eDebugNoNewLine(const char*, ...);
124 void CHECKFORMAT eWarning(const char*, ...);
125 #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
127 inline void eDebug(const char* fmt, ...)
131 inline void eDebugNoNewLine(const char* fmt, ...)
135 inline void eWarning(const char* fmt, ...)
138 #define ASSERT(x) do { } while (0)
141 void eWriteCrashdump();
145 void ePythonOutput(const char *);
147 #endif // __E_ERROR__