From 8792d48ad7662a9fb83f80dcd0f2edfef019464a Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 2 Oct 2024 15:43:23 -0400 Subject: [PATCH 01/16] Update changelog link to diff --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 985b21c..e50cfa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -133,7 +133,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 -[Unreleased]: https://github.com/IGJoshua/coffi/compare/v0.6.409...develop +[1.0.450]: https://github.com/IGJoshua/coffi/compare/v0.6.409...v1.0.450 [0.6.409]: https://github.com/IGJoshua/coffi/compare/v0.5.357...v0.6.409 [0.5.357]: https://github.com/IGJoshua/coffi/compare/v0.4.341...v0.5.357 [0.4.341]: https://github.com/IGJoshua/coffi/compare/v0.3.298...v0.4.341 From 26a6877c39544504979edb4ef17418ada63b0e86 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 2 Oct 2024 15:44:42 -0400 Subject: [PATCH 02/16] Fix use of replace-deps in codox generation --- deps.edn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps.edn b/deps.edn index cc8687e..9f6884e 100644 --- a/deps.edn +++ b/deps.edn @@ -21,8 +21,8 @@ :jvm-opts ["--enable-native-access=ALL-UNNAMED"] :exec-fn cognitect.test-runner.api/test} - :codox {:extra-deps {codox/codox {:mvn/version "0.10.8"}} - :replace-deps {insn/insn {:mvn/version "0.2.1"}} + :codox {:extra-deps {codox/codox {:mvn/version "0.10.8"} + insn/insn {:mvn/version "0.2.1"}} :exec-fn codox.main/generate-docs :exec-args {:name "coffi" :version "v1.0.450" From ba11f5892efcd70c901cb934068d36f11c621fe2 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 2 Oct 2024 15:45:13 -0400 Subject: [PATCH 03/16] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e50cfa6..c34a0af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # 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/). +## [UNRELEASED] + ## [1.0.450] - 2024-10-02 ### Added - Support for JDK 22 @@ -133,6 +135,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 +[UNRELEASED]: https://github.com/IGJoshua/coffi/compare/v1.0.450...develop [1.0.450]: https://github.com/IGJoshua/coffi/compare/v0.6.409...v1.0.450 [0.6.409]: https://github.com/IGJoshua/coffi/compare/v0.5.357...v0.6.409 [0.5.357]: https://github.com/IGJoshua/coffi/compare/v0.4.341...v0.5.357 From 5c644d054f6901d72c343630a902ba9a906e0fea Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 2 Oct 2024 15:47:21 -0400 Subject: [PATCH 04/16] Add known issue about generating docs --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fa0b2aa..2d1836c 100644 --- a/README.md +++ b/README.md @@ -1126,7 +1126,10 @@ stands, coffi is the fastest FFI available to Clojure developers. The project author is aware of these issues and plans to fix them in a future release: -No known issues, hooray! +- When generating docs with codox in a library that depends on coffi, the below error will be produced. A temporary workaround is to add an explicit dependency in your codox build on insn at version 0.2.1 +``` clojure +Unable to find static field: ACC_OPEN in interface org.objectweb.asm.Opcodes +``` ## Future Plans These features are planned for future releases. From fd8d649f63adfd8f41b8dddce0872b689a549399 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 2 Oct 2024 16:16:09 -0400 Subject: [PATCH 05/16] Fix bad usage of static fields as calls --- CHANGELOG.md | 2 ++ src/clj/coffi/ffi.clj | 2 +- src/clj/coffi/mem.clj | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c34a0af..0732987 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). ## [UNRELEASED] +### Fixed +- Usage of deprecated `(Class/STATIC_FIELD)` access pattern ## [1.0.450] - 2024-10-02 ### Added diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index d3d770b..9263c45 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -292,7 +292,7 @@ ;; cast null pointers to something understood by panama (#{::mem/pointer} type) - `(or ~sym (MemorySegment/NULL)) + `(or ~sym MemorySegment/NULL) (mem/primitive-type type) `(mem/serialize* ~sym ~type-sym ~arena) diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index ec5e665..fcf3ecb 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -115,7 +115,7 @@ (defn null? "Checks if a memory address is null." [addr] - (or (.equals (MemorySegment/NULL) addr) (not addr))) + (or (.equals MemorySegment/NULL addr) (not addr))) (defn address? "Checks if an object is a memory address. @@ -872,7 +872,7 @@ (serialize-into obj (second type) segment arena) (address-of segment)) obj) - (MemorySegment/NULL))) + MemorySegment/NULL)) (defmethod serialize* ::void [_obj _type _arena] @@ -1132,7 +1132,7 @@ [obj _type ^Arena arena] (if obj (.allocateFrom arena ^String obj) - (MemorySegment/NULL))) + MemorySegment/NULL)) (defmethod deserialize* ::c-string [addr _type] From bd7216a06e6698a8583407d9b29ce0d6fe4ac9cc Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Wed, 2 Oct 2024 16:22:29 -0400 Subject: [PATCH 06/16] Add `null` for implementing serdes --- CHANGELOG.md | 3 +++ src/clj/coffi/ffi.clj | 2 +- src/clj/coffi/mem.clj | 14 +++++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0732987..0a2accb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes to this project will be documented in this file. This change log follows the conventions of [keepachangelog.com](http://keepachangelog.com/). ## [UNRELEASED] +### Added +- New `coffi.mem/null` var for implementing custom types + ### Fixed - Usage of deprecated `(Class/STATIC_FIELD)` access pattern diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index 9263c45..1ec9a4b 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -292,7 +292,7 @@ ;; cast null pointers to something understood by panama (#{::mem/pointer} type) - `(or ~sym MemorySegment/NULL) + `(or ~sym mem/null) (mem/primitive-type type) `(mem/serialize* ~sym ~type-sym ~arena) diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index fcf3ecb..99bd00e 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -112,10 +112,18 @@ ^long [addressable] (.address ^MemorySegment addressable)) +(def ^MemorySegment null + "The NULL pointer object. + + While this object is safe to pass to functions which serialize to a pointer, + it's generally encouraged to simply pass `nil`. This value primarily exists to + make it easier to write custom types with a primitive pointer representation." + MemorySegment/NULL) + (defn null? "Checks if a memory address is null." [addr] - (or (.equals MemorySegment/NULL addr) (not addr))) + (or (.equals null addr) (not addr))) (defn address? "Checks if an object is a memory address. @@ -872,7 +880,7 @@ (serialize-into obj (second type) segment arena) (address-of segment)) obj) - MemorySegment/NULL)) + null)) (defmethod serialize* ::void [_obj _type _arena] @@ -1132,7 +1140,7 @@ [obj _type ^Arena arena] (if obj (.allocateFrom arena ^String obj) - MemorySegment/NULL)) + null)) (defmethod deserialize* ::c-string [addr _type] From cce6c823f6805fb2377edf3f0a36a96c0509057d Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 10:55:54 -0400 Subject: [PATCH 07/16] Implement memoization of upcall and downcall classes --- CHANGELOG.md | 3 + src/clj/coffi/ffi.clj | 198 +++++++++++++++++++++++++----------------- 2 files changed, 120 insertions(+), 81 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a2accb..566381f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. This change ### Added - New `coffi.mem/null` var for implementing custom types +### Performance +- Upcall and downcall classes have been changed to be memoized, meaning ASM is no longer invoked every time a function is serialized, which should drastically improve performance where functions are serialized in a hot loop + ### Fixed - Usage of deprecated `(Class/STATIC_FIELD)` access pattern diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index 1ec9a4b..bcac52b 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -130,53 +130,70 @@ [:invokevirtual (prim-classes prim-type) (unbox-fn-for-type prim-type) [prim]]] [])))) -(defn- downcall-class - "Class definition for an implementation of [[IFn]] which calls a closed over +(defn- downcall-class-ctor* + "Returns a function to construct a downcall class for the given `args` and `ret` types. + + A downcall class is an implementation of [[IFn]] which calls a closed over 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 - :flags #{:final}}] - :methods [{:name :init - :flags #{:public} - :desc [MethodHandle :void] - :emit [[:aload 0] - [:dup] - [:invokespecial :super :init [:void]] - [:aload 1] - [:putfield :this "downcall_handle" MethodHandle] - [:return]]} - {:name :invoke - :flags #{:public} - :desc (repeat (cond-> (inc (count args)) - (not (mem/primitive-type ret)) inc) - Object) - :emit [[:aload 0] - [:getfield :this "downcall_handle" MethodHandle] - (when-not (mem/primitive-type ret) - [[:aload 1] - [:checkcast SegmentAllocator]]) - (map-indexed - (fn [idx arg] - [[:aload (cond-> (inc idx) - (not (mem/primitive-type ret)) inc)] - (to-prim-asm arg)]) - args) - [:invokevirtual MethodHandle "invokeExact" - (cond->> - (conj (mapv insn-layout args) - (insn-layout ret)) - (not (mem/primitive-type ret)) (cons SegmentAllocator))] - (to-object-asm ret) - [:areturn]]}]}) + (let [klass (insn/define + {:flags #{:public :final} + :version 8 + :super clojure.lang.AFunction + :fields [{:name "downcall_handle" + :type MethodHandle + :flags #{:final}}] + :methods [{:name :init + :flags #{:public} + :desc [MethodHandle :void] + :emit [[:aload 0] + [:dup] + [:invokespecial :super :init [:void]] + [:aload 1] + [:putfield :this "downcall_handle" MethodHandle] + [:return]]} + {:name :invoke + :flags #{:public} + :desc (repeat (cond-> (inc (count args)) + (not (mem/primitive-type ret)) inc) + Object) + :emit [[:aload 0] + [:getfield :this "downcall_handle" MethodHandle] + (when-not (mem/primitive-type ret) + [[:aload 1] + [:checkcast SegmentAllocator]]) + (map-indexed + (fn [idx arg] + [[:aload (cond-> (inc idx) + (not (mem/primitive-type ret)) inc)] + (to-prim-asm arg)]) + args) + [:invokevirtual MethodHandle "invokeExact" + (cond->> + (conj (mapv insn-layout args) + (insn-layout ret)) + (not (mem/primitive-type ret)) (cons SegmentAllocator))] + (to-object-asm ret) + [:areturn]]}]}) + ctor (.getConstructor klass + (doto ^"[Ljava.lang.Class;" (make-array Class 1) + (aset 0 MethodHandle)))] + (fn [^MethodHandle h] + (.newInstance ctor + (doto (object-array 1) + (aset 0 h)))))) + +(def ^:private downcall-class-ctor + "Returns a function to construct a downcall class for the given memoized `args` and `ret` types. + + A downcall class is an implementation of [[IFn]] which calls a closed over + method handle without reflection, unboxing primitives when needed." + (memoize downcall-class-ctor*)) (defn- downcall-fn "Creates a function to call `handle` without reflection." [handle args ret] - (insn/new-instance (downcall-class args ret) ^MethodHandle handle)) + ((downcall-class-ctor args ret) ^MethodHandle handle)) (defn ensure-symbol "Returns the argument if it is a [[MemorySegment]], otherwise @@ -462,50 +479,69 @@ "Set of primitive types which require 2 indices in the constant pool." #{::mem/double ::mem/long}) -(defn- upcall-class - "Constructs a class definition for a class with a single method, `upcall`, which - boxes any primitives passed to it and calls a closed over [[IFn]]." +(defn- upcall-class-ctor* + "Returns a function to construct an upcall class for the given `arg-types` and `ret-types`. + + An upcall class is a class with a single method, `upcall`, which 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}}] - :methods [{:name :init - :flags #{:public} - :desc [IFn :void] - :emit [[:aload 0] - [:dup] - [:invokespecial :super :init [:void]] - [:aload 1] - [:putfield :this "upcall_ifn" IFn] - [:return]]} - {:name :upcall - :flags #{:public} - :desc (conj (mapv insn-layout arg-types) - (insn-layout ret-type)) - :emit [[:aload 0] - [:getfield :this "upcall_ifn" IFn] - (loop [types arg-types - acc [] - idx 1] - (if (seq types) - (let [prim (mem/primitive-type (first types))] - (recur (rest types) - (conj acc [[(load-instructions prim :aload) idx] - (to-object-asm (first types))]) - (cond-> (inc idx) - (double-sized? prim) - inc))) - acc)) - [:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)] - (to-prim-asm ret-type) - [(return-for-type ret-type :areturn)]]}]}) + (let [klass (insn/define + {:flags #{:public :final} + :version 8 + :fields [{:name "upcall_ifn" + :type IFn + :flags #{:final}}] + :methods [{:name :init + :flags #{:public} + :desc [IFn :void] + :emit [[:aload 0] + [:dup] + [:invokespecial :super :init [:void]] + [:aload 1] + [:putfield :this "upcall_ifn" IFn] + [:return]]} + {:name :upcall + :flags #{:public} + :desc (conj (mapv insn-layout arg-types) + (insn-layout ret-type)) + :emit [[:aload 0] + [:getfield :this "upcall_ifn" IFn] + (loop [types arg-types + acc [] + idx 1] + (if (seq types) + (let [prim (mem/primitive-type (first types))] + (recur (rest types) + (conj acc [[(load-instructions prim :aload) idx] + (to-object-asm (first types))]) + (cond-> (inc idx) + (double-sized? prim) + inc))) + acc)) + [:invokeinterface IFn "invoke" (repeat (inc (count arg-types)) Object)] + (to-prim-asm ret-type) + [(return-for-type ret-type :areturn)]]}]}) + ctor (.getConstructor klass + (doto ^"[Ljava.lang.Class;" (make-array Class 1) + (aset 0 IFn)))] + (fn [^IFn f] + (.newInstance ctor + (doto (object-array 1) + (aset 0 f)))))) + +(def ^:private upcall-class-ctor + "Returns a function to construct an upcall class for the given memoized `arg-types` and `ret-types`. + + An upcall class is a class with a single method, `upcall`, which boxes any + primitives passed to it and calls a closed over [[IFn]]." + (memoize upcall-class-ctor*)) (defn- upcall - "Constructs an instance of [[upcall-class]], closing over `f`." + "Constructs an instance of an upcall class, closing over `f`. + + See [[upcall-class-ctor]]." [f arg-types ret-type] - (insn/new-instance (upcall-class arg-types ret-type) ^IFn f)) + ((upcall-class-ctor arg-types ret-type) ^IFn f)) (defn- method-type "Gets the [[MethodType]] for a set of `args` and `ret` types." From f752a1592aadc0c8c251e7fe1f2a8f4ca5f38a48 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 11:12:37 -0400 Subject: [PATCH 08/16] Optimize re-serializing deserialized functions --- CHANGELOG.md | 1 + src/clj/coffi/ffi.clj | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 566381f..251df24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. This change - New `coffi.mem/null` var for implementing custom types ### Performance +- Upcall functions serialized from functions returned by deserializing function pointers now use the backing function pointer directly - Upcall and downcall classes have been changed to be memoized, meaning ASM is no longer invoked every time a function is serialized, which should drastically improve performance where functions are serialized in a hot loop ### Fixed diff --git a/src/clj/coffi/ffi.clj b/src/clj/coffi/ffi.clj index bcac52b..d6e72fd 100644 --- a/src/clj/coffi/ffi.clj +++ b/src/clj/coffi/ffi.clj @@ -575,25 +575,31 @@ (mem/global-arena)))) (defmethod mem/serialize* ::fn - [f [_fn arg-types ret-type & {:keys [raw-fn?]}] arena] - (.upcallStub - (Linker/nativeLinker) - ^MethodHandle (cond-> f - (not raw-fn?) (upcall-serde-wrapper arg-types ret-type) - :always (upcall-handle arg-types ret-type)) - ^FunctionDescriptor (function-descriptor arg-types ret-type) - ^Arena arena - (make-array Linker$Option 0))) + [f [_fn arg-types ret-type & {:keys [raw-fn?]} :as typ] arena] + (if-let [address (::address (meta f))] + (do (assert (= typ (::type (meta f))) + "The type of a deserialized function must match the type it is re-serialized to.") + address) + (.upcallStub + (Linker/nativeLinker) + ^MethodHandle (cond-> f + (not raw-fn?) (upcall-serde-wrapper arg-types ret-type) + :always (upcall-handle arg-types ret-type)) + ^FunctionDescriptor (function-descriptor arg-types ret-type) + ^Arena arena + (make-array Linker$Option 0)))) (defmethod mem/deserialize* ::fn - [addr [_fn arg-types ret-type & {:keys [raw-fn?]}]] + [addr [_fn arg-types ret-type & {:keys [raw-fn?] :as typ}]] (when-not (mem/null? addr) (vary-meta (-> ^MemorySegment addr (downcall-handle (function-descriptor arg-types ret-type)) (downcall-fn arg-types ret-type) (cond-> (not raw-fn?) (make-serde-wrapper arg-types ret-type))) - assoc ::address addr))) + assoc + ::address addr + ::type typ))) ;;; Static memory access From 2833d48d4dc002237fbda31d385dff77f974e109 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:11:15 -0400 Subject: [PATCH 09/16] Fix bad use of address-of in example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d1836c..7de83d5 100644 --- a/README.md +++ b/README.md @@ -338,7 +338,7 @@ Clojure code to make this easier. [ints] (let [arr-len (count ints) int-array (mem/serialize ints [::mem/array ::mem/int arr-len])] - (native-fn (mem/address-of int-array) arr-len))) + (native-fn int-array arr-len))) ``` The symbol `native-fn` can be any unqualified symbol, and names the native From d183fcdf985b0a2c52c16d0ff2a77beed30c89fb Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:11:48 -0400 Subject: [PATCH 10/16] Fix error when running tests with emacs --- test/clj/coffi/ffi_test.clj | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/test/clj/coffi/ffi_test.clj b/test/clj/coffi/ffi_test.clj index d45e3ae..b462191 100644 --- a/test/clj/coffi/ffi_test.clj +++ b/test/clj/coffi/ffi_test.clj @@ -62,9 +62,11 @@ (t/deftest can-call-with-trailing-string-arg (t/is - (= - ((ffi/cfn "test_call_with_trailing_string_arg" - [::mem/int ::mem/int ::mem/c-string] - ::mem/void) - 1 2 "third arg")))) - + (= (try ((ffi/cfn "test_call_with_trailing_string_arg" + [::mem/int ::mem/int ::mem/c-string] + ::mem/void) + 1 2 "third arg") + :ok + (catch Throwable _t + :err)) + :ok))) From 6ff882b85da0f73d6228361c6eaac801bc5effd5 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:11:57 -0400 Subject: [PATCH 11/16] Update docstring to reflect address-of returning a long --- CHANGELOG.md | 1 + src/clj/coffi/mem.clj | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 251df24..8de7bbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. This change - Upcall and downcall classes have been changed to be memoized, meaning ASM is no longer invoked every time a function is serialized, which should drastically improve performance where functions are serialized in a hot loop ### Fixed +- Incorrect docstring on `coffi.mem/address-of` that implied some type of pointer type was returned rather than a long - Usage of deprecated `(Class/STATIC_FIELD)` access pattern ## [1.0.450] - 2024-10-02 diff --git a/src/clj/coffi/mem.clj b/src/clj/coffi/mem.clj index 99bd00e..7dde14a 100644 --- a/src/clj/coffi/mem.clj +++ b/src/clj/coffi/mem.clj @@ -106,9 +106,7 @@ (.allocate ^SegmentAllocator allocator (long size) (long alignment)))) (defn address-of - "Gets the address of a given segment. - - This value can be used as an argument to functions which take a pointer." + "Gets the address of a given segment as a number." ^long [addressable] (.address ^MemorySegment addressable)) From a2dd6f2518eb124090bdecb6b1b5d86f91249b62 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:12:54 -0400 Subject: [PATCH 12/16] Add criterium to dev alias --- deps.edn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deps.edn b/deps.edn index 9f6884e..bcaa592 100644 --- a/deps.edn +++ b/deps.edn @@ -9,7 +9,8 @@ :aliases {:dev {:extra-paths ["."] :extra-deps {io.github.clojure/tools.build {:git/tag "v0.3.0" :git/sha "e418fc9"} - nodisassemble/nodisassemble {:mvn/version "0.1.3"}} + nodisassemble/nodisassemble {:mvn/version "0.1.3"} + criterium/criterium {:mvn/version "0.4.6"}} ;; NOTE(Joshua): If you want to use nodisassemble you should also add a ;; -javaagent for the resolved location :jvm-opts ["--enable-native-access=ALL-UNNAMED"]} From d3d2d25c782aed60672c80b1494337c91151783a Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:14:13 -0400 Subject: [PATCH 13/16] Update version in build script --- build.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.clj b/build.clj index c20f633..e8ac05e 100644 --- a/build.clj +++ b/build.clj @@ -17,8 +17,7 @@ [clojure.tools.build.api :as b])) (def lib-coord 'org.suskalo/coffi) -;;(def version (format "0.6.%s" (b/git-count-revs nil))) -(def version "1.0.450") +(def version (format "1.0.%s" (b/git-count-revs nil))) (def resource-dirs ["resources/"]) From c724e4208883f4caf05be206fd9462039cd29e55 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:19:59 -0400 Subject: [PATCH 14/16] Update codox documentation --- deps.edn | 2 +- docs/coffi.ffi.html | 42 ++++++------ docs/coffi.layout.html | 4 +- docs/coffi.mem.html | 151 +++++++++++++++++++++-------------------- docs/index.html | 4 +- 5 files changed, 102 insertions(+), 101 deletions(-) diff --git a/deps.edn b/deps.edn index bcaa592..6e85eca 100644 --- a/deps.edn +++ b/deps.edn @@ -26,7 +26,7 @@ insn/insn {:mvn/version "0.2.1"}} :exec-fn codox.main/generate-docs :exec-args {:name "coffi" - :version "v1.0.450" + :version "v1.0.471" :description "A Foreign Function Interface in Clojure for JDK 22+." :source-paths ["src/clj"] :output-path "docs" diff --git a/docs/coffi.ffi.html b/docs/coffi.ffi.html index 638e909..ad6f87c 100644 --- a/docs/coffi.ffi.html +++ b/docs/coffi.ffi.html @@ -1,41 +1,41 @@ -coffi.ffi documentation

