Fix nullpointer serialization in simpler inline cases

This commit is contained in:
Joshua Suskalo 2022-10-31 13:38:07 -05:00
parent fa40902ce9
commit 036d4112fb
No known key found for this signature in database
GPG key ID: 9B6BA586EFF1B9F0
2 changed files with 3 additions and 4 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 nil values would not be correctly coerced to null pointers when passed to inlined functions
- Bug where inline serde functions would fail on complex pointer types
- Bug where padding in structs may be increased when fields have alignments less than their size
- Bug where pointer alignment was incorrectly defined

View file

@ -247,9 +247,6 @@
[downcall arg-types ret-type]
(let [;; Complexity of types
const-args? (or (vector? arg-types) (nil? arg-types))
;; FIXME(Joshua): there's a potential bug where `nil` as a pointer
;; argument is not converted to [[MemoryAddress/NULL]] if it's
;; considered primitive.
simple-args? (when const-args?
(and (every? mem/primitive? arg-types)
;; NOTE(Joshua): Pointer types with serdes (e.g. [::mem/pointer ::mem/int])
@ -300,8 +297,9 @@
(not (#{::mem/pointer} (mem/primitive-type type))))
(list (primitive-cast-sym (mem/primitive-type type)) sym)
;; cast null pointers to something understood by panama
(#{::mem/pointer} type)
nil
`(or ~sym (MemoryAddress/NULL))
(mem/primitive-type type)
`(mem/serialize* ~sym ~type-sym ~scope)