diff --git a/minijinja-cabi/include/minijinja.h b/minijinja-cabi/include/minijinja.h index 348ea95c..f7f381aa 100644 --- a/minijinja-cabi/include/minijinja.h +++ b/minijinja-cabi/include/minijinja.h @@ -92,7 +92,7 @@ typedef struct mj_value_iter mj_value_iter; Opaque value type. */ typedef struct mj_value { - uintptr_t _opaque[3]; + uint64_t _opaque[3]; } mj_value; /* @@ -414,7 +414,7 @@ MINIJINJA_API char *mj_value_to_str(struct mj_value value); MINIJINJA_API struct mj_value_iter *mj_value_try_iter(struct mj_value value); #ifdef __cplusplus -} // extern "C" -#endif // __cplusplus +} // extern "C" +#endif // __cplusplus -#endif /* _minijinja_h_included */ +#endif /* _minijinja_h_included */ diff --git a/minijinja-cabi/src/value.rs b/minijinja-cabi/src/value.rs index d5a2a525..3738e931 100644 --- a/minijinja-cabi/src/value.rs +++ b/minijinja-cabi/src/value.rs @@ -39,7 +39,15 @@ where /// Opaque value type. #[repr(C)] pub struct mj_value { - _opaque: [usize; 3], + // Motivation on the size here: The size of `Value` is really not + // known and since cbindgen has no way to guarnatee us a matching + // size we have to be creative. The dominating type size wise is + // most likely going to be SmallStr which is a u8+[u8; 22] plus the + // enum discriminant (u8). + // + // We are going with u64 here for alignment reasons which is likely + // to be a good default across platforms. + _opaque: [u64; 3], } impl mj_value { @@ -51,7 +59,7 @@ impl mj_value { impl From for mj_value { fn from(value: Value) -> Self { mj_value { - _opaque: unsafe { transmute::(value) }, + _opaque: unsafe { transmute::(value) }, } } }