Initial import from FreeBSD RELENG_4:
[dragonfly.git] / contrib / gcc / cp / new2.cc
1 // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 // Copyright (C) 1997, 1998 Free Software Foundation
3
4 // This file is part of GNU CC.
5
6 // GNU CC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // GNU CC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License
17 // along with GNU CC; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA. 
20
21 // As a special exception, if you link this library with other files,
22 // some of which are compiled with GCC, to produce an executable,
23 // this library does not by itself cause the resulting executable
24 // to be covered by the GNU General Public License.
25 // This exception does not however invalidate any other reasons why
26 // the executable file might be covered by the GNU General Public License.
27
28 #include "new"
29
30 extern "C" void free (void *);
31
32 #define WEAK(x) \
33   x __attribute__ ((weak)); \
34   x
35
36 #ifdef L_op_vnew
37 WEAK(void * operator new[] (size_t sz) throw (std::bad_alloc))
38 {
39   return ::operator new(sz);
40 }
41 #endif
42
43 #ifdef L_op_vnewnt
44 WEAK(void *operator new[] (size_t sz, const std::nothrow_t& nothrow) throw())
45 {
46   return ::operator new(sz, nothrow);
47 }
48 #endif
49
50 #ifdef L_op_delete
51 WEAK (void operator delete (void *ptr) throw ())
52 {
53   if (ptr)
54     free (ptr);
55 }
56 #endif
57
58 #ifdef L_op_vdel
59 WEAK (void operator delete[] (void *ptr) throw ())
60 {
61   if (ptr)
62     free (ptr);
63 }
64 #endif
65
66 #ifdef L_op_delnt
67 WEAK (void operator delete (void *ptr, const std::nothrow_t&) throw ())
68 {
69   if (ptr)
70     free (ptr);
71 }
72 #endif
73
74 #ifdef L_op_vdelnt
75 WEAK (void operator delete[] (void *ptr, const std::nothrow_t&) throw ())
76 {
77   if (ptr)
78     free (ptr);
79 }
80 #endif