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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
//! dhat-rs-shaped compatibility surface.
//!
//! Behind the `dhat-compat` cargo feature. Provides drop-in
//! replacements for `dhat::Alloc`, `dhat::Profiler`,
//! `dhat::ProfilerBuilder`, `dhat::HeapStats`, `dhat::AdHocStats`,
//! and `dhat::ad_hoc_event` so consumers migrating from dhat-rs
//! can swap allocator profilers with a one-line import change:
//!
//! ```no_run
//! # #[cfg(feature = "dhat-compat")]
//! # mod swap_example {
//! use mod_alloc::dhat_compat as dhat;
//!
//! #[global_allocator]
//! static ALLOC: dhat::Alloc = dhat::Alloc;
//!
//! fn main() {
//! let _profiler = dhat::Profiler::new_heap();
//! // ... work ...
//! // _profiler drops here → writes dhat-heap.json
//! }
//! # }
//! ```
//!
//! ## Differences from dhat-rs
//!
//! Documented in `MIGRATING_FROM_DHAT.md`. Summary:
//!
//! - Backtrace depth is capped at 8 frames (Tier 2 walker limit);
//! `ProfilerBuilder::trim_backtraces` is accepted for parity
//! but silently clamps.
//! - Drop-time file-write errors are swallowed silently — same
//! as dhat-rs's behaviour.
//! - Double-Profiler construction is a no-op rather than a panic
//! (dhat-rs panics). Last writer wins on the JSON file.
//! - `dhat::assert!` / `assert_eq!` / `assert_ne!` macros are not
//! yet shipped. Use `HeapStats::get()` directly in test
//! assertions.
use ;
pub use ;
pub use ;
/// Drop-in replacement for `dhat::Alloc`.
///
/// Unit struct usable in the literal `static A: Alloc = Alloc;`
/// pattern that dhat-rs documents. Internally forwards every
/// allocation to a process-wide static [`crate::ModAlloc`] so
/// `HeapStats::get()` and `Profiler` find the live counters.
///
/// # Example
///
/// ```no_run
/// # #[cfg(feature = "dhat-compat")]
/// # mod ex {
/// use mod_alloc::dhat_compat::Alloc;
///
/// #[global_allocator]
/// static ALLOC: Alloc = Alloc;
/// # }
/// ```
;
// Process-wide tracking allocator that all `Alloc` instances
// delegate to. Hosting it as a `static` (rather than per-`Alloc`)
// is necessary because `Alloc` itself is a zero-sized type — it
// has no place to put atomic counters — and because dhat-rs's
// pattern uses literal `dhat::Alloc` values in `static` position
// without any constructor call.
static INNER: crateModAlloc = cratenew;
// SAFETY: `Alloc` is a thin forwarding wrapper around `INNER`,
// which is a `'static` `ModAlloc`. Every `GlobalAlloc` method
// forwards its arguments unchanged to `INNER`'s implementation;
// size and alignment invariants pass through unmodified. `INNER`
// itself satisfies the `GlobalAlloc` contract (see
// `crate::ModAlloc`'s `unsafe impl`), so the same contract holds
// through the forwarder.
unsafe