diff --git a/src/coffi/ffi.clj b/src/coffi/ffi.clj index 5e7eab0..36d1eb1 100644 --- a/src/coffi/ffi.clj +++ b/src/coffi/ffi.clj @@ -440,7 +440,7 @@ deserialize-from) obj type))) -;; C String type +;;; C String type (defmethod primitive-type ::c-string [_type] @@ -468,6 +468,27 @@ (rec (slice segment size))))))] (rec segment)))) +;;; Union types + +(defmethod c-layout ::union + [[_union _dispatch types & {:as _opts} :as _type]] + (let [items (map c-layout types)] + (MemoryLayout/unionLayout + (into-array MemoryLayout items)))) + +(defmethod serialize-into ::union + [obj [_union dispatch _types & {:keys [extract]}] segment scope] + (let [type (dispatch obj)] + (serialize-into + (if extract + (extract type obj) + obj) + type + segment + scope))) + +;;; FFI Code loading and function access + (defn load-system-library "Loads the library named `libname` from the system's load path." [libname]