MODULE_PARAMETERS section corrected
[deliverable/titan.core.git] / common / new.cc
CommitLineData
d44e3c4f 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 ******************************************************************************/
970ed795
EL
14#include "dbgnew.hh"
15#include <stddef.h>
0d8b746e 16#include <new>
970ed795
EL
17
18#undef new
19
20static void *dummy = NULL;
21
0d8b746e 22void *operator new(size_t size) throw (std::bad_alloc)
970ed795
EL
23{
24 return Malloc(size);
25}
26
0d8b746e 27void *operator new[](size_t size) throw (std::bad_alloc)
970ed795
EL
28{
29 if (size == 0) return &dummy;
30 else return Malloc(size);
31}
32
33void operator delete(void *ptr) throw()
34{
35 Free(ptr);
36}
37
38void 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
48void* operator new(size_t size, const char* file, int line)
49{
50 return Malloc_dbg(file, line, size);
51}
52
53void* 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
59int debug_new_counter_t::count = 0; // initial value
60
61#if defined(__CYGWIN__) || defined(INTERIX)
62
63extern char**__argv;
64
65#else
66
67const char * __argv [] __attribute__((weak)) =
68{
69 "program"
70};
71
72#endif
73
74const char * debug_new_counter_t::progname = __argv[0];
75
76debug_new_counter_t::debug_new_counter_t()
77{
78 ++count;
79}
80
81debug_new_counter_t::~debug_new_counter_t()
82{
83 if (--count == 0) {
84 check_mem_leak(progname);
85 }
86}
87
88void debug_new_counter_t::set_program_name(const char * pgn)
89{
90 progname = pgn;
91}
92
93#endif // MEMORY_DEBUG
This page took 0.026626 seconds and 5 git commands to generate.