From 9d65f47a96efbb80a54b1799e00ff4864d5ace6d Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 30 Sep 2021 19:54:48 -0500 Subject: [PATCH] Remove reference to method that isn't in panama anymore --- CHANGELOG.md | 3 +++ src/clj/coffi/mem.clj | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 007bd61..28e0bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. This change ### Added - An `::ffi/address` key to wrapper functions' metadata +### Fixed +- Usage of a method no longer in Panama that breaks `with-acquired` + ## [0.1.184] - 2021-09-30 ### Fixed - Deserializing nullpointers as functions threw an exception diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index 5f284c2..69118f6 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -29,6 +29,7 @@ MemoryLayout MemorySegment ResourceScope + ResourceScope$Handle SegmentAllocator))) (defn stack-scope @@ -96,11 +97,6 @@ ([allocator size alignment] (.allocate ^SegmentAllocator allocator (long size) (long alignment)))) -(defn keep-alive - "Ensures that the scope `target` is not released before `source`." - [source target] - (.keepAlive ^ResourceScope source ^ResourceScope target)) - (defmacro with-acquired "Acquires one or more `scopes` until the `body` completes. @@ -109,9 +105,15 @@ with it wrapped in this." {:style/indent 1} [scopes & body] - `(with-open [scope# (stack-scope)] - (run! (partial keep-alive scope#) ~scopes) - ~@body)) + `(let [scopes# (vec ~scopes) + handles# (mapv #(.acquire ^ResourceScope %) scopes#)] + (try ~@body + (finally + (doseq [idx# (range (count scopes#)) + :let [scope# (nth scopes# idx#) + handle# (nth handles# idx#)]] + (.release ^ResourceScope scope# + ^ResourceScope$Handle handle#)))))) (s/fdef with-acquired :args (s/cat :scopes any? :body (s/* any?)))