4 // to use memleak check change the following in configure.ac
5 // * add -rdynamic to LD_FLAGS
6 // * add -DMEMLEAK_CHECK to CPP_FLAGS
9 #define BACKTRACE_DEPTH 10
11 #include <lib/system/elock.h>
16 #endif // MEMLEAK_CHECK
22 #include <libsig_comp.h>
27 void eFatal(const char* fmt
, ...);
29 enum { lvlDebug
=1, lvlWarning
=2, lvlFatal
=4 };
31 extern Signal2
<void, int, const eString
&> logOutput
;
32 extern int logOutputConsole
;
39 void eDebug(const char* fmt
, ...);
40 void eDebugNoNewLine(const char* fmt
, ...);
41 void eWarning(const char* fmt
, ...);
42 #define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
50 void *backtrace
[BACKTRACE_DEPTH
];
51 unsigned char btcount
;
56 typedef std::map
<unsigned int, ALLOC_INFO
> AllocList
;
58 extern AllocList
*allocList
;
59 extern pthread_mutex_t memLock
;
61 static inline void AddTrack(unsigned int addr
, unsigned int asize
, const char *fname
, unsigned int lnum
, unsigned int type
)
66 allocList
= new(AllocList
);
69 info
.file
= strdup(fname
);
73 info
.btcount
= backtrace( info
.backtrace
, BACKTRACE_DEPTH
);
74 singleLock
s(memLock
);
75 (*allocList
)[addr
]=info
;
78 static inline void RemoveTrack(unsigned int addr
, unsigned int type
)
82 AllocList::iterator i
;
83 singleLock
s(memLock
);
84 i
= allocList
->find(addr
);
85 if ( i
!= allocList
->end() )
87 if ( i
->second
.type
!= type
)
97 inline void * operator new(unsigned int size
, const char *file
, int line
)
99 void *ptr
= (void *)malloc(size
);
100 AddTrack((unsigned int)ptr
, size
, file
, line
, 1);
104 inline void operator delete(void *p
)
106 RemoveTrack((unsigned int)p
,1);
110 inline void * operator new[](unsigned int size
, const char *file
, int line
)
112 void *ptr
= (void *)malloc(size
);
113 AddTrack((unsigned int)ptr
, size
, file
, line
, 2);
117 inline void operator delete[](void *p
)
119 RemoveTrack((unsigned int)p
, 2);
125 #define new new(__FILE__, __LINE__)
127 #endif // MEMLEAK_CHECK
130 inline void eDebug(const char* fmt
, ...)
134 inline void eDebugNoNewLine(const char* fmt
, ...)
138 inline void eWarning(const char* fmt
, ...)
141 #define ASSERT(x) do { } while (0)
144 #endif // __E_ERROR__