coffi.ffi

Functions for creating handles to native functions and loading native libraries.

+coffi.ffi documentation

coffi.ffi

Functions for creating handles to native functions and loading native libraries.

cfn

(cfn symbol args ret)

Constructs a Clojure function to call the native function referenced by symbol.

The function returned will serialize any passed arguments into the args types, and deserialize the return to the ret type.

If your args and ret are constants, then it is more efficient to call make-downcall followed by make-serde-wrapper because the latter has an inline definition which will result in less overhead from serdes.

-

const

(const symbol-or-addr type)

Gets the value of a constant stored in symbol-or-addr.

-

defcfn

macro

(defcfn name docstring? attr-map? symbol arg-types ret-type)(defcfn name docstring? attr-map? symbol arg-types ret-type native-fn & fn-tail)

Defines a Clojure function which maps to a native function.

+

const

(const symbol-or-addr type)

Gets the value of a constant stored in symbol-or-addr.

+

defcfn

macro

(defcfn name docstring? attr-map? symbol arg-types ret-type)(defcfn name docstring? attr-map? symbol arg-types ret-type native-fn & fn-tail)

Defines a Clojure function which maps to a native function.

name is the symbol naming the resulting var. symbol is a symbol or string naming the library symbol to link against. arg-types is a vector of qualified keywords representing the argument types. ret-type is a single qualified keyword representing the return type. fn-tail is the body of the function (potentially with multiple arities) which wraps the native one. Inside the function, native-fn is bound to a function that will serialize its arguments, call the native function, and deserialize its return type. If any body is present, you must call this function in order to call the native code.

