diff --git a/src/coffi/ffi.clj b/src/coffi/ffi.clj index 36d1eb1..1a79d08 100644 --- a/src/coffi/ffi.clj +++ b/src/coffi/ffi.clj @@ -715,6 +715,31 @@ (let [args (concat required-args types)] (make-downcall symbol args ret))))) +(defn make-serde-wrapper + "Constructs a wrapper function for the `downcall` which serializes the arguments + and deserializes the return value." + [downcall arg-types ret-type] + (fn native-fn [& args] + (with-open [scope (stack-scope)] + (deserialize (apply downcall (map #(serialize %1 %2 scope) args arg-types)) + ret-type)))) +(s/fdef make-serde-wrapper + :args (s/cat :downcall ifn? + :arg-types (s/coll-of ::type :kind vector?) + :ret-type ::type)) + +(defn make-serde-varargs-wrapper + "Constructs a wrapper function for the `varargs-factory` which produces + functions that serialize the arguments and deserialize the return value." + [varargs-factory required-args ret-type] + (memoize + (fn [& types] + (let [args-types (concat required-args types)] + (make-serde-wrapper + (apply varargs-factory types) + args-types + ret-type))))) + (s/def :coffi.ffi.symbolspec/symbol string?) (s/def :coffi.ffi.symbolspec/type keyword?) (s/def ::symbolspec @@ -773,19 +798,6 @@ :complex-type (s/cat :base-type qualified-keyword? :type-args (s/* any?))))) -(defn make-serde-wrapper - "Constructs a wrapper function for the `downcall` which serializes the arguments - and deserializes the return value." - [downcall arg-types ret-type] - (fn native-fn [& args] - (with-open [scope (stack-scope)] - (deserialize (apply downcall (map #(serialize %1 %2 scope) args arg-types)) - ret-type)))) -(s/fdef make-serde-wrapper - :args (s/cat :downcall ifn? - :arg-types (s/coll-of ::type :kind vector?) - :ret-type ::type)) - (s/def ::defcfn-args (s/and (s/cat :name simple-symbol?