From 0cc650103c4e137c9c7d27dc152a91865c45a504 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 23 Sep 2021 16:23:13 -0500 Subject: [PATCH] Make the default for function serdes be to serde the up/downcall --- src/clj/coffi/ffi.clj | 12 ++++++------ test/clj/coffi/ffi_test.clj | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index 0d3b2ff..33b068a 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -912,24 +912,24 @@ (global-scope)))) (defmethod serialize* ::fn - [f [_fn arg-types ret-type & {:keys [wrap-serde?]}] scope] + [f [_fn arg-types ret-type & {:keys [raw-fn?]}] scope] (.upcallStub (CLinker/getInstance) (cond-> f - wrap-serde? (upcall-serde-wrapper arg-types ret-type) + (not raw-fn?) (upcall-serde-wrapper arg-types ret-type) :always (upcall-handle arg-types ret-type)) (function-descriptor arg-types ret-type) scope)) (defmethod deserialize* ::fn - [addr [_fn arg-types ret-type & {:keys [wrap-serde?]}]] + [addr [_fn arg-types ret-type & {:keys [raw-fn?]}]] (-> addr (downcall-handle (method-type arg-types ret-type) (function-descriptor arg-types ret-type)) (downcall-fn arg-types ret-type) (cond-> - wrap-serde? (make-serde-wrapper arg-types ret-type)))) + (not raw-fn?) (make-serde-wrapper arg-types ret-type)))) ;;; Static memory access @@ -1002,7 +1002,7 @@ (make-downcall (:symbol spec) (:function/args spec) (:function/ret spec)) - (:function/wrap-serde? spec) + (not (:function/raw-fn? spec)) (make-serde-wrapper (:function/args spec) (:function/ret spec)))) @@ -1013,7 +1013,7 @@ (make-varargs-factory (:symbol spec) (:function/args spec) (:function/ret spec)) - (:function/wrap-serde? spec) + (not (:function/raw-fn? spec)) (make-serde-varargs-wrapper (:function/args spec) (:function/ret spec)))) diff --git a/test/clj/coffi/ffi_test.clj b/test/clj/coffi/ffi_test.clj index a77ddcf..f0041d4 100644 --- a/test/clj/coffi/ffi_test.clj +++ b/test/clj/coffi/ffi_test.clj @@ -21,10 +21,10 @@ (t/deftest can-call-deserialized-fn-pointers (t/is (= "Alternate string" - (((sut/cfn "get_downcall" [::sut/int] [::sut/fn [] ::sut/c-string :wrap-serde? true]) + (((sut/cfn "get_downcall" [::sut/int] [::sut/fn [] ::sut/c-string]) 1))))) (t/deftest can-make-upcall - (t/is (= ((sut/cfn "upcall_test" [[::sut/fn [] ::sut/c-string :wrap-serde? true]] ::sut/c-string) + (t/is (= ((sut/cfn "upcall_test" [[::sut/fn [] ::sut/c-string]] ::sut/c-string) (fn [] "hello")) "hello")))