If no fn-tail is provided, then the resulting function will simply serialize the arguments according to arg-types, call the native function, and deserialize the return value.

The number of args in the fn-tail need not match the number of arg-types for the native function. It need only call the native wrapper function with the correct arguments.

See serialize, deserialize, make-downcall.

-

defconst

macro

(defconst symbol docstring? symbol-or-addr type)

Defines a var named by symbol to be the value of the given type from symbol-or-addr.

-

defvar

macro

(defvar symbol docstring? symbol-or-addr type)

Defines a var named by symbol to be a reference to the native memory from symbol-or-addr.

-

ensure-symbol

(ensure-symbol symbol-or-addr)

Returns the argument if it is a MemorySegment, otherwise calls find-symbol on it.

-

find-symbol

(find-symbol sym)

Gets the MemorySegment of a symbol from the loaded libraries.

-

freset!

(freset! static-var newval)

Sets the value of static-var to newval, running it through serialize.

-

fswap!

(fswap! static-var f & args)

Non-atomically runs the function f over the value stored in static-var.

+

defconst

macro

(defconst symbol docstring? symbol-or-addr type)

Defines a var named by symbol to be the value of the given type from symbol-or-addr.

+

defvar

macro

(defvar symbol docstring? symbol-or-addr type)

Defines a var named by symbol to be a reference to the native memory from symbol-or-addr.

+

ensure-symbol

(ensure-symbol symbol-or-addr)

Returns the argument if it is a MemorySegment, otherwise calls find-symbol on it.

+

find-symbol

(find-symbol sym)

Gets the MemorySegment of a symbol from the loaded libraries.

+

freset!

(freset! static-var newval)

Sets the value of static-var to newval, running it through serialize.

+

fswap!

(fswap! static-var f & args)

Non-atomically runs the function f over the value stored in static-var.

The value is deserialized before passing it to f, and serialized before putting the value into static-var.

-

load-library

(load-library path)

Loads the library at path.

-

load-system-library

(load-system-library libname)

Loads the library named libname from the system’s load path.

-

make-downcall

(make-downcall symbol-or-addr args ret)

Constructs a downcall function reference to symbol-or-addr with the given args and ret types.

+

load-library

(load-library path)

Loads the library at path.

+

load-system-library

(load-system-library libname)

Loads the library named libname from the system’s load path.

+

make-downcall

(make-downcall symbol-or-addr args ret)

Constructs a downcall function reference to symbol-or-addr with the given args and ret types.

The function returned takes only arguments whose types match exactly the java-layout for that type, and returns an argument with exactly the java-layout of the ret type. This function will perform no serialization or deserialization of arguments or the return type.

If the ret type is non-primitive, then the returned function will take a first argument of a SegmentAllocator.

