1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
#ifndef __E_ERROR__
#define __E_ERROR__
#include <string>
#include <map>
#include <new>
#include <libsig_comp.h>
// to use memleak check change the following in configure.ac
// * add -DMEMLEAK_CHECK and -rdynamic to CPP_FLAGS
#ifdef MEMLEAK_CHECK
#define BACKTRACE_DEPTH 5
#include <map>
#include <lib/base/elock.h>
#include <execinfo.h>
#include <string>
#include <new>
#include <cxxabi.h>
typedef struct
{
unsigned int address;
unsigned int size;
const char *file;
void *backtrace[BACKTRACE_DEPTH];
unsigned char btcount;
unsigned short line;
unsigned char type;
} ALLOC_INFO;
typedef std::map<unsigned int, ALLOC_INFO> AllocList;
extern AllocList *allocList;
extern pthread_mutex_t memLock;
static inline void AddTrack(unsigned int addr, unsigned int asize, const char *fname, unsigned int lnum, unsigned int type)
{
ALLOC_INFO info;
if(!allocList)
allocList = new(AllocList);
info.address = addr;
info.file = fname;
info.line = lnum;
info.size = asize;
info.type = type;
info.btcount = 0; //backtrace( info.backtrace, BACKTRACE_DEPTH );
singleLock s(memLock);
(*allocList)[addr]=info;
};
static inline void RemoveTrack(unsigned int addr, unsigned int type)
{
if(!allocList)
return;
AllocList::iterator i;
singleLock s(memLock);
i = allocList->find(addr);
if ( i != allocList->end() )
{
if ( i->second.type != type )
i->second.type=3;
else
allocList->erase(i);
}
};
inline void * operator new(size_t size, const char *file, int line)
{
void *ptr = (void *)malloc(size);
AddTrack((unsigned int)ptr, size, file, line, 1);
return(ptr);
};
inline void operator delete(void *p)
{
RemoveTrack((unsigned int)p,1);
free(p);
};
inline void * operator new[](size_t size, const char *file, int line)
{
void *ptr = (void *)malloc(size);
AddTrack((unsigned int)ptr, size, file, line, 2);
return(ptr);
};
inline void operator delete[](void *p)
{
RemoveTrack((unsigned int)p, 2);
free(p);
};
void DumpUnfreed();
#define new new(__FILE__, __LINE__)
#endif // MEMLEAK_CHECK
#ifndef NULL
#define NULL 0
#endif
#ifdef ASSERT
#undef ASSERT
#endif
#ifndef SWIG
#define CHECKFORMAT __attribute__ ((__format__(__printf__, 1, 2)))
extern Signal2<void, int, const std::string&> logOutput;
extern int logOutputConsole;
void CHECKFORMAT eFatal(const char*, ...);
enum { lvlDebug=1, lvlWarning=2, lvlFatal=4 };
#ifdef DEBUG
void CHECKFORMAT eDebug(const char*, ...);
void CHECKFORMAT eDebugNoNewLine(const char*, ...);
void CHECKFORMAT eWarning(const char*, ...);
#define ASSERT(x) { if (!(x)) eFatal("%s:%d ASSERTION %s FAILED!", __FILE__, __LINE__, #x); }
#else // DEBUG
inline void eDebug(const char* fmt, ...)
{
}
inline void eDebugNoNewLine(const char* fmt, ...)
{
}
inline void eWarning(const char* fmt, ...)
{
}
#define ASSERT(x) do { } while (0)
#endif //DEBUG
void eWriteCrashdump();
#endif // SWIG
void ePythonOutput(const char *);
#endif // __E_ERROR__
|