Remove reference to method that isn't in panama anymore

This commit is contained in:
Joshua Suskalo 2021-09-30 19:54:48 -05:00
parent daa1949f32
commit 9d65f47a96
2 changed files with 13 additions and 8 deletions

View file

@ -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

View file

@ -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?)))