ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
mcd.h
Go to the documentation of this file.
1/*
2 * Softpixel MemCheckDeluxe v1.2.2
3 * 2003 cwright <cwright@softpixel.com>
4 */
5
6/* Copyright (C) 2002, 2003 Softpixel (http://softpixel.com/)
7 * This file is covered by a BSD-Style License, available in
8 * the LICENSE file in the root directory of this package, as well as at
9 * http://prj.softpixel.com/licenses/#bsd
10 */
11
12
13#ifndef MCD_H
14#define MCD_H
15
16#include <stdio.h> //for file redirection
17
18#define MCD_VERSION 0x010201
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24#ifndef _MCD_GONE
25
26#ifdef _MCD_CHECK
27
28#include <stdarg.h>
29
30#ifdef WIN32
31 #define __FUNCTION__ __FILE__
32#endif
33
34#ifndef MCD_QUIET
35 #ifndef WIN32
36 #warning - Building with memory checking.
37 #warning expect lower performance. -
38 #endif
39#endif
40
41//warn about redefinitions (sometimes these can be #defined)
42
43#ifdef malloc
44#undef malloc
45 #ifndef WIN32
46 #warning ------ Redefining malloc() ------
47 #endif
48#endif
49
50#ifdef calloc
51#undef calloc
52 #ifndef WIN32
53 #warning ------ Redefining calloc() ------
54 #endif
55#endif
56
57#ifdef realloc
58#undef realloc
59 #ifndef WIN32
60 #warning ------ Redefining realloc() ------
61 #endif
62#endif
63
64#ifdef free
65#undef free
66 #ifndef WIN32
67 #warning ------ Redefining free() ------
68 #endif
69#endif
70
71#ifdef strdup
72#undef strdup
73 #ifndef WIN32
74 #warning ------- Redefining strdup() --------
75 #endif
76#endif
77
78#ifdef strndup
79#undef strndup
80 #ifndef WIN32
81 #warning ------- Redefining strndup() -------
82 #endif
83#endif
84
85#ifdef asprintf
86#undef asprintf
87 #ifndef WIN32
88 #warning ------ Redefining asprintf() ------
89 #endif
90#endif
91
92#ifdef vasprintf
93#undef vasprintf
94 #ifndef WIN32
95 #warning ------ Redefining vasprintf() ------
96 #endif
97#endif
98
99#ifdef scanf
100#undef scanf
101 #ifndef WIN32
102 #warning ------ Redefining scanf() ------
103 #endif
104#endif
105
106#ifdef fscanf
107#undef fscanf
108 #ifndef WIN32
109 #warning ------ Redefining fscanf() ------
110 #endif
111#endif
112
113#ifdef sscanf
114#undef sscanf
115 #ifndef WIN32
116 #warning ------ Redefining sscanf() ------
117 #endif
118#endif
119
120#ifdef getcwd
121#undef getcwd
122 #ifndef WIN32
123 #warning ------ Redefining getcwd() ------
124 #endif
125#endif
126
127#define strdup(p) MCD_strdup(p,__FUNCTION__,__FILE__,__LINE__)
128#ifndef WIN32 //no strndup in win32
129#define strndup(p,n) MCD_strndup(p,n,__FUNCTION__,__FILE__,__LINE__)
130#endif
131#define malloc(size) MCD_malloc(size,__FUNCTION__,__FILE__,__LINE__)
132#define calloc(n,s) MCD_calloc(s*n,__FUNCTION__,__FILE__,__LINE__)
133#define realloc(p,s) MCD_realloc(p,s,__FUNCTION__,__FILE__,__LINE__)
134
135#ifdef _GNU_SOURCE
136#define asprintf(p,f,args...) MCD_asprintf(p,f,__FUNCTION__,__FILE__,__LINE__, ## args)
137#define vasprintf(p,f,ap) MCD_vasprintf(p,f,ap,__FUNCTION__,__FILE__,__LINE__)
138#endif
139
140#ifndef WIN32
141/* windows doesn't like variable arguments in #define's */
142#ifndef MCD_FASTFREE //fastfree isnt supported here yet
143#define scanf(f,args...) MCD_scanf(f,__FUNCTION__,__FILE__,__LINE__, ## args)
144#define fscanf(s,f,args...) MCD_fscanf(s,f,__FUNCTION__,__FILE__,__LINE__, ## args)
145#define sscanf(s,f,args...) MCD_sscanf(s,f,__FUNCTION__,__FILE__,__LINE__, ## args)
146#define getcwd(p,s) MCD_getcwd(p,s,__FUNCTION__,__FILE__,__LINE__)
147#endif //fastfree
148#endif //win32
149
150#define free(p) MCD_free(p,__FUNCTION__,__FILE__,__LINE__)
151
152#endif // _MCD_CHECK
153
154
155/* !!! These are called by the defines only. Do NOT use directly. !!! */
156void *MCD_malloc(int size, char*, char*, int);
157void *MCD_calloc(int size, char*, char*, int);
158void *MCD_realloc(void *p, int size, char*, char*, int);
159char *MCD_getcwd (char *p, int size, char*, char*, int);
160#ifdef __GNUC__
161char *MCD_strdup (const char*s, char*, char*, int);
162char *MCD_strndup(const char*s, int n, char*, char*, int);
163#else
164char *MCD_strdup (char*s, char*, char*, int);
165char *MCD_strndup(char*s, int n, char*, char*, int);
166#endif
167int MCD_scanf (const char *fmt, char*fun, char*file, int line,...);
168int MCD_fscanf(FILE *stream,const char *fmt,char*fun,char*file,int line,...);
169int MCD_sscanf(const char *str,const char *fmt,char*fun,char*file,int line,...);
170// Private MCD function, no need to be in public namespace
171//void scan_args(const char*fmt,va_list argptr,char*fun,char*file,int line);
172#ifdef _GNU_SOURCE
173int MCD_asprintf(char **ptr, const char*fmt,char*,char*,int,...);
174int MCD_vasprintf(char **ptr, const char*fmt,va_list argptr,char*,char*,int);
175#endif // _GNU_SOURCE
176
177void MCD_free(void *p,char*,char*,int);
178
179/* --- call this for memory stats --- */
180void showMemStats(void);
181
182/* --- to send realtime stats somewhere other than stderr,
183 put an opened fp in here --- */
184void _MCD_RealTimeLog(FILE*);
185
186/* --- to send showMemStats() somewhere other than stdout,
187 put an opened fp in here --- */
188void _MCD_MemStatLog(FILE*);
189
190#else //MCD is gone
191
192/* define functions so source will compile without modification */
193#define showMemStats()
194#define _MCD_RealTimeLog(x)
195#define _MCD_MemStatLog(x)
196
197#endif //_MCD_GONE
198
199#ifdef __cplusplus
200} /* extern "C" */
201#endif
202
203#ifndef _MCD_GONE // check again, outside of extern "C" mode
204#ifdef __cplusplus /* Some C++ new/delete operator overloading */
205
206#ifndef WIN32
207 #warning C++ Extentions Enabled
208#endif
209
210#ifdef new
211 #undef new
212#endif
213
214#ifdef delete
215 #undef delete
216#endif
217
218extern char *_MCD_LastSetFile,*_MCD_LastSetFun;
219extern int _MCD_LastSetLine;
220
221inline void setFileFunLineState(char*file,char*fun,int line)
222{
223 _MCD_LastSetLine=line;
224 _MCD_LastSetFile=file;
225 _MCD_LastSetFun=fun;
226}
227
228inline void* operator new (unsigned int size,char *file,
229char*fun,int line)
230{
231 return MCD_malloc(size,file,fun,line);
232}
233
234inline void* operator new[] (unsigned int size,char*file,
235char*fun,int line)
236{
237 return MCD_malloc(size,file,fun,line);
238}
239
240// currently, passing args to delete operator is not working at all...
241#ifndef WIN32 //win32 doesn't like default params to delete
242inline void operator delete (void * buf,char*file=__FILE__,
243#ifdef WIN32
244char*fun=__FILE__,int line=__LINE__)
245#else
246char*fun=__FUNCTION__,int line=__LINE__)
247#endif
248{
249 MCD_free(buf,_MCD_LastSetFile,_MCD_LastSetFun,_MCD_LastSetLine);
250}
251// ...so we have these here for the day they work, which isn't today.
252inline void operator delete[] (void * buf,char*file=__FILE__,
253#ifdef WIN32
254char*fun=__FILE__,int line=__LINE__)
255#else
256char*fun=__FUNCTION__,int line=__LINE__)
257#endif
258{
259 MCD_free(buf,_MCD_LastSetFile,_MCD_LastSetFun,_MCD_LastSetLine);
260}
261#endif // win32 default delete params
262
263inline void operator delete (void * buf)
264{
265 MCD_free(buf,0,0,0);
266}
267
268inline void operator delete[] (void * buf)
269{
270 MCD_free(buf,0,0,0);
271}
272
273#ifdef WIN32
274#define new new(__FILE__,__FILE__,__LINE__)
275#else
276#define new new(__FILE__,__FUNCTION__,__LINE__)
277#endif
278//#define delete setFileFunLineState(__FILE__,__FUNCTION__,__LINE__);delete
279//#define delete delete(__FILE__,__FUNCTION__,__LINE__)
280
281#endif // __cplusplus
282#endif // _MCD_GONE
283
284
285#endif // MCD_H
void showMemStats(void)
Definition mcd.c:779
void * MCD_calloc(int size, char *, char *, int)
Definition mcd.c:396
void * MCD_realloc(void *p, int size, char *, char *, int)
Definition mcd.c:419
void _MCD_RealTimeLog(FILE *)
Definition mcd.c:813
int MCD_fscanf(FILE *stream, const char *fmt, char *fun, char *file, int line,...)
Definition mcd.c:667
int MCD_scanf(const char *fmt, char *fun, char *file, int line,...)
Definition mcd.c:649
int MCD_sscanf(const char *str, const char *fmt, char *fun, char *file, int line,...)
Definition mcd.c:685
void * MCD_malloc(int size, char *, char *, int)
Definition mcd.c:373
char * MCD_strdup(char *s, char *, char *, int)
Definition mcd.c:514
char * MCD_getcwd(char *p, int size, char *, char *, int)
void MCD_free(void *p, char *, char *, int)
Definition mcd.c:729
char * MCD_strndup(char *s, int n, char *, char *, int)
Definition mcd.c:542
void _MCD_MemStatLog(FILE *)
Definition mcd.c:819
file(GLOB ATen_CORE_SRCS "*.cpp") set(ATen_CPU_SRCS $
Definition CMakeLists.txt:1