boc_sys/
descriptor.rs

1//! Object Descriptor
2//!
3//! See `src/rt/object/object.h` in `verona-rt`
4
5use core::marker::{PhantomData, PhantomPinned};
6
7#[repr(C)]
8// TODO: Is this FFI Safe??
9pub struct Object {
10    _data: [u8; 0],
11    _marker: PhantomData<(*mut u8, PhantomPinned)>,
12    // TODO: Give unique_id with USE_SYSTEMATIC_TESTING
13}
14
15#[repr(C)]
16pub struct ObjectStack {
17    _data: [u8; 0],
18    _marker: PhantomData<(*mut u8, PhantomPinned)>,
19}
20
21pub type TraceFunction = extern "C" fn(o: *const Object, st: *mut ObjectStack);
22
23pub type NotifiedFunction = extern "C" fn(o: *mut Object);
24
25pub type FinalFunction = extern "C" fn(o: *mut Object, region: *mut Object, st: *mut ObjectStack);
26
27pub type DestructorFunction = extern "C" fn(o: *mut Object);
28
29pub extern "C" fn noop_trace(_o: *const Object, _st: *mut ObjectStack) {}
30
31#[repr(C)]
32// TODO: Make sure this is aligned correctly on non-64bit platforms.
33pub struct Descriptor {
34    pub size: usize,
35    pub trace: TraceFunction,
36    pub finaliser: Option<FinalFunction>,
37    pub notified: Option<NotifiedFunction>,
38    pub destructor: Option<DestructorFunction>,
39}
40
41#[test]
42fn size_and_align() {
43    #[link(name = "boxcar_bindings")]
44    extern "C" {
45        fn boxcars_test_descriptor_info(size: &mut usize, align: &mut usize);
46    }
47    let mut size = 0;
48    let mut align = 0;
49    unsafe {
50        boxcars_test_descriptor_info(&mut size, &mut align);
51    }
52    assert_eq!(size, std::mem::size_of::<Descriptor>());
53    assert_eq!(align, std::mem::align_of::<Descriptor>())
54}
55
56#[test]
57fn noop_signature() {
58    let _: TraceFunction = noop_trace;
59}