-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retrieve the actual alignment of
max_align_t
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`.
- Loading branch information
Showing
3 changed files
with
92 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <stddef.h> | ||
|
||
// Note that this symbol is NOT linked with the rest of the library. | ||
// The name is sort of unique in case it accidentally gets linked. | ||
const size_t rust_secp256k1_private_max_align = _Alignof(max_align_t); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters