From 85d52f64b7980839602a5de7de81eeb54a087761 Mon Sep 17 00:00:00 2001 From: Kristin Rutenkolk Date: Wed, 26 Jun 2024 13:22:47 +0200 Subject: [PATCH] fix upcalls with strings --- deps.edn | 2 +- src/clj/coffi/ffi.clj | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/deps.edn b/deps.edn index d0e1469..a6c2599 100644 --- a/deps.edn +++ b/deps.edn @@ -1,6 +1,6 @@ {:paths ["src/clj" "target/classes" "resources"] :deps {org.clojure/clojure {:mvn/version "1.11.1"} - insn/insn {:mvn/version "0.2.1"}} + insn/insn {:mvn/version "0.5.4"}} :deps/prep-lib {:alias :build :fn build/compile-java diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index bff4e99..730908d 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -135,6 +135,7 @@ method handle without reflection, unboxing primitives when needed." [args ret] {:flags #{:public :final} + :version 8 :super clojure.lang.AFunction :fields [{:name "downcall_handle" :type MethodHandle @@ -466,6 +467,7 @@ boxes any primitives passed to it and calls a closed over [[IFn]]." [arg-types ret-type] {:flags #{:public :final} + :version 8 :fields [{:name "upcall_ifn" :type IFn :flags #{:final}}] @@ -497,6 +499,10 @@ inc))) acc)) [:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)] + (if (identical? ::mem/pointer (mem/primitive-type ret-type)) + [[:checkcast Long] + [:invokevirtual Long "longValue" [:long]] + [:invokestatic MemorySegment "ofAddress" [:long MemorySegment] true]]) (to-prim-asm ret-type) [(return-for-type ret-type :areturn)]]}]}) @@ -538,7 +544,6 @@ (defmethod mem/serialize* ::fn [f [_fn arg-types ret-type & {:keys [raw-fn?]}] arena] - (println "Attempting to serialize function of type" (str ret-type "(*)(" (clojure.string/join "," arg-types) ")")) (.upcallStub (Linker/nativeLinker) ^MethodHandle (cond-> f