Merge pull request #10 from egerpil/master
[deliverable/titan.core.git] / common / new.cc
CommitLineData
970ed795 1///////////////////////////////////////////////////////////////////////////////
3abe9331 2// Copyright (c) 2000-2015 Ericsson Telecom AB
970ed795
EL
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#include "dbgnew.hh"
9#include <stddef.h>
10
11#undef new
12
13static void *dummy = NULL;
14
15void *operator new(size_t size) throw ()
16{
17 return Malloc(size);
18}
19
20void *operator new[](size_t size) throw ()
21{
22 if (size == 0) return &dummy;
23 else return Malloc(size);
24}
25
26void operator delete(void *ptr) throw()
27{
28 Free(ptr);
29}
30
31void operator delete[](void *ptr) throw()
32{
33 if (ptr != (void*)&dummy) Free(ptr);
34}
35
36/**************************************************************************/
37
38#ifdef MEMORY_DEBUG
39
40// overloads for memory debug
41void* operator new(size_t size, const char* file, int line)
42{
43 return Malloc_dbg(file, line, size);
44}
45
46void* operator new[](size_t size, const char* file, int line)
47{
48 if (size == 0) return &dummy;
49 else return Malloc_dbg(file, line, size);
50}
51
52int debug_new_counter_t::count = 0; // initial value
53
54#if defined(__CYGWIN__) || defined(INTERIX)
55
56extern char**__argv;
57
58#else
59
60const char * __argv [] __attribute__((weak)) =
61{
62 "program"
63};
64
65#endif
66
67const char * debug_new_counter_t::progname = __argv[0];
68
69debug_new_counter_t::debug_new_counter_t()
70{
71 ++count;
72}
73
74debug_new_counter_t::~debug_new_counter_t()
75{
76 if (--count == 0) {
77 check_mem_leak(progname);
78 }
79}
80
81void debug_new_counter_t::set_program_name(const char * pgn)
82{
83 progname = pgn;
84}
85
86#endif // MEMORY_DEBUG
This page took 0.026046 seconds and 5 git commands to generate.