-

make-serde-varargs-wrapper

(make-serde-varargs-wrapper varargs-factory required-args ret-type)

Constructs a wrapper function for the varargs-factory which produces functions that serialize the arguments and deserialize the return value.

-

make-serde-wrapper

(make-serde-wrapper downcall arg-types ret-type)

Constructs a wrapper function for the downcall which serializes the arguments and deserializes the return value.

-

make-varargs-factory

(make-varargs-factory symbol required-args ret)

Returns a function for constructing downcalls with additional types for arguments.

+

make-serde-varargs-wrapper

(make-serde-varargs-wrapper varargs-factory required-args ret-type)

Constructs a wrapper function for the varargs-factory which produces functions that serialize the arguments and deserialize the return value.

+

make-serde-wrapper

(make-serde-wrapper downcall arg-types ret-type)

Constructs a wrapper function for the downcall which serializes the arguments and deserializes the return value.

+

make-varargs-factory

(make-varargs-factory symbol required-args ret)

Returns a function for constructing downcalls with additional types for arguments.

The required-args are the types of the first arguments passed to the downcall handle, and the values passed to the returned function are only the varargs types.

The returned function is memoized, so that only one downcall function will be generated per combination of argument types.

See make-downcall.

-

reify-libspec

(reify-libspec libspec)

Loads all the symbols specified in the libspec.

+

reify-libspec

(reify-libspec libspec)

Loads all the symbols specified in the libspec.

The value of each key of the passed map is transformed as by reify-symbolspec.

-

reify-symbolspec

multimethod

Takes a spec for a symbol reference and returns a live value for that type.

-

static-variable

(static-variable symbol-or-addr type)

Constructs a reference to a mutable value stored in symbol-or-addr.

+

reify-symbolspec

multimethod

Takes a spec for a symbol reference and returns a live value for that type.

+

static-variable

(static-variable symbol-or-addr type)

Constructs a reference to a mutable value stored in symbol-or-addr.

The returned value can be dereferenced, and has metadata.

See freset!, fswap!.

-

static-variable-segment

(static-variable-segment static-var)

Gets the backing MemorySegment from static-var.

+

static-variable-segment

(static-variable-segment static-var)

Gets the backing MemorySegment from static-var.

This is primarily useful when you need to pass the static variable’s address to a native function which takes an Addressable.

-

vacfn-factory

(vacfn-factory symbol required-args ret)

Constructs a varargs factory to call the native function referenced by symbol.

+

vacfn-factory

(vacfn-factory symbol required-args ret)

Constructs a varargs factory to call the native function referenced by symbol.

The function returned takes any number of type arguments and returns a specialized Clojure function for calling the native function with those arguments.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/coffi.layout.html b/docs/coffi.layout.html index f76061e..9b171de 100644 --- a/docs/coffi.layout.html +++ b/docs/coffi.layout.html @@ -1,6 +1,6 @@ -coffi.layout documentation

coffi.layout

Functions for adjusting the layout of structs.

+coffi.layout documentation

coffi.layout

Functions for adjusting the layout of structs.

with-c-layout

(with-c-layout struct-spec)

Forces a struct specification to C layout rules.

This will add padding fields between fields to match C alignment requirements.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/coffi.mem.html b/docs/coffi.mem.html index a2f55d9..4e44699 100644 --- a/docs/coffi.mem.html +++ b/docs/coffi.mem.html @@ -1,120 +1,121 @@ -coffi.mem documentation

coffi.mem

Functions for managing native allocations, memory arenas, and (de)serialization.

+coffi.mem documentation

coffi.mem

Functions for managing native allocations, memory arenas, and (de)serialization.

