File tree 2 files changed +29
-30
lines changed
crates/swc_allocator/tests
2 files changed +29
-30
lines changed Original file line number Diff line number Diff line change 1
1
use criterion:: black_box;
2
- use swc_allocator:: Allocator ;
2
+ use swc_allocator:: { boxed :: Box , Allocator , FastAlloc } ;
3
3
4
4
#[ test]
5
5
fn direct_alloc_std ( ) {
@@ -33,3 +33,31 @@ fn direct_alloc_in_scope() {
33
33
vec. push ( item) ;
34
34
}
35
35
}
36
+
37
+ #[ test]
38
+ fn escape ( ) {
39
+ let allocator = Allocator :: default ( ) ;
40
+
41
+ let obj = {
42
+ let _guard = unsafe { allocator. guard ( ) } ;
43
+ Box :: new ( 1234 )
44
+ } ;
45
+
46
+ assert_eq ! ( * obj, 1234 ) ;
47
+ // It should not segfault, because the allocator is still alive.
48
+ drop ( obj) ;
49
+ }
50
+
51
+ #[ test]
52
+ fn global_allocator_escape ( ) {
53
+ let allocator = Allocator :: default ( ) ;
54
+ let obj = {
55
+ let _guard = unsafe { allocator. guard ( ) } ;
56
+ Box :: new_in ( 1234 , FastAlloc :: global ( ) )
57
+ } ;
58
+
59
+ assert_eq ! ( * obj, 1234 ) ;
60
+ drop ( allocator) ;
61
+ // Object created with global allocator should outlive the allocator.
62
+ drop ( obj) ;
63
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments