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>
20 #endif // MEMLEAK_CHECK
32 #define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2)))
34 extern Signal2<void, int, const std::string&> logOutput;
35 extern int logOutputConsole;
37 void CHECKFORMAT eFatal(const char*, ...);
38 enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 };
41 void CHECKFORMAT eDebug(const char*, ...);
42 void CHECKFORMAT eDebugNoNewLine(const char*, ...);
43 void CHECKFORMAT eWarning(const char*, ...);
44 #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
52 void *backtrace[BACKTRACE_DEPTH];
53 unsigned char btcount;
58 typedef std::map<unsigned int, ALLOC_INFO> AllocList;
60 extern AllocList *allocList;
61 extern pthread_mutex_t memLock;
63 static inline void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum, unsigned int type)
68 allocList = new(AllocList);
71 info.file = strdup(fname);
75 info.btcount = backtrace( info.backtrace, BACKTRACE_DEPTH );
76 singleLock s(memLock);
77 (*allocList)[addr]=info;
80 static inline void RemoveTrack(unsigned int addr, unsigned int type)
84 AllocList::iterator i;
85 singleLock s(memLock);
86 i = allocList->find(addr);
87 if ( i != allocList->end() )
89 if ( i->second.type != type )
99 inline void * operator new(unsigned int size, const char *file, int line)
101 void *ptr = (void *)malloc(size);
102 AddTrack((unsigned int)ptr, size, file, line, 1);
106 inline void operator delete(void *p)
108 RemoveTrack((unsigned int)p,1);
112 inline void * operator new[](unsigned int size, const char *file, int line)
114 void *ptr = (void *)malloc(size);
115 AddTrack((unsigned int)ptr, size, file, line, 2);
119 inline void operator delete[](void *p)
121 RemoveTrack((unsigned int)p, 2);
126 #define new new(__FILE__, __LINE__)
128 #endif // MEMLEAK_CHECK
131 inline void eDebug(const char* fmt, ...)
135 inline void eDebugNoNewLine(const char* fmt, ...)
139 inline void eWarning(const char* fmt, ...)
142 #define ASSERT(x) do { } while (0)
145 void eWriteCrashdump();
149 void ePythonOutput(const char *);
151 #endif // __E_ERROR__