For any new type to be implemented, three multimethods must be overriden, but which three depends on the native representation of the type.

If the native representation of the type is a primitive (whether or not other data beyond the primitive is associated with it, as e.g. a pointer), then primitive-type must be overriden to return which primitive type it is serialized as, then serialize* and deserialize* should be overriden.

If the native representation of the type is a composite type, like a union, struct, or array, then c-layout must be overriden to return the native layout of the type, and serialize-into and deserialize-from should be overriden to allow marshaling values of the type into and out of memory segments.

-

address-of

(address-of addressable)

Gets the address of a given segment.

-

This value can be used as an argument to functions which take a pointer.

-

address?

(address? addr)

Checks if an object is a memory address.

+

address-of

(address-of addressable)

Gets the address of a given segment as a number.

+

address?

(address? addr)

Checks if an object is a memory address.

nil is considered an address.

-

align-of

(align-of type)

The alignment in bytes of the given type.

-

alloc

(alloc size)(alloc size arena)(alloc size alignment arena)

Allocates size bytes.

+

align-of

(align-of type)

The alignment in bytes of the given type.

+

alloc

(alloc size)(alloc size arena)(alloc size alignment arena)

Allocates size bytes.

If an arena is provided, the allocation will be reclaimed when it is closed.

-

alloc-instance

(alloc-instance type)(alloc-instance type arena)

Allocates a memory segment for the given type.

-

alloc-with

(alloc-with allocator size)(alloc-with allocator size alignment)

Allocates size bytes using the allocator.

-

arena-allocator

(arena-allocator arena)

Constructs a SegmentAllocator from the given Arena.

+

alloc-instance

(alloc-instance type)(alloc-instance type arena)

Allocates a memory segment for the given type.

+

alloc-with

(alloc-with allocator size)(alloc-with allocator size alignment)

Allocates size bytes using the allocator.

+

arena-allocator

(arena-allocator arena)

Constructs a SegmentAllocator from the given Arena.

This is primarily used when working with unwrapped downcall functions. When a downcall function returns a non-primitive type, it must be provided with an allocator.

-

as-segment

(as-segment address)(as-segment address size)(as-segment address size arena)(as-segment address size arena cleanup)

Dereferences an address into a memory segment associated with the arena (default global).

-

auto-arena

(auto-arena)

Constructs a new memory arena that is managed by the garbage collector.

+

as-segment

(as-segment address)(as-segment address size)(as-segment address size arena)(as-segment address size arena cleanup)

Dereferences an address into a memory segment associated with the arena (default global).

+

auto-arena

(auto-arena)

Constructs a new memory arena that is managed by the garbage collector.

The arena may be shared across threads, and all resources created with it will be cleaned up at the same time, when all references have been collected.

This type of arena cannot be closed, and therefore should not be created in a with-open clause.

-

big-endian

The big-endian ByteOrder.

+

big-endian

The big-endian ByteOrder.

See little-endian, native-endian.

-

byte-layout

The MemoryLayout for a byte in native-endian ByteOrder.

-

c-layout

multimethod

Gets the layout object for a given type.

+

byte-layout

The MemoryLayout for a byte in native-endian ByteOrder.

+

c-layout

multimethod

Gets the layout object for a given type.

If a type is primitive it will return the appropriate primitive layout (see c-prim-layout).

Otherwise, it should return a GroupLayout for the given type.

-

char-layout

The MemoryLayout for a c-sized char in native-endian ByteOrder.

-

clone-segment

(clone-segment segment)(clone-segment segment arena)

Clones the content of segment into a new segment of the same size.

-

confined-arena

(confined-arena)

Constructs a new arena for use only in this thread.

+

char-layout

The MemoryLayout for a c-sized char in native-endian ByteOrder.

+

clone-segment

(clone-segment segment)(clone-segment segment arena)

Clones the content of segment into a new segment of the same size.

+

confined-arena

(confined-arena)

Constructs a new arena for use only in this thread.

The memory allocated within this arena is cheap to allocate, like a native stack.

The memory allocated within this arena will be cleared once it is closed, so it is usually a good idea to create it in a with-open clause.

-

copy-segment

(copy-segment dest src)

Copies the content to dest from src.

+

copy-segment

(copy-segment dest src)

Copies the content to dest from src.

Returns dest.

-

defalias

macro

(defalias new-type aliased-type)

Defines a type alias from new-type to aliased-type.

+

defalias

macro

(defalias new-type aliased-type)

Defines a type alias from new-type to aliased-type.

This creates needed serialization and deserialization implementations for the aliased type.

-

deserialize

(deserialize obj type)

Deserializes an arbitrary type.

+

deserialize

(deserialize obj type)

Deserializes an arbitrary type.

For types which have a primitive representation, this deserializes the primitive representation. For types which do not, this deserializes out of a segment.

-

deserialize*

multimethod

Deserializes a primitive object into a Clojure data structure.

+

deserialize*

multimethod

Deserializes a primitive object into a Clojure data structure.

This is intended for use with types that are returned as a primitive but which need additional processing before they can be returned.

-

deserialize-from

multimethod

Deserializes the given segment into a Clojure data structure.

+

deserialize-from

multimethod

Deserializes the given segment into a Clojure data structure.

For types that serialize to primitives, a default implementation will deserialize the primitive before calling deserialize*.

-

double-alignment

The alignment in bytes of a c-sized double.

-

double-layout

The MemoryLayout for a c-sized double in native-endian ByteOrder.

-

double-size

The size in bytes of a c-sized double.

-

float-alignment

The alignment in bytes of a c-sized float.

-

float-layout

The MemoryLayout for a c-sized float in native-endian ByteOrder.

-

float-size

The size in bytes of a c-sized float.

-

global-arena

(global-arena)

Constructs the global arena, which will never reclaim its resources.

+

double-alignment

The alignment in bytes of a c-sized double.

+

double-layout

The MemoryLayout for a c-sized double in native-endian ByteOrder.

+

double-size

The size in bytes of a c-sized double.

+

float-alignment

The alignment in bytes of a c-sized float.

+

float-layout

The MemoryLayout for a c-sized float in native-endian ByteOrder.

