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
mod util;
#[cfg(feature = "local-rt")]
mod tests {
use jlrs::{
data::layout::tuple::{Tuple2, Tuple4},
prelude::*,
};
use super::util::JULIA;
fn read_atomic_field() {
JULIA.with(|handle| {
handle.borrow_mut().with_stack(|mut stack| {
stack.scope(|mut frame| unsafe {
let ty = {
Module::main(&frame)
.submodule(&frame, "JlrsStableTests")
.unwrap()
.as_managed()
.global(&frame, "WithAtomic")
.unwrap()
.as_value()
};
let arg1 = Value::new(&mut frame, 3u32);
let instance = ty.call(&mut frame, &mut [arg1]).unwrap();
let a = instance
.field_accessor()
.field("a")
.unwrap()
.access::<u32>()
.unwrap();
assert_eq!(a, 3);
})
})
})
}
fn read_large_atomic_field() {
JULIA.with(|handle| {
handle.borrow_mut().with_stack(|mut stack| {
stack.scope(|mut frame| unsafe {
let ty = {
Module::main(&frame)
.submodule(&frame, "JlrsStableTests")
.unwrap()
.as_managed()
.global(&frame, "WithLargeAtomic")
.unwrap()
.as_value()
};
let tup = Value::new(&mut frame, Tuple4(1u64, 2u64, 3u64, 4u64));
let instance = ty.call(&mut frame, &mut [tup]).unwrap();
let a = instance
.field_accessor()
.field("a")
.unwrap()
.access::<Tuple4<u64, u64, u64, u64>>()
.unwrap();
assert_eq!(a, Tuple4(1, 2, 3, 4));
})
})
})
}
fn read_oddly_sized_atomic_field() {
JULIA.with(|handle| {
handle.borrow_mut().with_stack(|mut stack| {
stack.scope(|mut frame| unsafe {
let ty = {
Module::main(&frame)
.submodule(&frame, "JlrsStableTests")
.unwrap()
.as_managed()
.global(&frame, "WithOddlySizedAtomic")
.unwrap()
.as_value()
};
let tup = Value::new(&mut frame, Tuple2(1u32, 2u16));
let instance = ty.call(&mut frame, &mut [tup]).unwrap();
let a = instance
.field_accessor()
.field("a")
.unwrap()
.access::<Tuple2<u32, u16>>()
.unwrap();
assert_eq!(a, Tuple2(1, 2));
})
})
})
}
fn atomic_union_is_pointer_field() {
JULIA.with(|handle| {
handle.borrow_mut().with_stack(|mut stack| {
stack.scope(|frame| {
let ty = unsafe {
Module::main(&frame)
.submodule(&frame, "JlrsStableTests")
.unwrap()
.as_managed()
.global(&frame, "WithAtomicUnion")
.unwrap()
.as_value()
};
assert!(ty.cast::<DataType>().unwrap().is_pointer_field(0).unwrap());
assert!(ty.cast::<DataType>().unwrap().is_atomic_field(0).unwrap());
assert!(ty.cast::<DataType>().unwrap().is_atomic_field(20).is_none());
})
})
})
}
#[test]
fn atomic_field_tests() {
read_atomic_field();
read_large_atomic_field();
read_oddly_sized_atomic_field();
atomic_union_is_pointer_field();
}
}