forked from foonathan/memory
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.cpp
More file actions
105 lines (85 loc) · 2.94 KB
/
Copy patherror.cpp
File metadata and controls
105 lines (85 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2015-2023 Jonathan Müller and foonathan/memory contributors
// SPDX-License-Identifier: Zlib
#include "error.hpp"
#include <atomic>
#if FOONATHAN_HOSTED_IMPLEMENTATION
#include <cstdio>
#endif
using namespace foonathan::memory;
namespace
{
void default_out_of_memory_handler(const allocator_info& info, std::size_t amount) noexcept
{
#if FOONATHAN_HOSTED_IMPLEMENTATION
std::fprintf(stderr,
"[%s] Allocator %s (at %p) ran out of memory trying to allocate %zu bytes.\n",
FOONATHAN_MEMORY_LOG_PREFIX, info.name, info.allocator, amount);
#endif
}
std::atomic<out_of_memory::handler> out_of_memory_h(default_out_of_memory_handler);
} // namespace
out_of_memory::handler out_of_memory::set_handler(out_of_memory::handler h)
{
return out_of_memory_h.exchange(h ? h : default_out_of_memory_handler);
}
out_of_memory::handler out_of_memory::get_handler()
{
return out_of_memory_h;
}
out_of_memory::out_of_memory(const allocator_info& info, std::size_t amount)
: info_(info), amount_(amount)
{
out_of_memory_h.load()(info, amount);
}
const char* out_of_memory::what() const noexcept
{
return "low-level allocator is out of memory";
}
const char* out_of_fixed_memory::what() const noexcept
{
return "fixed size allocator is out of memory";
}
namespace
{
void default_bad_alloc_size_handler(const allocator_info& info, std::size_t passed,
std::size_t supported) noexcept
{
#if FOONATHAN_HOSTED_IMPLEMENTATION
std::fprintf(stderr,
"[%s] Allocator %s (at %p) received invalid size/alignment %zu, "
"max supported is %zu\n",
FOONATHAN_MEMORY_LOG_PREFIX, info.name, info.allocator, passed, supported);
#endif
}
std::atomic<bad_allocation_size::handler> bad_alloc_size_h(default_bad_alloc_size_handler);
} // namespace
bad_allocation_size::handler bad_allocation_size::set_handler(bad_allocation_size::handler h)
{
return bad_alloc_size_h.exchange(h ? h : default_bad_alloc_size_handler);
}
bad_allocation_size::handler bad_allocation_size::get_handler()
{
return bad_alloc_size_h;
}
bad_allocation_size::bad_allocation_size(const allocator_info& info, std::size_t passed,
std::size_t supported)
: info_(info), passed_(passed), supported_(supported)
{
bad_alloc_size_h.load()(info_, passed_, supported_);
}
const char* bad_allocation_size::what() const noexcept
{
return "allocation node size exceeds supported maximum of allocator";
}
const char* bad_node_size::what() const noexcept
{
return "allocation node size exceeds supported maximum of allocator";
}
const char* bad_array_size::what() const noexcept
{
return "allocation array size exceeds supported maximum of allocator";
}
const char* bad_alignment::what() const noexcept
{
return "allocation alignment exceeds supported maximum of allocator";
}