Skip to content

Commit c42a375

Browse files
committed
ffi: don't use empty enums for opaque types
The nomicon doesn't like this. From the bottom of https://doc.rust-lang.org/nomicon/ffi.html "Notice that it is a really bad idea to use an empty enum as FFI type. The compiler relies on empty enums being uninhabited, so handling values of type &Empty is a huge footgun and can lead to buggy program behavior (by triggering undefined behavior)." They give an example that uses a phantom to also remove Send, Sync, and Unpin. I did not do this. I think all these traits are fine, because the type has no self-references and is never mutated by the C code except when it is freed, and then only through a `*mut` pointer.
1 parent 2d8c56e commit c42a375

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

simplicity-sys/src/c_jets/c_env/elements.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ pub struct CRawTapEnv {
130130
pub branch_len: u8,
131131
}
132132

133-
#[derive(Debug)]
134-
pub enum CTransaction {}
133+
#[repr(C)]
134+
pub struct CTransaction {
135+
_data: (),
136+
}
135137

136138
#[derive(Debug)]
137139
#[repr(C)]
@@ -143,8 +145,10 @@ pub struct CTxEnv {
143145
ix: c_uint_fast32_t,
144146
}
145147

146-
#[derive(Debug)]
147-
pub enum CTapEnv {}
148+
#[repr(C)]
149+
pub struct CTapEnv {
150+
_data: (),
151+
}
148152

149153
extern "C" {
150154
#[link_name = "rustsimplicity_0_5_c_sizeof_rawElementsBuffer"]

0 commit comments

Comments
 (0)