From 301f6c15345a9415714fa138cbe38e8e9b91ae6c Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 14 Oct 2021 12:44:20 -0500 Subject: [PATCH 1/2] Add unreleased section to the changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02c4bdb..27fa126 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.241] - 2021-10-14 ### Performance - Added an `:inline` function to `make-serde-wrapper` to remove serialization overhead on primitives @@ -55,6 +57,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.241...HEAD [0.1.241]: https://github.com/IGJoshua/coffi/compare/v0.1.220...v0.1.241 [0.1.220]: https://github.com/IGJoshua/coffi/compare/v0.1.205...v0.1.220 [0.1.205]: https://github.com/IGJoshua/coffi/compare/v0.1.192...v0.1.205 From 9cc83e7d1ad674333a33b0dd80e51271f842e3a8 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 14 Oct 2021 13:05:51 -0500 Subject: [PATCH 2/2] Fix bug with inline expansion with no arguments --- CHANGELOG.md | 2 ++ src/clj/coffi/ffi.clj | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27fa126..d111ad0 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 +- Incorrect inline expansion of `make-serde-wrapper` in cases where a function has no arguments ## [0.1.241] - 2021-10-14 ### Performance diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index ebb8094..f052c7b 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -305,10 +305,12 @@ nil)) (list sym `(mem/serialize ~sym ~type ~scope)))) arg-syms arg-types) + wrap-scope (fn [expr] + `(with-open [~scope (mem/stack-scope)] + ~expr)) wrap-serialize (fn [expr] - `(with-open [~scope (mem/stack-scope)] - (let [~@(mapcat identity serialize-args)] - ~expr))) + `(let [~@(mapcat identity serialize-args)] + ~expr)) native-fn (fn [expr] `(fn ~'native-fn [~@arg-syms] ~expr)) @@ -321,6 +323,7 @@ primitive-ret? (-> (cons downcall-sym arg-syms) wrap-serialize + wrap-scope native-fn) :else @@ -336,12 +339,12 @@ const-ret?) (native-fn (if (mem/primitive-type ret-type) prim-call - non-prim-call)) + (wrap-scope non-prim-call))) none-to-serialize? - (if (mem/primitive-type ~ret) - ~(native-fn prim-call) - ~(native-fn non-prim-call)) + `(if (mem/primitive-type ~ret) + ~(native-fn prim-call) + ~(native-fn (wrap-scope non-prim-call))) const-ret? (native-fn (wrap-serialize