Skip to content
Open
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
4 changes: 2 additions & 2 deletions Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ dependencies = [
"miniscript",
"santiago",
"serde",
"simplicity-sys 0.6.1",
"simplicity-sys 0.6.2",
]

[[package]]
Expand All @@ -518,7 +518,7 @@ dependencies = [

[[package]]
name = "simplicity-sys"
version = "0.6.1"
version = "0.6.2"
dependencies = [
"bitcoin_hashes",
"cc",
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ ghost-cell = { version = "0.2.6", default-features = false }
hashes = { package = "bitcoin_hashes", version = "0.14" }
hex = { package = "hex-conservative", version = "0.2.1" }
santiago = "1.3"
simplicity-sys = { version = "0.6.1", path = "./simplicity-sys" }
simplicity-sys = { version = "0.6.2", path = "./simplicity-sys" }
serde = { version = "1.0.103", features = ["derive"], optional = true }

[target.wasm32-unknown-unknown.dependencies]
getrandom = { version = "0.2", features = ["js"] }

[dev-dependencies]
simplicity-sys = { version = "0.6.1", path = "./simplicity-sys", features = [
simplicity-sys = { version = "0.6.2", path = "./simplicity-sys", features = [
"test-utils",
] }

Expand Down
2 changes: 1 addition & 1 deletion simplicity-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "simplicity-sys"
version = "0.6.1"
version = "0.6.2"
license = "CC0-1.0"
homepage = "https://github.com/BlockstreamResearch/rust-simplicity/"
repository = "https://github.com/BlockstreamResearch/rust-simplicity/"
Expand Down
109 changes: 78 additions & 31 deletions simplicity-sys/src/c_jets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,83 @@ pub mod exec_ffi;
///
/// This will also us detect whenever there is a change in the underlying C representation
pub fn sanity_checks() -> bool {
unsafe {
if std::mem::size_of::<crate::ffi::UWORD>() != crate::ffi::c_sizeof_UWORD
|| std::mem::align_of::<crate::ffi::UWORD>() != crate::ffi::c_alignof_UWORD
{
return false;
}

if std::mem::size_of::<CFrameItem>() != frame_ffi::c_sizeof_frameItem
|| std::mem::size_of::<elements::CRawBuffer>() != c_env::elements::c_sizeof_rawBuffer
|| std::mem::size_of::<elements::CRawInput>() != c_env::elements::c_sizeof_rawInput
|| std::mem::size_of::<elements::CRawOutput>() != c_env::elements::c_sizeof_rawOutput
|| std::mem::size_of::<elements::CRawTransaction>()
!= c_env::elements::c_sizeof_rawTransaction
|| std::mem::size_of::<elements::CTxEnv>() != c_env::elements::c_sizeof_txEnv
|| std::mem::size_of::<elements::CRawTapEnv>() != c_env::elements::c_sizeof_rawTapEnv
{
return false;
}

if std::mem::align_of::<CFrameItem>() != frame_ffi::c_alignof_frameItem
|| std::mem::align_of::<elements::CRawBuffer>() != c_env::elements::c_alignof_rawBuffer
|| std::mem::align_of::<elements::CRawInput>() != c_env::elements::c_alignof_rawInput
|| std::mem::align_of::<elements::CRawOutput>() != c_env::elements::c_alignof_rawOutput
|| std::mem::align_of::<elements::CRawTransaction>()
!= c_env::elements::c_alignof_rawTransaction
|| std::mem::align_of::<elements::CTxEnv>() != c_env::elements::c_alignof_txEnv
|| std::mem::align_of::<elements::CRawTapEnv>() != c_env::elements::c_alignof_rawTapEnv
{
return false;
}
sanity_check_report().is_empty()
}

#[must_use]
pub fn sanity_check_report() -> Vec<String> {
let mut issues = Vec::new();

macro_rules! check_layout {
($ty:ty, $c_size:path, $c_align:path, $name:expr) => {{
let rust_size = std::mem::size_of::<$ty>();
let rust_align = std::mem::align_of::<$ty>();
let (c_size, c_align) = unsafe { ($c_size, $c_align) };

if rust_size != c_size {
issues.push(format!(
"{name}: size mismatch (rust={rust_size}, c={c_size})",
name = $name
));
}

if rust_align != c_align {
issues.push(format!(
"{name}: align mismatch (rust={rust_align}, c={c_align})",
name = $name
));
}
}};
}
true

check_layout!(
crate::ffi::UWORD,
crate::ffi::c_sizeof_UWORD,
crate::ffi::c_alignof_UWORD,
"UWORD"
);
check_layout!(
CFrameItem,
frame_ffi::c_sizeof_frameItem,
frame_ffi::c_alignof_frameItem,
"CFrameItem"
);
check_layout!(
elements::CRawBuffer,
elements::c_sizeof_rawBuffer,
elements::c_alignof_rawBuffer,
"CRawBuffer"
);
check_layout!(
elements::CRawInput,
elements::c_sizeof_rawInput,
elements::c_alignof_rawInput,
"CRawInput"
);
check_layout!(
elements::CRawOutput,
elements::c_sizeof_rawOutput,
elements::c_alignof_rawOutput,
"CRawOutput"
);
check_layout!(
elements::CRawTransaction,
elements::c_sizeof_rawTransaction,
elements::c_alignof_rawTransaction,
"CRawTransaction"
);
check_layout!(
elements::CTxEnv,
elements::c_sizeof_txEnv,
elements::c_alignof_txEnv,
"CTxEnv"
);
check_layout!(
elements::CRawTapEnv,
elements::c_sizeof_rawTapEnv,
elements::c_alignof_rawTapEnv,
"CRawTapEnv"
);

issues
}
11 changes: 4 additions & 7 deletions simplicity-sys/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ pub type c_size_t = usize;
pub type c_uint_fast8_t = u8;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub type c_uint_fast16_t = u16;
#[cfg(any(target_os = "windows", target_os = "android"))]
#[cfg(target_os = "windows")]
pub type c_uint_fast16_t = u32;
#[cfg(target_arch = "wasm32")]
pub type c_uint_fast16_t = u16;
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "windows",
target_os = "android",
target_arch = "wasm32"
)))]
pub type c_uint_fast16_t = usize;
Expand All @@ -38,22 +37,20 @@ pub type c_uint_fast16_t = usize;
target_os = "macos",
target_os = "ios",
target_os = "windows",
target_os = "android",
target_arch = "wasm32"
))]
pub type c_uint_fast32_t = u32;
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "windows",
target_os = "android",
target_arch = "wasm32"
)))]
pub type c_uint_fast32_t = usize;
#[cfg(target_arch = "wasm32")]
pub type c_uint_fast64_t = u64;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(target_pointer_width = "64")]
pub type c_uint_fast64_t = usize;
#[cfg(not(target_pointer_width = "64"))]
pub type c_uint_fast64_t = u64;
pub type c_uint_least32_t = u32;

extern "C" {
Expand Down
Loading