You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code had a hard-coded maximum alignment of 16 (128 bits) which may
have potentially wasted memory and cause memory unsafety if it was ever
compiled with larger alignment (unlikely).
This change implements a trick to retrieve the actual alignment from C.
To achieve this a newly added C file defines a symbol initialized to
`_Alignof(max_align_t)`. It is then compiled (as a separate object), the
contents of the symbol is extracted and converted to decimal string
which is injected into the `AlignedType` definition. The definition is
generated as a separate `.rs` file in `OUT_DIR` and included into
`types.rs`.
Copy file name to clipboardexpand all lines: secp256k1-sys/src/types.rs
+3-9
Original file line number
Diff line number
Diff line change
@@ -11,21 +11,15 @@ pub type c_char = i8;
11
11
12
12
pubuse core::ffi::c_void;
13
13
14
-
/// A type that is as aligned as the biggest alignment for fundamental types in C
15
-
/// since C11 that means as aligned as `max_align_t` is.
16
-
/// the exact size/alignment is unspecified.
17
-
// 16 matches is as big as the biggest alignment in any arch that rust currently supports https://github.com/rust-lang/rust/blob/2c31b45ae878b821975c4ebd94cc1e49f6073fd0/library/std/src/sys_common/alloc.rs
0 commit comments