Skip to content

Commit d28440b

Browse files
committed
Merge #347: Fix FFI type layout for Android
8839c91 Bump simplicity-sys version to 0.6.2 (Kyryl R) 462ee05 fix: fix type layout for android (Kyryl R) 27d8ca0 feat: add ability to get what is mismatched when calling sanity_checks (Kyryl R) Pull request description: Apparently my docker check was wrong: #334 (comment) This time I launched in on Android and verified that it works ACKs for top commit: apoelstra: ACK 8839c91; successfully ran local tests; though I don't have an Android system to test on. Also **technically** this is a breaking change but it's a bugfix so I'm happy to do a point release with it Tree-SHA512: fa53963543075793ec37ad177927f8db460d569276646d4e4acdcc5b6fb3c3807517f67696f879858e1704cbb9fd42e3bc798a8177160e6dec05e6c7cc3b643e
2 parents b73d6a5 + 8839c91 commit d28440b

File tree

5 files changed

+87
-43
lines changed

5 files changed

+87
-43
lines changed

Cargo-recent.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ dependencies = [
523523
"santiago",
524524
"serde",
525525
"serde_json",
526-
"simplicity-sys 0.6.1",
526+
"simplicity-sys 0.6.2",
527527
]
528528

529529
[[package]]
@@ -538,7 +538,7 @@ dependencies = [
538538

539539
[[package]]
540540
name = "simplicity-sys"
541-
version = "0.6.1"
541+
version = "0.6.2"
542542
dependencies = [
543543
"bitcoin_hashes",
544544
"cc",

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ ghost-cell = { version = "0.2.6", default-features = false }
3030
hashes = { package = "bitcoin_hashes", version = "0.14" }
3131
hex = { package = "hex-conservative", version = "0.2.1" }
3232
santiago = "1.3"
33-
simplicity-sys = { version = "0.6.1", path = "./simplicity-sys" }
33+
simplicity-sys = { version = "0.6.2", path = "./simplicity-sys" }
3434
serde = { version = "1.0.103", features = ["derive"], optional = true }
3535

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

3939
[dev-dependencies]
40-
simplicity-sys = { version = "0.6.1", path = "./simplicity-sys", features = [
40+
simplicity-sys = { version = "0.6.2", path = "./simplicity-sys", features = [
4141
"test-utils",
4242
] }
4343
serde_json = "1.0.149"

simplicity-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "simplicity-sys"
3-
version = "0.6.1"
3+
version = "0.6.2"
44
license = "CC0-1.0"
55
homepage = "https://github.com/BlockstreamResearch/rust-simplicity/"
66
repository = "https://github.com/BlockstreamResearch/rust-simplicity/"

simplicity-sys/src/c_jets/mod.rs

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,83 @@ pub mod exec_ffi;
2828
///
2929
/// This will also us detect whenever there is a change in the underlying C representation
3030
pub fn sanity_checks() -> bool {
31-
unsafe {
32-
if std::mem::size_of::<crate::ffi::UWORD>() != crate::ffi::c_sizeof_UWORD
33-
|| std::mem::align_of::<crate::ffi::UWORD>() != crate::ffi::c_alignof_UWORD
34-
{
35-
return false;
36-
}
37-
38-
if std::mem::size_of::<CFrameItem>() != frame_ffi::c_sizeof_frameItem
39-
|| std::mem::size_of::<elements::CRawBuffer>() != c_env::elements::c_sizeof_rawBuffer
40-
|| std::mem::size_of::<elements::CRawInput>() != c_env::elements::c_sizeof_rawInput
41-
|| std::mem::size_of::<elements::CRawOutput>() != c_env::elements::c_sizeof_rawOutput
42-
|| std::mem::size_of::<elements::CRawTransaction>()
43-
!= c_env::elements::c_sizeof_rawTransaction
44-
|| std::mem::size_of::<elements::CTxEnv>() != c_env::elements::c_sizeof_txEnv
45-
|| std::mem::size_of::<elements::CRawTapEnv>() != c_env::elements::c_sizeof_rawTapEnv
46-
{
47-
return false;
48-
}
49-
50-
if std::mem::align_of::<CFrameItem>() != frame_ffi::c_alignof_frameItem
51-
|| std::mem::align_of::<elements::CRawBuffer>() != c_env::elements::c_alignof_rawBuffer
52-
|| std::mem::align_of::<elements::CRawInput>() != c_env::elements::c_alignof_rawInput
53-
|| std::mem::align_of::<elements::CRawOutput>() != c_env::elements::c_alignof_rawOutput
54-
|| std::mem::align_of::<elements::CRawTransaction>()
55-
!= c_env::elements::c_alignof_rawTransaction
56-
|| std::mem::align_of::<elements::CTxEnv>() != c_env::elements::c_alignof_txEnv
57-
|| std::mem::align_of::<elements::CRawTapEnv>() != c_env::elements::c_alignof_rawTapEnv
58-
{
59-
return false;
60-
}
31+
sanity_check_report().is_empty()
32+
}
33+
34+
#[must_use]
35+
pub fn sanity_check_report() -> Vec<String> {
36+
let mut issues = Vec::new();
37+
38+
macro_rules! check_layout {
39+
($ty:ty, $c_size:path, $c_align:path, $name:expr) => {{
40+
let rust_size = std::mem::size_of::<$ty>();
41+
let rust_align = std::mem::align_of::<$ty>();
42+
let (c_size, c_align) = unsafe { ($c_size, $c_align) };
43+
44+
if rust_size != c_size {
45+
issues.push(format!(
46+
"{name}: size mismatch (rust={rust_size}, c={c_size})",
47+
name = $name
48+
));
49+
}
50+
51+
if rust_align != c_align {
52+
issues.push(format!(
53+
"{name}: align mismatch (rust={rust_align}, c={c_align})",
54+
name = $name
55+
));
56+
}
57+
}};
6158
}
62-
true
59+
60+
check_layout!(
61+
crate::ffi::UWORD,
62+
crate::ffi::c_sizeof_UWORD,
63+
crate::ffi::c_alignof_UWORD,
64+
"UWORD"
65+
);
66+
check_layout!(
67+
CFrameItem,
68+
frame_ffi::c_sizeof_frameItem,
69+
frame_ffi::c_alignof_frameItem,
70+
"CFrameItem"
71+
);
72+
check_layout!(
73+
elements::CRawBuffer,
74+
elements::c_sizeof_rawBuffer,
75+
elements::c_alignof_rawBuffer,
76+
"CRawBuffer"
77+
);
78+
check_layout!(
79+
elements::CRawInput,
80+
elements::c_sizeof_rawInput,
81+
elements::c_alignof_rawInput,
82+
"CRawInput"
83+
);
84+
check_layout!(
85+
elements::CRawOutput,
86+
elements::c_sizeof_rawOutput,
87+
elements::c_alignof_rawOutput,
88+
"CRawOutput"
89+
);
90+
check_layout!(
91+
elements::CRawTransaction,
92+
elements::c_sizeof_rawTransaction,
93+
elements::c_alignof_rawTransaction,
94+
"CRawTransaction"
95+
);
96+
check_layout!(
97+
elements::CTxEnv,
98+
elements::c_sizeof_txEnv,
99+
elements::c_alignof_txEnv,
100+
"CTxEnv"
101+
);
102+
check_layout!(
103+
elements::CRawTapEnv,
104+
elements::c_sizeof_rawTapEnv,
105+
elements::c_alignof_rawTapEnv,
106+
"CRawTapEnv"
107+
);
108+
109+
issues
63110
}

simplicity-sys/src/ffi.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@ pub type c_size_t = usize;
2121
pub type c_uint_fast8_t = u8;
2222
#[cfg(any(target_os = "macos", target_os = "ios"))]
2323
pub type c_uint_fast16_t = u16;
24-
#[cfg(any(target_os = "windows", target_os = "android"))]
24+
#[cfg(target_os = "windows")]
2525
pub type c_uint_fast16_t = u32;
2626
#[cfg(target_arch = "wasm32")]
2727
pub type c_uint_fast16_t = u16;
2828
#[cfg(not(any(
2929
target_os = "macos",
3030
target_os = "ios",
3131
target_os = "windows",
32-
target_os = "android",
3332
target_arch = "wasm32"
3433
)))]
3534
pub type c_uint_fast16_t = usize;
@@ -38,22 +37,20 @@ pub type c_uint_fast16_t = usize;
3837
target_os = "macos",
3938
target_os = "ios",
4039
target_os = "windows",
41-
target_os = "android",
4240
target_arch = "wasm32"
4341
))]
4442
pub type c_uint_fast32_t = u32;
4543
#[cfg(not(any(
4644
target_os = "macos",
4745
target_os = "ios",
4846
target_os = "windows",
49-
target_os = "android",
5047
target_arch = "wasm32"
5148
)))]
5249
pub type c_uint_fast32_t = usize;
53-
#[cfg(target_arch = "wasm32")]
54-
pub type c_uint_fast64_t = u64;
55-
#[cfg(not(target_arch = "wasm32"))]
50+
#[cfg(target_pointer_width = "64")]
5651
pub type c_uint_fast64_t = usize;
52+
#[cfg(not(target_pointer_width = "64"))]
53+
pub type c_uint_fast64_t = u64;
5754
pub type c_uint_least32_t = u32;
5855

5956
extern "C" {

0 commit comments

Comments
 (0)