Merge branch 'release'
This commit is contained in:
commit
d039b980ad
4 changed files with 34 additions and 19 deletions
|
|
@ -1,6 +1,13 @@
|
|||
# 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/).
|
||||
|
||||
## [0.1.192] - 2021-09-30
|
||||
### 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
|
||||
|
|
@ -21,6 +28,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
|
||||
|
||||
[0.1.192]: https://github.com/IGJoshua/coffi/compare/v0.1.184...v0.1.192
|
||||
[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
|
||||
|
|
|
|||
|
|
@ -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.184"}
|
||||
io.github.IGJoshua/coffi {:git/tag "v0.1.184" :git/sha "ea53cfb"}
|
||||
org.suskalo/coffi {:mvn/version "0.1.192"}
|
||||
io.github.IGJoshua/coffi {:git/tag "v0.1.192" :git/sha "9d65f47"}
|
||||
```
|
||||
|
||||
If you use this library as a git dependency, you will need to prepare the
|
||||
|
|
|
|||
|
|
@ -368,13 +368,15 @@
|
|||
(defmethod mem/deserialize* ::fn
|
||||
[addr [_fn arg-types ret-type & {:keys [raw-fn?]}]]
|
||||
(when-not (mem/null? addr)
|
||||
(vary-meta
|
||||
(-> 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)))))
|
||||
(not raw-fn?) (make-serde-wrapper arg-types ret-type)))
|
||||
assoc ::address addr)))
|
||||
|
||||
;;; Static memory access
|
||||
|
||||
|
|
@ -543,6 +545,7 @@
|
|||
(let [args (s/conform ::defcfn-args args)
|
||||
args-types (gensym "args-types")
|
||||
ret-type (gensym "ret-type")
|
||||
address (gensym "symbol")
|
||||
invoke (gensym "invoke")
|
||||
native-sym (gensym "native")
|
||||
[arity fn-tail] (-> args :wrapper :fn-tail)
|
||||
|
|
@ -556,7 +559,8 @@
|
|||
nil))]
|
||||
`(let [~args-types ~(:native-arglist args)
|
||||
~ret-type ~(:return-type args)
|
||||
~invoke (make-downcall ~(name (:symbol args)) ~args-types ~ret-type)
|
||||
~address (find-symbol ~(name (:symbol args)))
|
||||
~invoke (make-downcall ~address ~args-types ~ret-type)
|
||||
~(or (-> args :wrapper :native-fn) native-sym)
|
||||
~(if (and (every? #(= % (mem/primitive-type %))
|
||||
(:native-arglist args))
|
||||
|
|
@ -579,7 +583,8 @@
|
|||
(list
|
||||
(mapv (comp symbol name)
|
||||
(:native-arglist args)))))))
|
||||
(:attr-map args)))
|
||||
(assoc (:attr-map args)
|
||||
::address address)))
|
||||
~@(when-let [doc (:doc args)]
|
||||
(list doc))
|
||||
fun#))))
|
||||
|
|
|
|||
|
|
@ -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?)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue