Skip to content

Commit ef4f722

Browse files
committed
std: xous: share allocator symbol in tests
When using the testing framework, a second copy of libstd is built and linked. Use a global symbol for the `DLMALLOC` variable and mark it as `extern` when building as a test. This ensures we only have a single allocator even when running tests. Signed-off-by: Sean Cross <sean@xobs.io>
1 parent 007bf7a commit ef4f722

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

library/std/src/sys/pal/xous/alloc.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
use crate::alloc::{GlobalAlloc, Layout, System};
22

3+
#[cfg(not(test))]
4+
#[export_name = "_ZN16__rust_internals3std3sys4xous5alloc8DLMALLOCE"]
35
static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::Dlmalloc::new();
46

7+
#[cfg(test)]
8+
extern "Rust" {
9+
#[link_name = "_ZN16__rust_internals3std3sys4xous5alloc8DLMALLOCE"]
10+
static mut DLMALLOC: dlmalloc::Dlmalloc;
11+
}
12+
513
#[stable(feature = "alloc_system_type", since = "1.28.0")]
614
unsafe impl GlobalAlloc for System {
715
#[inline]

0 commit comments

Comments
 (0)