+

float-size

The size in bytes of a c-sized float.

+

global-arena

(global-arena)

Constructs the global arena, which will never reclaim its resources.

This arena may be shared across threads, but is intended mainly in cases where memory is allocated with alloc but is either never freed or whose management is relinquished to a native library, such as when returned from a callback.

-

int-alignment

The alignment in bytes of a c-sized int.

-

int-layout

The MemoryLayout for a c-sized int in native-endian ByteOrder.

-

int-size

The size in bytes of a c-sized int.

-

java-layout

(java-layout type)

Gets the Java class to an argument of this type for a method handle.

+

int-alignment

The alignment in bytes of a c-sized int.

+

int-layout

The MemoryLayout for a c-sized int in native-endian ByteOrder.

+

int-size

The size in bytes of a c-sized int.

+

java-layout

(java-layout type)

Gets the Java class to an argument of this type for a method handle.

If a type serializes to a primitive it returns return a Java primitive type. Otherwise, it returns MemorySegment.

-

java-prim-layout

Map of primitive type names to the Java types for a method handle.

-

little-endian

The little-endian ByteOrder.

+

java-prim-layout

Map of primitive type names to the Java types for a method handle.

+

little-endian

The little-endian ByteOrder.

See big-endian, native-endian

-

long-alignment

The alignment in bytes of a c-sized long.

-

long-layout

The MemoryLayout for a c-sized long in native-endian ByteOrder.

-

long-size

The size in bytes of a c-sized long.

-

native-endian

The ByteOrder for the native endianness of the current hardware.

+

long-alignment

The alignment in bytes of a c-sized long.

+

long-layout

The MemoryLayout for a c-sized long in native-endian ByteOrder.

+

long-size

The size in bytes of a c-sized long.

+

native-endian

The ByteOrder for the native endianness of the current hardware.

See big-endian, little-endian.

-

null?

(null? addr)

Checks if a memory address is null.

-

pointer-alignment

The alignment in bytes of a c-sized pointer.

-

pointer-layout

The MemoryLayout for a native pointer in native-endian ByteOrder.

-

pointer-size

The size in bytes of a c-sized pointer.

-

primitive-type

multimethod

Gets the primitive type that is used to pass as an argument for the type.

+

null

The NULL pointer object.

+

While this object is safe to pass to functions which serialize to a pointer, it’s generally encouraged to simply pass nil. This value primarily exists to make it easier to write custom types with a primitive pointer representation.

+

null?

(null? addr)

Checks if a memory address is null.

+

pointer-alignment

The alignment in bytes of a c-sized pointer.

+

pointer-layout

The MemoryLayout for a native pointer in native-endian ByteOrder.

+

pointer-size

The size in bytes of a c-sized pointer.

+

primitive-type

multimethod

Gets the primitive type that is used to pass as an argument for the type.

This is for objects which are passed to native functions as primitive types, but which need additional logic to be performed during serialization and deserialization.

Implementations of this method should take into account that type arguments may not always be evaluated before passing to this function.

Returns nil for any type which does not have a primitive representation.

-

primitive-types

A set of all primitive types.

-

primitive?

(primitive? type)

A predicate to determine if a given type is primitive.

-

read-address

(read-address segment)(read-address segment offset)

Reads an address from the segment, at an optional offset, wrapped in a MemorySegment.

-

read-byte

(read-byte segment)(read-byte segment offset)

Reads a byte from the segment, at an optional offset.

-

read-char

(read-char segment)(read-char segment offset)

Reads a char from the segment, at an optional offset.

-

read-double

(read-double segment)(read-double segment offset)(read-double segment offset byte-order)

Reads a double from the segment, at an optional offset.

+

primitive-types

A set of all primitive types.

+

primitive?

(primitive? type)

A predicate to determine if a given type is primitive.

+

read-address

(read-address segment)(read-address segment offset)

Reads an address from the segment, at an optional offset, wrapped in a MemorySegment.

+

read-byte

(read-byte segment)(read-byte segment offset)

Reads a byte from the segment, at an optional offset.

+

read-char

(read-char segment)(read-char segment offset)

Reads a char from the segment, at an optional offset.

+

read-double

(read-double segment)(read-double segment offset)(read-double segment offset byte-order)

Reads a double from the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

read-float

(read-float segment)(read-float segment offset)(read-float segment offset byte-order)

Reads a float from the segment, at an optional offset.

+

read-float

(read-float segment)(read-float segment offset)(read-float segment offset byte-order)

Reads a float from the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

read-int

(read-int segment)(read-int segment offset)(read-int segment offset byte-order)

Reads a int from the segment, at an optional offset.

+

read-int

(read-int segment)(read-int segment offset)(read-int segment offset byte-order)

Reads a int from the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

read-long

(read-long segment)(read-long segment offset)(read-long segment offset byte-order)

Reads a long from the segment, at an optional offset.

+

read-long

(read-long segment)(read-long segment offset)(read-long segment offset byte-order)

Reads a long from the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

read-short

(read-short segment)(read-short segment offset)(read-short segment offset byte-order)

Reads a short from the segment, at an optional offset.

+

read-short

(read-short segment)(read-short segment offset)(read-short segment offset byte-order)

Reads a short from the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

reinterpret

(reinterpret segment size)(reinterpret segment size arena)(reinterpret segment size arena cleanup)

Reinterprets the segment as having the passed size.

+

reinterpret

(reinterpret segment size)(reinterpret segment size arena)(reinterpret segment size arena cleanup)

Reinterprets the segment as having the passed size.

If arena is passed, the scope of the segment is associated with the arena, as well as its access constraints. If cleanup is passed, it will be a 1-argument function of a fresh memory segment backed by the same memory as the returned segment which should perform any required cleanup operations. It will be called when the arena is closed.

-

seq-of

(seq-of type segment)

Constructs a lazy sequence of type elements deserialized from segment.

-

serialize

(serialize obj type)(serialize obj type arena)

Serializes an arbitrary type.

+

seq-of

(seq-of type segment)

Constructs a lazy sequence of type elements deserialized from segment.

+

serialize

(serialize obj type)(serialize obj type arena)

