Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(allocator): Merge test #9267

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::black_box;
use swc_allocator::Allocator;
use swc_allocator::{boxed::Box, Allocator, FastAlloc};

#[test]
fn direct_alloc_std() {
Expand Down Expand Up @@ -33,3 +33,31 @@ fn direct_alloc_in_scope() {
vec.push(item);
}
}

#[test]
fn escape() {
let allocator = Allocator::default();

let obj = {
let _guard = unsafe { allocator.guard() };
Box::new(1234)
};

assert_eq!(*obj, 1234);
// It should not segfault, because the allocator is still alive.
drop(obj);
}

#[test]
fn global_allocator_escape() {
let allocator = Allocator::default();
let obj = {
let _guard = unsafe { allocator.guard() };
Box::new_in(1234, FastAlloc::global())
};

assert_eq!(*obj, 1234);
drop(allocator);
// Object created with global allocator should outlive the allocator.
drop(obj);
}
29 changes: 0 additions & 29 deletions crates/swc_allocator/tests/escape.rs

This file was deleted.

Loading