From 3043bf787706162cf273a8dee5d80dbaeb4c445c Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 30 Sep 2021 15:25:21 -0500 Subject: [PATCH 1/4] Fix upcall stubs having incorrect type descriptors --- CHANGELOG.md | 5 +++++ src/clj/coffi/ffi.clj | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0df9aaa..b7dab6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). +## [Unreleased] +### Fixed +- Upcall stubs had incorrect types + ## [0.1.176] - 2021-09-29 ### Fixed - Usage of `defcfn` without a docstring produced an invalid `def` form @@ -15,5 +19,6 @@ All notable changes to this project will be documented in this file. This change - Support for serializing and deserializing arbitrary Clojure functions - Support for serializing and deserializing arbitrary Clojure data structures +[Unreleased]: https://github.com/IGJoshua/coffi/compare/v0.1.176...HEAD [0.1.176]: https://github.com/IGJoshua/coffi/compare/v0.1.169...v0.1.176 [0.1.169]: https://github.com/IGJoshua/coffi/compare/16f56bc31d69142ec4d2fb61b15b069d78b127ca...v0.1.169 diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index 4c966e6..ec04dce 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -314,8 +314,8 @@ [:return]]} {:name :upcall :flags #{:public} - :desc (conj (mapv mem/java-layout arg-types) - (mem/java-layout ret-type)) + :desc (conj (mapv insn-layout arg-types) + (insn-layout ret-type)) :emit [[:aload 0] [:getfield :this "upcall_ifn" IFn] (map-indexed From 50cc6f3bdc2bce77417f3608d96d84b40206061d Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 30 Sep 2021 15:25:58 -0500 Subject: [PATCH 2/4] Fix upcall stubs not compiling with non-primitive argument types --- CHANGELOG.md | 1 + src/clj/coffi/ffi.clj | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7dab6e..462474b 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 +- Upcall stubs with non-primitive arguments failed to compile - Upcall stubs had incorrect types ## [0.1.176] - 2021-09-29 diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index ec04dce..ed93bfc 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -320,7 +320,7 @@ [:getfield :this "upcall_ifn" IFn] (map-indexed (fn [idx arg] - [[(load-instructions arg) (inc idx)] + [[(load-instructions arg :aload) (inc idx)] (to-object-asm arg)]) arg-types) [:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)] From ea53cfbdc2f03cfa88ffec3623ee7df7745846ab Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 30 Sep 2021 15:26:56 -0500 Subject: [PATCH 3/4] 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 From c4a97949fa6c01b6d6c78425d5bc59c7b6a0977b Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 30 Sep 2021 15:31:14 -0500 Subject: [PATCH 4/4] Update readme and changelog for release --- CHANGELOG.md | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11068eb..2c56c22 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Change Log All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). -## [Unreleased] +## [0.1.184] - 2021-09-30 ### Fixed - Deserializing nullpointers as functions threw an exception - Upcall stubs with non-primitive arguments failed to compile @@ -21,6 +21,6 @@ All notable changes to this project will be documented in this file. This change - Support for serializing and deserializing arbitrary Clojure functions - Support for serializing and deserializing arbitrary Clojure data structures -[Unreleased]: https://github.com/IGJoshua/coffi/compare/v0.1.176...HEAD +[0.1.184]: https://github.com/IGJoshua/coffi/compare/v0.1.176...v0.1.184 [0.1.176]: https://github.com/IGJoshua/coffi/compare/v0.1.169...v0.1.176 [0.1.169]: https://github.com/IGJoshua/coffi/compare/16f56bc31d69142ec4d2fb61b15b069d78b127ca...v0.1.169 diff --git a/README.md b/README.md index a900d1b..5bcbb00 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ This library is available on Clojars. Add one of the following entries to the `:deps` key of your `deps.edn`: ```clojure -org.suskalo/coffi {:mvn/version "0.1.176"} -io.github.IGJoshua/coffi {:git/tag "v0.1.176" :git/sha "2a90bdb"} +org.suskalo/coffi {:mvn/version "0.1.184"} +io.github.IGJoshua/coffi {:git/tag "v0.1.184" :git/sha "ea53cfb"} ``` If you use this library as a git dependency, you will need to prepare the