Serializes an arbitrary type.

For types which have a primitive representation, this serializes into that representation. For types which do not, it allocates a new segment and serializes into that.

-

serialize*

multimethod

Constructs a serialized version of the obj and returns it.

+

serialize*

multimethod

Constructs a serialized version of the obj and returns it.

Any new allocations made during the serialization should be tied to the given arena, except in extenuating circumstances.

This method should only be implemented for types that serialize to primitives.

-

serialize-into

multimethod

Writes a serialized version of the obj to the given segment.

+

serialize-into

multimethod

Writes a serialized version of the obj to the given segment.

Any new allocations made during the serialization should be tied to the given arena, except in extenuating circumstances.

This method should be implemented for any type which does not override c-layout.

For any other type, this will serialize it as serialize* before writing the result value into the segment.

-

shared-arena

(shared-arena)

Constructs a new shared memory arena.

+

shared-arena

(shared-arena)

Constructs a new shared memory arena.

This arena can be shared across threads and memory allocated in it will only be cleaned up once any thread accessing the arena closes it.

-

short-alignment

The alignment in bytes of a c-sized short.

-

short-layout

The MemoryLayout for a c-sized short in native-endian ByteOrder.

-

short-size

The size in bytes of a c-sized short.

-

size-of

(size-of type)

The size in bytes of the given type.

-

slice

(slice segment offset)(slice segment offset size)

Get a slice over the segment with the given offset.

-

slice-segments

(slice-segments segment size)

Constructs a lazy seq of size-length memory segments, sliced from segment.

-

write-address

(write-address segment value)(write-address segment offset value)

Writes the address of the MemorySegment value to the segment, at an optional offset.

-

write-byte

(write-byte segment value)(write-byte segment offset value)

Writes a byte to the segment, at an optional offset.

-

write-char

(write-char segment value)(write-char segment offset value)

Writes a char to the segment, at an optional offset.

-

write-double

(write-double segment value)(write-double segment offset value)(write-double segment offset byte-order value)

Writes a double to the segment, at an optional offset.

+

short-alignment

The alignment in bytes of a c-sized short.

+

short-layout

The MemoryLayout for a c-sized short in native-endian ByteOrder.

+

short-size

The size in bytes of a c-sized short.

+

size-of

(size-of type)

The size in bytes of the given type.

+

slice

(slice segment offset)(slice segment offset size)

Get a slice over the segment with the given offset.

+

slice-segments

(slice-segments segment size)

Constructs a lazy seq of size-length memory segments, sliced from segment.

+

write-address

(write-address segment value)(write-address segment offset value)

Writes the address of the MemorySegment value to the segment, at an optional offset.

+

write-byte

(write-byte segment value)(write-byte segment offset value)

Writes a byte to the segment, at an optional offset.

+

write-char

(write-char segment value)(write-char segment offset value)

Writes a char to the segment, at an optional offset.

+

write-double

(write-double segment value)(write-double segment offset value)(write-double segment offset byte-order value)

Writes a double to the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

write-float

(write-float segment value)(write-float segment offset value)(write-float segment offset byte-order value)

Writes a float to the segment, at an optional offset.

+

write-float

(write-float segment value)(write-float segment offset value)(write-float segment offset byte-order value)

Writes a float to the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

write-int

(write-int segment value)(write-int segment offset value)(write-int segment offset byte-order value)

Writes a int to the segment, at an optional offset.

+

write-int

(write-int segment value)(write-int segment offset value)(write-int segment offset byte-order value)

Writes a int to the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

write-long

(write-long segment value)(write-long segment offset value)(write-long segment offset byte-order value)

Writes a long to the segment, at an optional offset.

+

write-long

(write-long segment value)(write-long segment offset value)(write-long segment offset byte-order value)

Writes a long to the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-

write-short

(write-short segment value)(write-short segment offset value)(write-short segment offset byte-order value)

Writes a short to the segment, at an optional offset.

+

write-short

(write-short segment value)(write-short segment offset value)(write-short segment offset byte-order value)

Writes a short to the segment, at an optional offset.

If byte-order is not provided, it defaults to native-endian.

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 5a5c360..e27ef35 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,6 +1,6 @@ -coffi v1.0.450

coffi v1.0.450

A Foreign Function Interface in Clojure for JDK 22+.

Namespaces

coffi.ffi

Functions for creating handles to native functions and loading native libraries.

+coffi v1.0.471

coffi v1.0.471

A Foreign Function Interface in Clojure for JDK 22+.

Namespaces

coffi.layout

Functions for adjusting the layout of structs.

Public variables and functions:

\ No newline at end of file +
\ No newline at end of file From e0af08dabf95349d104421ffec444e4c7a08508e Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:20:31 -0400 Subject: [PATCH 15/16] Update changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de7bbd..8ea4ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # 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/). -## [UNRELEASED] +## [1.0.472] - 2024-10-03 ### Added - New `coffi.mem/null` var for implementing custom types @@ -145,7 +145,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 -[UNRELEASED]: https://github.com/IGJoshua/coffi/compare/v1.0.450...develop +[1.0.472]: https://github.com/IGJoshua/coffi/compare/v1.0.450...v1.0.472 [1.0.450]: https://github.com/IGJoshua/coffi/compare/v0.6.409...v1.0.450 [0.6.409]: https://github.com/IGJoshua/coffi/compare/v0.5.357...v0.6.409 [0.5.357]: https://github.com/IGJoshua/coffi/compare/v0.4.341...v0.5.357 From abeeb447a228a467d54cc58d7e3b582eacff0057 Mon Sep 17 00:00:00 2001 From: Joshua Suskalo Date: Thu, 3 Oct 2024 14:21:10 -0400 Subject: [PATCH 16/16] Update version and tag in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7de83d5..d295046 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,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 "1.0.450"} -io.github.IGJoshua/coffi {:git/tag "v1.0.450" :git/sha "2676a7a"} +org.suskalo/coffi {:mvn/version "1.0.471"} +io.github.IGJoshua/coffi {:git/tag "v1.0.471" :git/sha "d3d2d25"} ``` If you use this library as a git dependency, you will need to prepare the