QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
debug_new.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
2// vim:tabstop=4:shiftwidth=4:expandtab:
3
4/*
5 * Copyright (C) 2004-2008 Wu Yongwei <adah at users dot sourceforge dot net>
6 *
7 * This software is provided 'as-is', without any express or implied
8 * warranty. In no event will the authors be held liable for any
9 * damages arising from the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute
13 * it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must
16 * not claim that you wrote the original software. If you use this
17 * software in a product, an acknowledgement in the product
18 * documentation would be appreciated but is not required.
19 * 2. Altered source versions must be plainly marked as such, and must
20 * not be misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source
22 * distribution.
23 *
24 * This file is part of Stones of Nvwa:
25 * http://sourceforge.net/projects/nvwa
26 *
27 */
28
40#ifndef QT_NO_DEBUG
41#ifndef _QX_MODE_RELEASE
42#if _QX_USE_MEM_LEAK_DETECTION
43
44#ifndef _DEBUG_NEW_H
45#define _DEBUG_NEW_H
46
47#ifdef _MSC_VER
48#pragma once
49#endif
50
51#include <new>
52#include <stdio.h>
53
54#include <QxCommon/QxMacro.h>
55
67#ifndef HAVE_PLACEMENT_DELETE
68#define HAVE_PLACEMENT_DELETE 1
69#endif
70
95#ifndef _DEBUG_NEW_REDEFINE_NEW
96#define _DEBUG_NEW_REDEFINE_NEW 1
97#endif
98
106#ifndef _DEBUG_NEW_CALLER_ADDRESS
107#ifdef __GNUC__
108#define _DEBUG_NEW_CALLER_ADDRESS __builtin_return_address(0)
109#else
110#define _DEBUG_NEW_CALLER_ADDRESS NULL
111#endif
112#endif
113
122#define DEBUG_NEW qx::memory::__debug_new_recorder(__FILE__, __LINE__, __FUNCTION__) ->* new
123
124#if _DEBUG_NEW_REDEFINE_NEW
125#define new DEBUG_NEW
126#endif // _DEBUG_NEW_REDEFINE_NEW
127
128#ifdef _DEBUG_NEW_EMULATE_MALLOC
129#include <stdlib.h>
130#ifdef new
131#define malloc(s) ((void*)(new char[s]))
132#else // new
133#define malloc(s) ((void*)(DEBUG_NEW char[s]))
134#endif // new
135#define free(p) delete[] (char*)(p)
136#endif // _DEBUG_NEW_EMULATE_MALLOC
137
138QX_DLL_EXPORT void * operator new(size_t size, const char * file, int line);
139QX_DLL_EXPORT void * operator new[](size_t size, const char * file, int line);
140
141#if HAVE_PLACEMENT_DELETE
142QX_DLL_EXPORT void operator delete(void * pointer, const char * file, int line) throw();
143QX_DLL_EXPORT void operator delete[](void * pointer, const char * file, int line) throw();
144#endif
145
146#if defined(_MSC_VER) && _MSC_VER < 1300
147// MSVC 6 requires the following declarations; or the non-placement
148// new[]/delete[] will not compile.
149QX_DLL_EXPORT void * operator new[](size_t) throw(std::bad_alloc);
150QX_DLL_EXPORT void operator delete[](void *) throw();
151#endif
152
153namespace qx {
154namespace memory {
155
156/* Prototypes */
159
160/* Control variables */
161extern bool new_autocheck_flag; // default to true: call check_leaks() on exit
162extern bool new_verbose_flag; // default to false: no verbose information
163extern FILE* new_output_fp; // default to stderr: output to console
164extern const char* new_progname;// default to NULL; should be assigned argv[0]
165
172{
173 const char* _M_file;
174 const int _M_line;
175 const char* _M_fct;
176 void _M_process(void* pointer);
177public:
182 __debug_new_recorder(const char* file, int line, const char* fct)
183 : _M_file(file), _M_line(line), _M_fct(fct) {}
190 template <class _Tp> _Tp* operator->*(_Tp* pointer) { _M_process(pointer); return pointer; };
191 static void free_pointer(void* pointer, void* addr, bool is_array);
192private:
195};
196
210
213
214} // namespace memory
215} // namespace qx
216
217#endif // _DEBUG_NEW_H
218#endif // _QX_USE_MEM_LEAK_DETECTION
219#endif // _QX_MODE_RELEASE
220#endif // QT_NO_DEBUG
List of common macros used by QxOrm library.
#define QX_DLL_EXPORT
Definition QxMacro.h:182
static void free_pointer(void *pointer, void *addr, bool is_array)
__debug_new_recorder(const char *file, int line, const char *fct)
Definition debug_new.h:182
__debug_new_recorder(const __debug_new_recorder &)
void _M_process(void *pointer)
_Tp * operator->*(_Tp *pointer)
Definition debug_new.h:190
__debug_new_recorder & operator=(const __debug_new_recorder &)
bool new_verbose_flag
const char * new_progname
bool new_autocheck_flag
QX_DLL_EXPORT int check_mem_corruption()
static __debug_new_counter __debug_new_count
Definition debug_new.h:212
QX_DLL_EXPORT int check_leaks()
FILE * new_output_fp
Root namespace for all QxOrm library features.