From ea53cfbdc2f03cfa88ffec3623ee7df7745846ab Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 30 Sep 2021 15:26:56 -0500 Subject: [PATCH] Fix bug where deserializing nullpointers as functions failed instead of returning nil --- CHANGELOG.md | 1 + src/clj/coffi/ffi.clj | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 462474b..11068eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This change ## [Unreleased] ### Fixed +- Deserializing nullpointers as functions threw an exception - Upcall stubs with non-primitive arguments failed to compile - Upcall stubs had incorrect types diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index ed93bfc..c6558a0 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -367,13 +367,14 @@ (defmethod mem/deserialize* ::fn [addr [_fn arg-types ret-type & {:keys [raw-fn?]}]] - (-> addr - (downcall-handle - (method-type arg-types ret-type) - (function-descriptor arg-types ret-type)) - (downcall-fn arg-types ret-type) - (cond-> - (not raw-fn?) (make-serde-wrapper arg-types ret-type)))) + (when-not (mem/null? addr) + (-> addr + (downcall-handle + (method-type arg-types ret-type) + (function-descriptor arg-types ret-type)) + (downcall-fn arg-types ret-type) + (cond-> + (not raw-fn?) (make-serde-wrapper arg-types ret-type))))) ;;; Static memory access