MODULE_PARAMETERS section corrected
[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 #include <new>
17
18 #undef new
19
20 static void *dummy = NULL;
21
22 void *operator new(size_t size) throw (std::bad_alloc)
23 {
24 return Malloc(size);
25 }
26
27 void *operator new[](size_t size) throw (std::bad_alloc)
28 {
29 if (size == 0) return &dummy;
30 else return Malloc(size);
31 }
32
33 void operator delete(void *ptr) throw()
34 {
35 Free(ptr);
36 }
37
38 void operator delete[](void *ptr) throw()
39 {
40 if (ptr != (void*)&dummy) Free(ptr);
41 }
42
43 /**************************************************************************/
44
45 #ifdef MEMORY_DEBUG
46
47 // overloads for memory debug
48 void* operator new(size_t size, const char* file, int line)
49 {
50 return Malloc_dbg(file, line, size);
51 }
52
53 void* operator new[](size_t size, const char* file, int line)
54 {
55 if (size == 0) return &dummy;
56 else return Malloc_dbg(file, line, size);
57 }
58
59 int debug_new_counter_t::count = 0; // initial value
60
61 #if defined(__CYGWIN__) || defined(INTERIX)
62
63 extern char**__argv;
64
65 #else
66
67 const char * __argv [] __attribute__((weak)) =
68 {
69 "program"
70 };
71
72 #endif
73
74 const char * debug_new_counter_t::progname = __argv[0];
75
76 debug_new_counter_t::debug_new_counter_t()
77 {
78 ++count;
79 }
80
81 debug_new_counter_t::~debug_new_counter_t()
82 {
83 if (--count == 0) {
84 check_mem_leak(progname);
85 }
86 }
87
88 void debug_new_counter_t::set_program_name(const char * pgn)
89 {
90 progname = pgn;
91 }
92
93 #endif // MEMORY_DEBUG
This page took 0.032058 seconds and 5 git commands to generate.