Merge github.com:eclipse/titan.core
[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 ()
22 {
23 return Malloc(size);
24 }
25
26 void *operator new[](size_t size) throw ()
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 int debug_new_counter_t::count = 0; // initial value
59
60 #if defined(__CYGWIN__) || defined(INTERIX)
61
62 extern char**__argv;
63
64 #else
65
66 const char * __argv [] __attribute__((weak)) =
67 {
68 "program"
69 };
70
71 #endif
72
73 const char * debug_new_counter_t::progname = __argv[0];
74
75 debug_new_counter_t::debug_new_counter_t()
76 {
77 ++count;
78 }
79
80 debug_new_counter_t::~debug_new_counter_t()
81 {
82 if (--count == 0) {
83 check_mem_leak(progname);
84 }
85 }
86
87 void debug_new_counter_t::set_program_name(const char * pgn)
88 {
89 progname = pgn;
90 }
91
92 #endif // MEMORY_DEBUG
This page took 0.045116 seconds and 6 git commands to generate.