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
27 #define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2)))
32 void CHECKFORMAT eFatal(const char*, ...);
34 enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 };
37 extern Signal2<void, int, const std::string&> logOutput;
38 extern int logOutputConsole;
46 void CHECKFORMAT eDebug(const char*, ...);
47 void CHECKFORMAT eDebugNoNewLine(const char*, ...);
48 void CHECKFORMAT eWarning(const char*, ...);
50 #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
59 void *backtrace[BACKTRACE_DEPTH];
60 unsigned char btcount;
65 typedef std::map<unsigned int, ALLOC_INFO> AllocList;
67 extern AllocList *allocList;
68 extern pthread_mutex_t memLock;
70 static inline void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum, unsigned int type)
75 allocList = new(AllocList);
78 info.file = strdup(fname);
82 info.btcount = backtrace( info.backtrace, BACKTRACE_DEPTH );
83 singleLock s(memLock);
84 (*allocList)[addr]=info;
87 static inline void RemoveTrack(unsigned int addr, unsigned int type)
91 AllocList::iterator i;
92 singleLock s(memLock);
93 i = allocList->find(addr);
94 if ( i != allocList->end() )
96 if ( i->second.type != type )
100 free(i->second.file);
106 inline void * operator new(unsigned int size, const char *file, int line)
108 void *ptr = (void *)malloc(size);
109 AddTrack((unsigned int)ptr, size, file, line, 1);
113 inline void operator delete(void *p)
115 RemoveTrack((unsigned int)p,1);
119 inline void * operator new[](unsigned int size, const char *file, int line)
121 void *ptr = (void *)malloc(size);
122 AddTrack((unsigned int)ptr, size, file, line, 2);
126 inline void operator delete[](void *p)
128 RemoveTrack((unsigned int)p, 2);
133 #define new new(__FILE__, __LINE__)
135 #endif // MEMLEAK_CHECK
138 inline void eDebug(const char* fmt, ...)
142 inline void eDebugNoNewLine(const char* fmt, ...)
146 inline void eWarning(const char* fmt, ...)
149 #define ASSERT(x) do { } while (0)
152 void ePythonOutput(const char *);
153 void eWriteCrashdump();
155 #endif // __E_ERROR__