From 48942da0990180bd6bab1a8bb81cbf954c3a11e9 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 14 Oct 2021 18:38:10 -0500 Subject: [PATCH 1/5] Update changelog unreleased --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 68a9120..3d30841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # 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.251] - 2021-10-14 ### Fixed - Bug with the inline expansion of `make-serde-wrapper`, make it more maintainable @@ -63,6 +65,7 @@ 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.251...HEAD [0.1.251]: https://github.com/IGJoshua/coffi/compare/v0.1.246...v0.1.251 [0.1.246]: https://github.com/IGJoshua/coffi/compare/v0.1.241...v0.1.246 [0.1.241]: https://github.com/IGJoshua/coffi/compare/v0.1.220...v0.1.241 From 4f0d151c7ac03a1535ae8dfa698a2bca23b94162 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 14 Oct 2021 19:22:30 -0500 Subject: [PATCH 2/5] Fix crash when returning void in an upcall --- CHANGELOG.md | 2 ++ src/clj/coffi/mem.clj | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d30841..225a461 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ 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 +- Void return types on upcalls would crash on serialization ## [0.1.251] - 2021-10-14 ### Fixed diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index 8e87d4a..b003216 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -417,6 +417,10 @@ obj) (MemoryAddress/NULL))) +(defmethod serialize* ::void + [_obj _type _scope] + nil) + (defmulti serialize-into "Writes a serialized version of the `obj` to the given `segment`. From 14d38e3b8ac5d38c86a7dd2ae9ab1c829ed8ce4e Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Fri, 15 Oct 2021 08:31:32 -0500 Subject: [PATCH 3/5] Fix some indentation --- src/clj/coffi/ffi.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index b742575..ee85bb2 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -538,8 +538,7 @@ (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))) + (cond-> (not raw-fn?) (make-serde-wrapper arg-types ret-type))) assoc ::address addr))) ;;; Static memory access From a1ad988aad8983103ba12ae2d73bab07066f27df Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Fri, 15 Oct 2021 22:13:45 -0500 Subject: [PATCH 4/5] Fix incorrect argument loading in upcall stubs --- CHANGELOG.md | 1 + src/clj/coffi/ffi.clj | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 225a461..3219399 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 +- Long and double arguments to upcalls failed to compile in some cases - Void return types on upcalls would crash on serialization ## [0.1.251] - 2021-10-14 diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index ee85bb2..4693e0b 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -459,6 +459,10 @@ ::mem/double :dreturn ::mem/void :return}) +(def ^:private double-sized? + "Set of primitive types which require 2 indices in the constant pool." + #{::mem/double ::mem/long ::mem/long-long}) + (defn- upcall-class "Constructs a class definition for a class with a single method, `upcall`, which boxes any primitives passed to it and calls a closed over [[IFn]]." @@ -482,11 +486,18 @@ (insn-layout ret-type)) :emit [[:aload 0] [:getfield :this "upcall_ifn" IFn] - (map-indexed - (fn [idx arg] - [[(load-instructions (mem/primitive-type arg) :aload) (inc idx)] - (to-object-asm arg)]) - arg-types) + (loop [types arg-types + acc [] + idx 1] + (if (seq types) + (let [prim (mem/primitive-type (first types))] + (recur (rest types) + (conj acc [[(load-instructions prim) idx] + (to-object-asm (first types))]) + (cond-> (inc idx) + (double-sized? prim) + inc))) + acc)) [:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)] (to-prim-asm ret-type) [(return-for-type ret-type :areturn)]]}]}) From ee5805ca4bd4d0a3205bbf02121bee6b15ba5797 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Sat, 16 Oct 2021 09:39:19 -0500 Subject: [PATCH 5/5] Version bump to 0.2 --- build.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.clj b/build.clj index 12135a5..039f034 100644 --- a/build.clj +++ b/build.clj @@ -17,7 +17,7 @@ [clojure.tools.build.api :as b])) (def lib-coord 'org.suskalo/coffi) -(def version (format "0.1.%s" (b/git-count-revs nil))) +(def version (format "0.2.%s" (b/git-count-revs nil))) (def resource-dirs ["resources/"])