-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptional_op.h
176 lines (176 loc) · 3.44 KB
/
optional_op.h
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//#ifndef MEM_TRACE
//#define MEM_TRACE
//#include <iostream>
//#include <fstream>
//#include <string>
//#include <memory>
//#include <new>
//#include <map>
//#include "../DL_Debug/StackWalker/StackWalker.h"
//
//struct memory_data
//{
// memory_data() = default;
// memory_data(void* p, const char* f, size_t l, size_t s)
// : pointer(p)
// , file(f)
// , line(l)
// , size(s)
// {
// }
// void* pointer;
// const char* file;
// size_t line;
// size_t size;
// std::string callstack[4];
// //CallstackEntryList callstack;
//};
//
//
//template<typename T>
//struct track_alloc : std::allocator<T>
//{
// typedef typename std::allocator<T>::pointer pointer;
// typedef typename std::allocator<T>::size_type size_type;
//
// template<typename U>
// struct rebind
// {
// typedef track_alloc<U> other;
// };
//
// track_alloc()
// {
// }
//
// template<typename U>
// track_alloc(track_alloc<U> const& u) : std::allocator<T>(u)
// {
// }
//
// pointer allocate(size_type size, std::allocator<void>::const_pointer = 0)
// {
// void* p = malloc(size * sizeof(T));
// if (p == 0)
// throw std::bad_alloc();
//
// return static_cast<pointer>(p);
// }
//
// void deallocate(pointer p, size_type)
// {
// free(p);
// }
//};
//
//
//typedef std::map< void*, memory_data, std::less<void*>, track_alloc<std::pair<void* const, size_t> > > track_type;
//
//
//struct track_printer
//{
// track_type* track;
// track_printer(track_type* track)
// :track(track)
// {
// }
//
// ~track_printer()
// {
// track_type::const_iterator it = track->begin();
// std::ofstream leak_track("leaks.txt", std::ios_base::trunc);
// while (it != track->end())
// {
// std::string file(it->second.file);
//
//
// if (!file.empty())
// {
// size_t pos = file.rfind('/');
// file = file.substr(pos + 1);
// }
// leak_track << "\nLeak at " << it->first << " size: " << it->second.size << " file: " << file << " line: " << it->second.line << "\n" << "callstack : \n";
//
// std::string entry = it->second.callstack[0];
// leak_track << entry << "\n";
//
// entry = it->second.callstack[1];
// leak_track << entry << "\n";
//
// entry = it->second.callstack[2];
// leak_track << entry << "\n";
//
// entry = it->second.callstack[3];
// leak_track << entry << "\n";
//
//
// ++it;
// }
// leak_track.close();
// }
//};
//
//track_type * get_map()
//{
// // don't use normal new to avoid infinite recursion.
// static track_type* track = new (malloc(sizeof *track)) track_type;
// static track_printer printer(track);
// return track;
//};
//
//char* __file__ = "unknown";
//size_t __line__ = 0;
//
//void* operator new(size_t n)
//{
// void * p = malloc(n);
//
// //this shit calls new
// BaseStackWalker walker;
// walker.ShowCallstack(4);
//
// memory_data data;
// data.file = __file__;
// data.line = __line__;
// data.pointer = p;
// data.size = n;
// for (int i = 0; i < 4; i++)
// {
// data.callstack[i] = walker.GetEntry(i);
// }
//
//
// (*get_map())[p] = memory_data(p, __file__, __line__, n);
// __file__ = "unknown";
// __line__ = 0;
//
//
//
// return p;
//}
//
//void* operator new[](size_t n)
//{
// void * p = malloc(n);
// (*get_map())[p] = memory_data(p, __file__, __line__, n);
// __file__ = "unknown";
// __line__ = 0;
//
// return p;
//}
//
//void operator delete(void* p)
//{
// (*get_map()).erase(p);
// free(p);
//}
//
//void operator delete[](void* p)
//{
// (*get_map()).erase(p);
// free(p);
//}
//
//#define new (__file__=__FILE__,__line__=__LINE__) && 0 ? NULL : new
//
//#endif