From 036d4112fbaae1f8f0837310e583760584f55e88 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Mon, 31 Oct 2022 13:38:07 -0500 Subject: [PATCH] Fix nullpointer serialization in simpler inline cases --- CHANGELOG.md | 1 + src/clj/coffi/ffi.clj | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e706cb0..d91551b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index b95119b..d704993 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -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)