Fix incorrect padding in C-layout structs

This commit is contained in:
Joshua Suskalo 2022-10-31 11:36:38 -05:00
parent 990e76c624
commit 319bb3a33b
No known key found for this signature in database
GPG key ID: 9B6BA586EFF1B9F0
2 changed files with 5 additions and 3 deletions

View file

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. This change
- New function to allow getting the backing memory segment of a `coffi.ffi.StaticVariable`, to replace the `Addressable` implementation lost in the migration to JDK 18
### Fixed
- Bug where padding in structs may be increased when fields have alignments less than their size
- Bug where pointer alignment was incorrectly defined
## [0.5.357] - 2022-07-07

View file

@ -16,11 +16,12 @@
(if (seq fields)
(let [[[_ type :as field] & fields] fields
size (mem/size-of type)
r (rem offset (mem/align-of type))]
align (mem/align-of type)
r (rem offset align)]
(recur (cond-> (+ offset size)
(pos? r) (+ (- size r)))
(pos? r) (+ (- align r)))
(cond-> aligned-fields
(pos? r) (conj [::padding [::mem/padding (- size r)]])
(pos? r) (conj [::padding [::mem/padding (- align r)]])
:always (conj field))
fields))
(let [strongest-alignment (mem/align-of struct-spec)