Add LTTngUSTLogger logger plugin test
[deliverable/titan.core.git] / common / new.cc
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Balasko, Jeno
10 * Raduly, Csaba
11 * Szabo, Janos Zoltan – initial implementation
12 *
13 ******************************************************************************/
14 #include "dbgnew.hh"
15 #include <stddef.h>
16
17 #undef new
18
19 static void *dummy = NULL;
20
21 void *operator new(size_t size) throw (std::bad_alloc)
22 {
23 return Malloc(size);
24 }
25
26 void *operator new[](size_t size) throw (std::bad_alloc)
27 {
28 if (size == 0) return &dummy;
29 else return Malloc(size);
30 }
31
32 void operator delete(void *ptr) throw()
33 {
34 Free(ptr);
35 }
36
37 void operator delete[](void *ptr) throw()
38 {
39 if (ptr != (void*)&dummy) Free(ptr);
40 }
41
42 /**************************************************************************/
43
44 #ifdef MEMORY_DEBUG
45
46 // overloads for memory debug
47 void* operator new(size_t size, const char* file, int line)
48 {
49 return Malloc_dbg(file, line, size);
50 }
51
52 void* operator new[](size_t size, const char* file, int line)
53 {
54 if (size == 0) return &dummy;
55 else return Malloc_dbg(file, line, size);
56 }
57
58 void* operator new(size_t size, const std::nothrow_t&, const char* file, int line)
59 {
60 return Malloc_dbg(file, line, size);
61 }
62
63 void* operator new[](size_t size, const std::nothrow_t&, const char* file, int line)
64 {
65 if (size == 0) return &dummy;
66 else return Malloc_dbg(file, line, size);
67 }
68
69 int debug_new_counter_t::count = 0; // initial value
70
71 #if defined(__CYGWIN__) || defined(INTERIX)
72
73 extern char**__argv;
74
75 #else
76
77 const char * __argv [] __attribute__((weak)) =
78 {
79 "program"
80 };
81
82 #endif
83
84 const char * debug_new_counter_t::progname = __argv[0];
85
86 debug_new_counter_t::debug_new_counter_t()
87 {
88 ++count;
89 }
90
91 debug_new_counter_t::~debug_new_counter_t()
92 {
93 if (--count == 0) {
94 check_mem_leak(progname);
95 }
96 }
97
98 void debug_new_counter_t::set_program_name(const char * pgn)
99 {
100 progname = pgn;
101 }
102
103 #endif // MEMORY_DEBUG
This page took 0.03415 seconds and 5 git commands to generate.