annotate libstdc++-v3/testsuite/util/testsuite_new_operators.h @ 155:da32f4b04d38

fix __code name conflict
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 17:51:46 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // -*- C++ -*-
kono
parents:
diff changeset
2 // Utility subroutines for the C++ library testsuite.
kono
parents:
diff changeset
3 //
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
4 // Copyright (C) 2000-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
5 //
kono
parents:
diff changeset
6 // This file is part of the GNU ISO C++ Library. This library is free
kono
parents:
diff changeset
7 // software; you can redistribute it and/or modify it under the
kono
parents:
diff changeset
8 // terms of the GNU General Public License as published by the
kono
parents:
diff changeset
9 // Free Software Foundation; either version 3, or (at your option)
kono
parents:
diff changeset
10 // any later version.
kono
parents:
diff changeset
11 //
kono
parents:
diff changeset
12 // This library is distributed in the hope that it will be useful,
kono
parents:
diff changeset
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
15 // GNU General Public License for more details.
kono
parents:
diff changeset
16 //
kono
parents:
diff changeset
17 // You should have received a copy of the GNU General Public License along
kono
parents:
diff changeset
18 // with this library; see the file COPYING3. If not see
kono
parents:
diff changeset
19 // <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
20 //
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 #ifndef _GLIBCXX_TESTSUITE_NEW_OPERATORS_H
kono
parents:
diff changeset
23 #define _GLIBCXX_TESTSUITE_NEW_OPERATORS_H
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 #include <new>
kono
parents:
diff changeset
26 #include <testsuite_hooks.h>
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 namespace __gnu_test
kono
parents:
diff changeset
29 {
kono
parents:
diff changeset
30 std::size_t&
kono
parents:
diff changeset
31 get_new_limit()
kono
parents:
diff changeset
32 {
kono
parents:
diff changeset
33 static std::size_t limit = 1024 * 1024;
kono
parents:
diff changeset
34 return limit;
kono
parents:
diff changeset
35 }
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 void
kono
parents:
diff changeset
38 set_new_limit(std::size_t l)
kono
parents:
diff changeset
39 { get_new_limit() = l; }
kono
parents:
diff changeset
40 }
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 void* operator new(std::size_t size) THROW(std::bad_alloc)
kono
parents:
diff changeset
43 {
kono
parents:
diff changeset
44 if (size > __gnu_test::get_new_limit())
kono
parents:
diff changeset
45 throw std::bad_alloc();
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 void* p = std::malloc(size);
kono
parents:
diff changeset
48 if (!p)
kono
parents:
diff changeset
49 throw std::bad_alloc();
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 return p;
kono
parents:
diff changeset
52 }
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 void* operator new (std::size_t size, const std::nothrow_t&) throw()
kono
parents:
diff changeset
55 {
kono
parents:
diff changeset
56 if (size > __gnu_test::get_new_limit())
kono
parents:
diff changeset
57 return 0;
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 return std::malloc(size);
kono
parents:
diff changeset
60 }
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 void operator delete(void* p) throw()
kono
parents:
diff changeset
63 {
kono
parents:
diff changeset
64 if (p)
kono
parents:
diff changeset
65 std::free(p);
kono
parents:
diff changeset
66 }
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 void operator delete(void* p, const std::nothrow_t&) throw()
kono
parents:
diff changeset
69 {
kono
parents:
diff changeset
70 if (p)
kono
parents:
diff changeset
71 std::free(p);
kono
parents:
diff changeset
72 }
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 #endif // _GLIBCXX_TESTSUITE_NEW_OPERATORS_H
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77