Make the default for function serdes be to serde the up/downcall

This commit is contained in:
Joshua Suskalo 2021-09-23 16:23:13 -05:00
parent ee34eb6be0
commit 0cc650103c
2 changed files with 8 additions and 8 deletions

View file

@ -912,24 +912,24 @@
(global-scope)))) (global-scope))))
(defmethod serialize* ::fn (defmethod serialize* ::fn
[f [_fn arg-types ret-type & {:keys [wrap-serde?]}] scope] [f [_fn arg-types ret-type & {:keys [raw-fn?]}] scope]
(.upcallStub (.upcallStub
(CLinker/getInstance) (CLinker/getInstance)
(cond-> f (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)) :always (upcall-handle arg-types ret-type))
(function-descriptor arg-types ret-type) (function-descriptor arg-types ret-type)
scope)) scope))
(defmethod deserialize* ::fn (defmethod deserialize* ::fn
[addr [_fn arg-types ret-type & {:keys [wrap-serde?]}]] [addr [_fn arg-types ret-type & {:keys [raw-fn?]}]]
(-> addr (-> addr
(downcall-handle (downcall-handle
(method-type arg-types ret-type) (method-type arg-types ret-type)
(function-descriptor arg-types ret-type)) (function-descriptor arg-types ret-type))
(downcall-fn arg-types ret-type) (downcall-fn arg-types ret-type)
(cond-> (cond->
wrap-serde? (make-serde-wrapper arg-types ret-type)))) (not raw-fn?) (make-serde-wrapper arg-types ret-type))))
;;; Static memory access ;;; Static memory access
@ -1002,7 +1002,7 @@
(make-downcall (:symbol spec) (make-downcall (:symbol spec)
(:function/args spec) (:function/args spec)
(:function/ret spec)) (:function/ret spec))
(:function/wrap-serde? spec) (not (:function/raw-fn? spec))
(make-serde-wrapper (make-serde-wrapper
(:function/args spec) (:function/args spec)
(:function/ret spec)))) (:function/ret spec))))
@ -1013,7 +1013,7 @@
(make-varargs-factory (:symbol spec) (make-varargs-factory (:symbol spec)
(:function/args spec) (:function/args spec)
(:function/ret spec)) (:function/ret spec))
(:function/wrap-serde? spec) (not (:function/raw-fn? spec))
(make-serde-varargs-wrapper (make-serde-varargs-wrapper
(:function/args spec) (:function/args spec)
(:function/ret spec)))) (:function/ret spec))))

View file

@ -21,10 +21,10 @@
(t/deftest can-call-deserialized-fn-pointers (t/deftest can-call-deserialized-fn-pointers
(t/is (= "Alternate string" (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))))) 1)))))
(t/deftest can-make-upcall (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")) (fn [] "hello"))
"hello"))) "hello")))