Compare commits

..

103 commits

Author SHA1 Message Date
Joshua Suskalo
8ca1efcb26
Update changelog 2025-03-03 16:05:37 -05:00
Joshua Suskalo
00faaaa78b
Merge remote-tracking branch 'rutenkolk/master' into develop 2025-03-03 15:48:44 -05:00
Joshua Suskalo
5d94afdbf3
Add tests for string variables in native 2025-02-27 10:44:55 -05:00
Joshua Suskalo
053166d0f4
Add arglists to serialize-into and deserialize-from 2025-02-27 10:43:40 -05:00
Joshua Suskalo
544cf59280
Revert "Fix issue with StaticVariable failing on pointer-carried types"
This reverts commit c1fa08586a.
2025-02-27 10:43:18 -05:00
Joshua Suskalo
c1fa08586a
Fix issue with StaticVariable failing on pointer-carried types 2025-02-26 14:50:42 -05:00
Kristin Rutenkolk
6383c6e425 fix defstruct pointer members 2025-02-23 16:54:06 +01:00
Kristin Rutenkolk
f307d1ed51 fix file not found error: replace load-file with load 2025-02-18 19:05:09 +01:00
Kristin Rutenkolk
f9784b33cc allow global offset to be expression for
register-new-struct-deserialization
2025-01-07 18:45:09 +01:00
Kristin Rutenkolk
a6b7ece504 remove layout dependency from mem test 2025-01-07 17:22:00 +01:00
Kristin Rutenkolk
8d29234db4 move with-c-layout back to layout.clj and load layout namespace from mem 2025-01-07 17:18:14 +01:00
Kristin Rutenkolk
1f5efb0982 emit serde registration and omit padding from defstruct 2025-01-04 23:32:59 +01:00
Kristin Rutenkolk
06cd910279 remove typename argument from typelist 2025-01-04 21:02:25 +01:00
Kristin Rutenkolk
637f156663 fix order of type and fieldname for defstruct in tests 2025-01-04 20:40:03 +01:00
Kristin Rutenkolk
5a9d156e17 reverse type and fieldname in defstruct definition 2025-01-04 20:33:22 +01:00
Kristin Rutenkolk
d2afb2b170 remove bulk deserialization for vectors 2025-01-03 01:23:59 +01:00
Kristin Rutenkolk
e25ad22ae6 fix unmatched parantheses 2025-01-03 00:25:34 +01:00
Kristin Rutenkolk
a6864fdba5
refactor generate-struct-type to return the form via syntax quote
Co-authored-by: Joshua Suskalo <joshua@suskalo.org>
2025-01-03 00:23:36 +01:00
Kristin Rutenkolk
d24ebc7810 refactor struct-vec-iterator to camel case 2025-01-03 00:20:03 +01:00
Kristin Rutenkolk
0dfb6bd3de
use syntax quoted expression in generate-deserialize implementation for strings
Co-authored-by: Joshua Suskalo <joshua@suskalo.org>
2025-01-02 23:50:26 +01:00
Kristin Rutenkolk
10b8baafa2 refactor multimethod dispatch function to use ffirst 2025-01-02 23:44:26 +01:00
Kristin Rutenkolk
cb3e62057f fix mangled keyword in coffitype->typename 2025-01-02 23:40:05 +01:00
Joshua Suskalo
78d39b1541 Don't use underscore on used args
Signed-off-by: Kristin Rutenkolk <kristin.rutenkolk@hhu.de>
2025-01-02 23:33:12 +01:00
Joshua Suskalo
33e1a95ba9 Remove duplicate c-layout implementation
Signed-off-by: Kristin Rutenkolk <kristin.rutenkolk@hhu.de>
2025-01-02 23:33:05 +01:00
Joshua Suskalo
8ea121723c Fix warning about defstruct redefinition
Signed-off-by: Kristin Rutenkolk <kristin.rutenkolk@hhu.de>
2025-01-02 23:32:58 +01:00
Joshua Suskalo
d763b39b51 Use a once-only impl rather than with-typehints
Signed-off-by: Kristin Rutenkolk <kristin.rutenkolk@hhu.de>
2025-01-02 23:32:37 +01:00
Kristin Rutenkolk
51dfbc39ed fix array serialization 2024-12-29 17:54:40 +01:00
Kristin Rutenkolk
c49dc796b2 remove array-copy-method 2024-12-29 16:16:41 +01:00
Kristin Rutenkolk
869e6787fa refactor array serdes & auto-choose copy methods 2024-12-29 15:28:50 +01:00
Kristin Rutenkolk
18f5699f3a remove necessity to create array when deserializing 2024-12-29 11:32:31 +01:00
Kristin Rutenkolk
ab8cc0c859 fix write-byte typehint 2024-12-29 10:23:01 +01:00
Kristin Rutenkolk
7bcdb8c227 typehint inline functions 2024-12-28 01:08:45 +01:00
Kristin Rutenkolk
a358fb6d77 add array-copy-method var to switch behavior 2024-12-21 17:56:25 +01:00
Kristin Rutenkolk
0467fe6006 add native array read functions 2024-12-20 21:53:01 +01:00
Kristin Rutenkolk
b03635e231 rewrite write array functions to take a length parameter 2024-12-20 17:26:52 +01:00
Kristin Rutenkolk
d1f54b1e05 fix defstruct cons implementation for mapentries and respective type
hints
2024-12-20 11:30:13 +01:00
Kristin Rutenkolk
b2cc9e6549 remove maplike option from defstruct generation 2024-12-20 10:40:55 +01:00
Kristin Rutenkolk
f3f156c53a add suppoort for native array write functions 2024-12-19 16:11:00 +01:00
Kristin Rutenkolk
e648c26a25 clean up deserializing logic 2024-12-19 15:12:10 +01:00
Kristin Rutenkolk
0c84c323b3 make private with-c-layout implementation behave like the one in
`layout`
2024-12-19 14:17:18 +01:00
Kristin Rutenkolk
bba05c7dfd improve defstruct doc 2024-12-19 12:28:43 +01:00
Kristin Rutenkolk
87e9bb7a7b adjust tests to make use of :raw? option in arrays 2024-12-12 12:36:15 +01:00
Kristin Rutenkolk
86c4f99a3f add optional :raw? true option for arrays 2024-12-12 12:35:37 +01:00
Kristin Rutenkolk
ff0bd6c568 make multimethods hygenic 2024-12-08 12:40:00 +01:00
Joshua Suskalo
167d3e0d9b
Add line for graalvm native-image in future plans 2024-11-22 10:26:52 -05:00
Joshua Suskalo
030c091c6d
Update api docs link 2024-11-22 10:25:14 -05:00
Joshua Suskalo
f7037b7a67
Link to cljdoc instead of codox documentation 2024-11-22 10:23:49 -05:00
Joshua Suskalo
7700f3f5e6
Add functions header in builtin types 2024-11-22 10:15:52 -05:00
Joshua Suskalo
2d708fa772
Add cross-link for tagged union type mention 2024-11-22 10:14:52 -05:00
Kristin Rutenkolk
2b1d062277 add non raw array ffi test 2024-10-30 21:00:45 +01:00
Kristin Rutenkolk
d190873f72 add raw-arrays struct serde 2024-10-30 20:58:23 +01:00
Kristin Rutenkolk
56a0df3257 add :raw-arrays? option 2024-10-30 20:28:20 +01:00
Kristin Rutenkolk
69a99d5521 remove nested struct definition tests, as they seem to not find the
right types consistently
2024-10-30 15:17:11 +01:00
Kristin Rutenkolk
63e029dc51 fix mem test to not create structs in in are clauses 2024-10-30 15:13:42 +01:00
Kristin Rutenkolk
7ccaad988d add IFN implementation to structs 2024-10-30 15:12:40 +01:00
Kristin Rutenkolk
68d9108ccf fix ffi_test 2024-10-30 14:12:18 +01:00
Kristin Rutenkolk
eef2e56f7e improve sequences on structs 2024-10-30 13:28:49 +01:00
Kristin Rutenkolk
fc62e1f345 remove vector-native struct version 2024-10-30 11:59:46 +01:00
Kristin Rutenkolk
a8fca25f7c add ffi tests with structs 2024-10-28 22:47:38 +01:00
Kristin Rutenkolk
8fb300c5c9 fix string deserialization for strings in structs 2024-10-28 22:42:59 +01:00
Kristin Rutenkolk
9765ec0deb fix strings in defstruct 2024-10-28 22:18:49 +01:00
Kristin Rutenkolk
cec1a8a0a8 add tests for structs with array members 2024-10-28 21:29:23 +01:00
Kristin Rutenkolk
8844eef320 fix array handling code 2024-10-28 21:28:50 +01:00
Kristin Rutenkolk
43acc60784 add struct definition and instantiation tests 2024-10-28 15:46:06 +01:00
Kristin Rutenkolk
78164a12a7 add struct serialization tests 2024-10-28 14:35:54 +01:00
Kristin Rutenkolk
bbd01dc4a9 add equivalence tests 2024-10-28 14:35:40 +01:00
Kristin Rutenkolk
fd0f22fda5 implement java.util.Map and MapEquivalence 2024-10-28 14:35:01 +01:00
Kristin Rutenkolk
e5cd228f94 add map functionaliy test for struct 2024-10-24 14:42:31 +02:00
Kristin Rutenkolk
18679c435e fix struct entryAt 2024-10-24 14:38:09 +02:00
Kristin Rutenkolk
9404ef4cf8 fix struct assoc 2024-10-24 14:24:54 +02:00
Kristin Rutenkolk
003a7377dd fix struct map containsKey 2024-10-24 14:05:58 +02:00
Kristin Rutenkolk
ec418cb6c9 fix map cons 2024-10-24 13:45:16 +02:00
Kristin Rutenkolk
4c408043ec improve error message 2024-10-24 12:04:36 +02:00
Kristin Rutenkolk
b6f1e44ce0 make defstruct robust against dangling and unbound vars 2024-10-24 11:45:17 +02:00
Kristin Rutenkolk
020e10264f add error message for invalid type usage 2024-10-24 11:37:40 +02:00
Kristin Rutenkolk
cf2decedcd introduce custom vector iterator 2024-10-24 09:07:46 +02:00
Kristin Rutenkolk
913c004adb fix forEach reference 2024-10-22 13:19:07 +02:00
Kristin Rutenkolk
f08fa20cf6 draft of new type generation 2024-10-19 03:26:45 +02:00
Kristin Rutenkolk
4f5b9fa60a fix seq of new type and remove indirection 2024-10-18 18:06:02 +02:00
Joshua Suskalo
39dc48b9e9
Use the --release flag for java compilation
This gets around the documented issue from java 9 and later where simply
using -source and -target might result in newer APIs still getting used
anyway. This version will ensure the compiled classes work on the
intended version.

This also fixes a warning that javac printed.
2024-10-18 11:24:36 -04:00
Joshua Suskalo
50dca53b7d
Merge branch 'bugfix-for-const' into develop 2024-10-18 11:20:18 -04:00
Jan Wedekind (Dr)
26fbed6927
Bugfix for const expressions 2024-10-18 11:20:01 -04:00
Kristin Rutenkolk
53a8435768 add pprint impl for struct types 2024-10-13 22:08:01 +02:00
Kristin Rutenkolk
21c547c469 add custom deftype for struct type generation 2024-10-12 15:52:03 +02:00
Kristin Rutenkolk
f702096ed5 fix array handling for defstruct macro 2024-10-12 00:36:21 +02:00
Kristin Rutenkolk
eea1b43da3 fix nested types serdes 2024-10-11 22:26:41 +02:00
Kristin Rutenkolk
37b74fc638 add serialization generation 2024-10-11 17:48:58 +02:00
Kristin Rutenkolk
c5d18e9e50 add generate-serialize multimethod 2024-10-11 16:55:03 +02:00
Kristin Rutenkolk
8bfc156d10 add deserialization generation 2024-10-11 15:52:40 +02:00
Kristin Rutenkolk
b0cb0f2ff3 add c-layout to struct generation 2024-10-11 15:18:35 +02:00
Kristin Rutenkolk
df29b16d71 remove namespace qualifiers from with-c-layout 2024-10-11 15:17:54 +02:00
Kristin Rutenkolk
d04a9f6286 copy with-c-layout to mem namespace 2024-10-11 14:53:09 +02:00
Kristin Rutenkolk
cf6dff3b52 add defstruct macro and helper functions 2024-10-11 14:25:18 +02:00
Joshua Suskalo
8ec46af8de
Add thankyou for adding named union member support 2024-10-10 17:15:42 -04:00
Joshua Suskalo
bb4dc5d389
Merge pull request #13 from jjttjj/develop
Support named union members in c-layout
2024-10-10 16:14:46 -05:00
Justin Tirrell
abfe6145ba Update changelog 2024-10-10 12:09:46 -04:00
Justin Tirrell
413d231d29 Add support for named union members in c-layout 2024-10-10 11:56:28 -04:00
Kristin Rutenkolk
f96df719eb remove namespaced references 2024-10-10 15:59:28 +02:00
Joshua Suskalo
3fb34923e1
Merge branch 'master' into develop 2024-10-04 16:35:49 -04:00
Joshua Suskalo
07216c7b2f
Remove reference to fixed "known issue" from readme 2024-10-04 12:00:34 -04:00
Joshua Suskalo
030a7413d7
Update changelog 2024-10-04 11:51:54 -04:00
Joshua Suskalo
b702ec4cec
Merge branch 'master' into develop 2024-10-04 11:51:29 -04:00
Kristin Rutenkolk
557cd27763 add write functions for arrays 2024-10-04 16:17:27 +02:00
13 changed files with 1238 additions and 195 deletions

View file

@ -1,6 +1,11 @@
# 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]
### Added
- New `coffi.mem/defstruct` macro to allow the definition of struct types with more performant serdes
- Support for named union members in c-layout (thanks to @jjttjj)
## [1.0.486] - 2024-10-04
### Fixed
- Bug where one too many indirections is used when serializing/deserializing pointer types
@ -149,6 +154,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.486...develop
[1.0.486]: https://github.com/IGJoshua/coffi/compare/v1.0.472...v1.0.486
[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

View file

@ -152,6 +152,7 @@ These features are planned for future releases.
- Improve error messages from defcfn macro
- Mapped memory
- Helper macros for custom serde implementations for composite data types (this is in progress [for structs](https://github.com/IGJoshua/coffi/issues/12)!)
- Support for GraalVM Native Image (once their support for FFM becomes mature)
## License

View file

@ -53,8 +53,7 @@
(b/process {:command-args ["javac"
"src/java/coffi/ffi/Loader.java"
"-d" class-dir
"-target" "22"
"-source" "22"]})]
"--release" "22"]})]
(when-not (zero? (:exit compilation-result))
(b/delete {:path class-dir})))
opts)

View file

@ -1,10 +0,0 @@
{:cljdoc.doc/tree
[["Readme" {:file "README.md"}]
["Changelog" {:file "CHANGELOG.md"}]
["Getting Started" {:file "docs/articles/01-Getting-Started.md"}
["Memory Management" {:file "docs/articles/02-Memory-Management.md"}]
["Built-in Types WIP" {:file "docs/articles/03-Builtin-Types.md"}]
["Custom Types" {:file "docs/articles/04-Custom-Types.md"}]
["Low-Level Wrappers" {:file "docs/articles/05-Low-Level-Wrappers.md"}]]
["Data Model" {:file "docs/articles/50-Data-Model.md"}]
["Benchmarks" {:file "docs/articles/99-Benchmarks.md"}]]}

View file

@ -4,38 +4,38 @@
</div></div><div class="public anchor" id="var-cfn"><h3>cfn</h3><div class="usage"><code>(cfn symbol args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a Clojure function to call the native function referenced by <code>symbol</code>.</p>
<p>The function returned will serialize any passed arguments into the <code>args</code> types, and deserialize the return to the <code>ret</code> type.</p>
<p>If your <code>args</code> and <code>ret</code> are constants, then it is more efficient to call <a href="coffi.ffi.html#var-make-downcall">make-downcall</a> followed by <a href="coffi.ffi.html#var-make-serde-wrapper">make-serde-wrapper</a> because the latter has an inline definition which will result in less overhead from serdes.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L438">view source</a></div></div><div class="public anchor" id="var-const"><h3>const</h3><div class="usage"><code>(const symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Gets the value of a constant stored in <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L606">view source</a></div></div><div class="public anchor" id="var-defcfn"><h3>defcfn</h3><h4 class="type">macro</h4><div class="usage"><code>(defcfn name docstring? attr-map? symbol arg-types ret-type)</code><code>(defcfn name docstring? attr-map? symbol arg-types ret-type native-fn &amp; fn-tail)</code></div><div class="doc"><div class="markdown"><p>Defines a Clojure function which maps to a native function.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L438">view source</a></div></div><div class="public anchor" id="var-const"><h3>const</h3><div class="usage"><code>(const symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Gets the value of a constant stored in <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L606">view source</a></div></div><div class="public anchor" id="var-defcfn"><h3>defcfn</h3><h4 class="type">macro</h4><div class="usage"><code>(defcfn name docstring? attr-map? symbol arg-types ret-type)</code><code>(defcfn name docstring? attr-map? symbol arg-types ret-type native-fn &amp; fn-tail)</code></div><div class="doc"><div class="markdown"><p>Defines a Clojure function which maps to a native function.</p>
<p><code>name</code> is the symbol naming the resulting var. <code>symbol</code> is a symbol or string naming the library symbol to link against. <code>arg-types</code> is a vector of qualified keywords representing the argument types. <code>ret-type</code> is a single qualified keyword representing the return type. <code>fn-tail</code> is the body of the function (potentially with multiple arities) which wraps the native one. Inside the function, <code>native-fn</code> 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.</p>
<p>If no <code>fn-tail</code> is provided, then the resulting function will simply serialize the arguments according to <code>arg-types</code>, call the native function, and deserialize the return value.</p>
<p>The number of args in the <code>fn-tail</code> need not match the number of <code>arg-types</code> for the native function. It need only call the native wrapper function with the correct arguments.</p>
<p>See <a href="coffi.mem.html#var-serialize">serialize</a>, <a href="coffi.mem.html#var-deserialize">deserialize</a>, <a href="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L780">view source</a></div></div><div class="public anchor" id="var-defconst"><h3>defconst</h3><h4 class="type">macro</h4><div class="usage"><code>(defconst symbol docstring? symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Defines a var named by <code>symbol</code> to be the value of the given <code>type</code> from <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L617">view source</a></div></div><div class="public anchor" id="var-defvar"><h3>defvar</h3><h4 class="type">macro</h4><div class="usage"><code>(defvar symbol docstring? symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Defines a var named by <code>symbol</code> to be a reference to the native memory from <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L683">view source</a></div></div><div class="public anchor" id="var-ensure-symbol"><h3>ensure-symbol</h3><div class="usage"><code>(ensure-symbol symbol-or-addr)</code></div><div class="doc"><div class="markdown"><p>Returns the argument if it is a <a href="null">MemorySegment</a>, otherwise calls <a href="coffi.ffi.html#var-find-symbol">find-symbol</a> on it.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L198">view source</a></div></div><div class="public anchor" id="var-find-symbol"><h3>find-symbol</h3><div class="usage"><code>(find-symbol sym)</code></div><div class="doc"><div class="markdown"><p>Gets the <a href="null">MemorySegment</a> of a symbol from the loaded libraries.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L38">view source</a></div></div><div class="public anchor" id="var-freset.21"><h3>freset!</h3><div class="usage"><code>(freset! static-var newval)</code></div><div class="doc"><div class="markdown"><p>Sets the value of <code>static-var</code> to <code>newval</code>, running it through <a href="coffi.mem.html#var-serialize">serialize</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L647">view source</a></div></div><div class="public anchor" id="var-fswap.21"><h3>fswap!</h3><div class="usage"><code>(fswap! static-var f &amp; args)</code></div><div class="doc"><div class="markdown"><p>Non-atomically runs the function <code>f</code> over the value stored in <code>static-var</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L780">view source</a></div></div><div class="public anchor" id="var-defconst"><h3>defconst</h3><h4 class="type">macro</h4><div class="usage"><code>(defconst symbol docstring? symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Defines a var named by <code>symbol</code> to be the value of the given <code>type</code> from <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L617">view source</a></div></div><div class="public anchor" id="var-defvar"><h3>defvar</h3><h4 class="type">macro</h4><div class="usage"><code>(defvar symbol docstring? symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Defines a var named by <code>symbol</code> to be a reference to the native memory from <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L683">view source</a></div></div><div class="public anchor" id="var-ensure-symbol"><h3>ensure-symbol</h3><div class="usage"><code>(ensure-symbol symbol-or-addr)</code></div><div class="doc"><div class="markdown"><p>Returns the argument if it is a <a href="null">MemorySegment</a>, otherwise calls <a href="coffi.ffi.html#var-find-symbol">find-symbol</a> on it.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L198">view source</a></div></div><div class="public anchor" id="var-find-symbol"><h3>find-symbol</h3><div class="usage"><code>(find-symbol sym)</code></div><div class="doc"><div class="markdown"><p>Gets the <a href="null">MemorySegment</a> of a symbol from the loaded libraries.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L38">view source</a></div></div><div class="public anchor" id="var-freset.21"><h3>freset!</h3><div class="usage"><code>(freset! static-var newval)</code></div><div class="doc"><div class="markdown"><p>Sets the value of <code>static-var</code> to <code>newval</code>, running it through <a href="coffi.mem.html#var-serialize">serialize</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L647">view source</a></div></div><div class="public anchor" id="var-fswap.21"><h3>fswap!</h3><div class="usage"><code>(fswap! static-var f &amp; args)</code></div><div class="doc"><div class="markdown"><p>Non-atomically runs the function <code>f</code> over the value stored in <code>static-var</code>.</p>
<p>The value is deserialized before passing it to <code>f</code>, and serialized before putting the value into <code>static-var</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L656">view source</a></div></div><div class="public anchor" id="var-load-library"><h3>load-library</h3><div class="usage"><code>(load-library path)</code></div><div class="doc"><div class="markdown"><p>Loads the library at <code>path</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L33">view source</a></div></div><div class="public anchor" id="var-load-system-library"><h3>load-system-library</h3><div class="usage"><code>(load-system-library libname)</code></div><div class="doc"><div class="markdown"><p>Loads the library named <code>libname</code> from the systems load path.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L28">view source</a></div></div><div class="public anchor" id="var-make-downcall"><h3>make-downcall</h3><div class="usage"><code>(make-downcall symbol-or-addr args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a downcall function reference to <code>symbol-or-addr</code> with the given <code>args</code> and <code>ret</code> types.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L656">view source</a></div></div><div class="public anchor" id="var-load-library"><h3>load-library</h3><div class="usage"><code>(load-library path)</code></div><div class="doc"><div class="markdown"><p>Loads the library at <code>path</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L33">view source</a></div></div><div class="public anchor" id="var-load-system-library"><h3>load-system-library</h3><div class="usage"><code>(load-system-library libname)</code></div><div class="doc"><div class="markdown"><p>Loads the library named <code>libname</code> from the systems load path.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L28">view source</a></div></div><div class="public anchor" id="var-make-downcall"><h3>make-downcall</h3><div class="usage"><code>(make-downcall symbol-or-addr args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a downcall function reference to <code>symbol-or-addr</code> with the given <code>args</code> and <code>ret</code> types.</p>
<p>The function returned takes only arguments whose types match exactly the <a href="coffi.mem.html#var-java-layout">java-layout</a> for that type, and returns an argument with exactly the <a href="coffi.mem.html#var-java-layout">java-layout</a> of the <code>ret</code> type. This function will perform no serialization or deserialization of arguments or the return type.</p>
<p>If the <code>ret</code> type is non-primitive, then the returned function will take a first argument of a <a href="null">SegmentAllocator</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L206">view source</a></div></div><div class="public anchor" id="var-make-serde-varargs-wrapper"><h3>make-serde-varargs-wrapper</h3><div class="usage"><code>(make-serde-varargs-wrapper varargs-factory required-args ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>varargs-factory</code> which produces functions that serialize the arguments and deserialize the return value.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L426">view source</a></div></div><div class="public anchor" id="var-make-serde-wrapper"><h3>make-serde-wrapper</h3><div class="usage"><code>(make-serde-wrapper downcall arg-types ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>downcall</code> which serializes the arguments and deserializes the return value.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L407">view source</a></div></div><div class="public anchor" id="var-make-varargs-factory"><h3>make-varargs-factory</h3><div class="usage"><code>(make-varargs-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Returns a function for constructing downcalls with additional types for arguments.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L206">view source</a></div></div><div class="public anchor" id="var-make-serde-varargs-wrapper"><h3>make-serde-varargs-wrapper</h3><div class="usage"><code>(make-serde-varargs-wrapper varargs-factory required-args ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>varargs-factory</code> which produces functions that serialize the arguments and deserialize the return value.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L426">view source</a></div></div><div class="public anchor" id="var-make-serde-wrapper"><h3>make-serde-wrapper</h3><div class="usage"><code>(make-serde-wrapper downcall arg-types ret-type)</code></div><div class="doc"><div class="markdown"><p>Constructs a wrapper function for the <code>downcall</code> which serializes the arguments and deserializes the return value.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L407">view source</a></div></div><div class="public anchor" id="var-make-varargs-factory"><h3>make-varargs-factory</h3><div class="usage"><code>(make-varargs-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Returns a function for constructing downcalls with additional types for arguments.</p>
<p>The <code>required-args</code> 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.</p>
<p>The returned function is memoized, so that only one downcall function will be generated per combination of argument types.</p>
<p>See <a href="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L222">view source</a></div></div><div class="public anchor" id="var-reify-libspec"><h3>reify-libspec</h3><div class="usage"><code>(reify-libspec libspec)</code></div><div class="doc"><div class="markdown"><p>Loads all the symbols specified in the <code>libspec</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L222">view source</a></div></div><div class="public anchor" id="var-reify-libspec"><h3>reify-libspec</h3><div class="usage"><code>(reify-libspec libspec)</code></div><div class="doc"><div class="markdown"><p>Loads all the symbols specified in the <code>libspec</code>.</p>
<p>The value of each key of the passed map is transformed as by <a href="coffi.ffi.html#var-reify-symbolspec">reify-symbolspec</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L742">view source</a></div></div><div class="public anchor" id="var-reify-symbolspec"><h3>reify-symbolspec</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Takes a spec for a symbol reference and returns a live value for that type.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L701">view source</a></div></div><div class="public anchor" id="var-static-variable"><h3>static-variable</h3><div class="usage"><code>(static-variable symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Constructs a reference to a mutable value stored in <code>symbol-or-addr</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L742">view source</a></div></div><div class="public anchor" id="var-reify-symbolspec"><h3>reify-symbolspec</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Takes a spec for a symbol reference and returns a live value for that type.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L701">view source</a></div></div><div class="public anchor" id="var-static-variable"><h3>static-variable</h3><div class="usage"><code>(static-variable symbol-or-addr type)</code></div><div class="doc"><div class="markdown"><p>Constructs a reference to a mutable value stored in <code>symbol-or-addr</code>.</p>
<p>The returned value can be dereferenced, and has metadata.</p>
<p>See <a href="coffi.ffi.html#var-freset.21">freset!</a>, <a href="coffi.ffi.html#var-fswap.21">fswap!</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L672">view source</a></div></div><div class="public anchor" id="var-static-variable-segment"><h3>static-variable-segment</h3><div class="usage"><code>(static-variable-segment static-var)</code></div><div class="doc"><div class="markdown"><p>Gets the backing <a href="null">MemorySegment</a> from <code>static-var</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L672">view source</a></div></div><div class="public anchor" id="var-static-variable-segment"><h3>static-variable-segment</h3><div class="usage"><code>(static-variable-segment static-var)</code></div><div class="doc"><div class="markdown"><p>Gets the backing <a href="null">MemorySegment</a> from <code>static-var</code>.</p>
<p>This is primarily useful when you need to pass the static variables address to a native function which takes an <a href="null">Addressable</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L664">view source</a></div></div><div class="public anchor" id="var-vacfn-factory"><h3>vacfn-factory</h3><div class="usage"><code>(vacfn-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a varargs factory to call the native function referenced by <code>symbol</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L664">view source</a></div></div><div class="public anchor" id="var-vacfn-factory"><h3>vacfn-factory</h3><div class="usage"><code>(vacfn-factory symbol required-args ret)</code></div><div class="doc"><div class="markdown"><p>Constructs a varargs factory to call the native function referenced by <code>symbol</code>.</p>
<p>The function returned takes any number of type arguments and returns a specialized Clojure function for calling the native function with those arguments.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/ffi.clj#L453">view source</a></div></div></div></body></html>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/ffi.clj#L453">view source</a></div></div></div></body></html>

View file

@ -3,4 +3,4 @@
<html><head><meta charset="UTF-8" /><title>coffi.layout documentation</title><link rel="stylesheet" type="text/css" href="css/default.css" /><link rel="stylesheet" type="text/css" href="css/highlight.css" /><script type="text/javascript" src="js/highlight.min.js"></script><script type="text/javascript" src="js/jquery.min.js"></script><script type="text/javascript" src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div id="header"><h2>Generated by <a href="https://github.com/weavejester/codox">Codox</a></h2><h1><a href="index.html"><span class="project-title"><span class="project-name">coffi</span> <span class="project-version">v1.0.486</span></span></a></h1></div><div class="sidebar primary"><h3 class="no-link"><span class="inner">Project</span></h3><ul class="index-link"><li class="depth-1 "><a href="index.html"><div class="inner">Index</div></a></li></ul><h3 class="no-link"><span class="inner">Topics</span></h3><ul><li class="depth-1 "><a href="01-Getting-Started.html"><div class="inner"><span>Getting Started</span></div></a></li><li class="depth-1 "><a href="02-Memory-Management.html"><div class="inner"><span>Memory Management</span></div></a></li><li class="depth-1 "><a href="03-Builtin-Types.html"><div class="inner"><span>Built-in Types **WIP**</span></div></a></li><li class="depth-1 "><a href="04-Custom-Types.html"><div class="inner"><span>Custom Types</span></div></a></li><li class="depth-1 "><a href="05-Low-Level-Wrappers.html"><div class="inner"><span>Low-Level Wrappers</span></div></a></li><li class="depth-1 "><a href="50-Data-Model.html"><div class="inner"><span>Data Model</span></div></a></li><li class="depth-1 "><a href="99-Benchmarks.html"><div class="inner"><span>Benchmarks **OUTDATED**</span></div></a></li></ul><h3 class="no-link"><span class="inner">Namespaces</span></h3><ul><li class="depth-1"><div class="no-link"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>coffi</span></div></div></li><li class="depth-2 branch"><a href="coffi.ffi.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>ffi</span></div></a></li><li class="depth-2 branch current"><a href="coffi.layout.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>layout</span></div></a></li><li class="depth-2"><a href="coffi.mem.html"><div class="inner"><span class="tree"><span class="top"></span><span class="bottom"></span></span><span>mem</span></div></a></li></ul></div><div class="sidebar secondary"><h3><a href="#top"><span class="inner">Public Vars</span></a></h3><ul><li class="depth-1"><a href="coffi.layout.html#var-with-c-layout"><div class="inner"><span>with-c-layout</span></div></a></li></ul></div><div class="namespace-docs" id="content"><h1 class="anchor" id="top">coffi.layout</h1><div class="doc"><div class="markdown"><p>Functions for adjusting the layout of structs.</p>
</div></div><div class="public anchor" id="var-with-c-layout"><h3>with-c-layout</h3><div class="usage"><code>(with-c-layout struct-spec)</code></div><div class="doc"><div class="markdown"><p>Forces a struct specification to C layout rules.</p>
<p>This will add padding fields between fields to match C alignment requirements.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/layout.clj#L6">view source</a></div></div></div></body></html>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/layout.clj#L6">view source</a></div></div></div></body></html>

View file

@ -5,117 +5,117 @@
<p>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 <a href="coffi.mem.html#var-primitive-type">primitive-type</a> must be overriden to return which primitive type it is serialized as, then <a href="coffi.mem.html#var-serialize*">serialize*</a> and <a href="coffi.mem.html#var-deserialize*">deserialize*</a> should be overriden.</p>
<p>If the native representation of the type is a composite type, like a union, struct, or array, then <a href="coffi.mem.html#var-c-layout">c-layout</a> must be overriden to return the native layout of the type, and <a href="coffi.mem.html#var-serialize-into">serialize-into</a> and <a href="coffi.mem.html#var-deserialize-from">deserialize-from</a> should be overriden to allow marshaling values of the type into and out of memory segments.</p>
</div></div><div class="public anchor" id="var-address-of"><h3>address-of</h3><div class="usage"><code>(address-of addressable)</code></div><div class="doc"><div class="markdown"><p>Gets the address of a given segment as a number.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L108">view source</a></div></div><div class="public anchor" id="var-address.3F"><h3>address?</h3><div class="usage"><code>(address? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if an object is a memory address.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L108">view source</a></div></div><div class="public anchor" id="var-address.3F"><h3>address?</h3><div class="usage"><code>(address? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if an object is a memory address.</p>
<p><code>nil</code> is considered an address.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L126">view source</a></div></div><div class="public anchor" id="var-align-of"><h3>align-of</h3><div class="usage"><code>(align-of type)</code></div><div class="doc"><div class="markdown"><p>The alignment in bytes of the given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L813">view source</a></div></div><div class="public anchor" id="var-alloc"><h3>alloc</h3><div class="usage"><code>(alloc size)</code><code>(alloc size arena)</code><code>(alloc size alignment arena)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L126">view source</a></div></div><div class="public anchor" id="var-align-of"><h3>align-of</h3><div class="usage"><code>(align-of type)</code></div><div class="doc"><div class="markdown"><p>The alignment in bytes of the given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L813">view source</a></div></div><div class="public anchor" id="var-alloc"><h3>alloc</h3><div class="usage"><code>(alloc size)</code><code>(alloc size arena)</code><code>(alloc size alignment arena)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes.</p>
<p>If an <code>arena</code> is provided, the allocation will be reclaimed when it is closed.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L93">view source</a></div></div><div class="public anchor" id="var-alloc-instance"><h3>alloc-instance</h3><div class="usage"><code>(alloc-instance type)</code><code>(alloc-instance type arena)</code></div><div class="doc"><div class="markdown"><p>Allocates a memory segment for the given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L820">view source</a></div></div><div class="public anchor" id="var-alloc-with"><h3>alloc-with</h3><div class="usage"><code>(alloc-with allocator size)</code><code>(alloc-with allocator size alignment)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes using the <code>allocator</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L101">view source</a></div></div><div class="public anchor" id="var-arena-allocator"><h3>arena-allocator</h3><div class="usage"><code>(arena-allocator arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a <a href="null">SegmentAllocator</a> from the given <a href="null">Arena</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L93">view source</a></div></div><div class="public anchor" id="var-alloc-instance"><h3>alloc-instance</h3><div class="usage"><code>(alloc-instance type)</code><code>(alloc-instance type arena)</code></div><div class="doc"><div class="markdown"><p>Allocates a memory segment for the given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L820">view source</a></div></div><div class="public anchor" id="var-alloc-with"><h3>alloc-with</h3><div class="usage"><code>(alloc-with allocator size)</code><code>(alloc-with allocator size alignment)</code></div><div class="doc"><div class="markdown"><p>Allocates <code>size</code> bytes using the <code>allocator</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L101">view source</a></div></div><div class="public anchor" id="var-arena-allocator"><h3>arena-allocator</h3><div class="usage"><code>(arena-allocator arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a <a href="null">SegmentAllocator</a> from the given <a href="null">Arena</a>.</p>
<p>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.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L82">view source</a></div></div><div class="public anchor" id="var-as-segment"><h3>as-segment</h3><div class="usage"><code>(as-segment address)</code><code>(as-segment address size)</code><code>(as-segment address size arena)</code><code>(as-segment address size arena cleanup)</code></div><div class="doc"><div class="markdown"><p>Dereferences an <code>address</code> into a memory segment associated with the <code>arena</code> (default global).</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L158">view source</a></div></div><div class="public anchor" id="var-auto-arena"><h3>auto-arena</h3><div class="usage"><code>(auto-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a new memory arena that is managed by the garbage collector.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L82">view source</a></div></div><div class="public anchor" id="var-as-segment"><h3>as-segment</h3><div class="usage"><code>(as-segment address)</code><code>(as-segment address size)</code><code>(as-segment address size arena)</code><code>(as-segment address size arena cleanup)</code></div><div class="doc"><div class="markdown"><p>Dereferences an <code>address</code> into a memory segment associated with the <code>arena</code> (default global).</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L158">view source</a></div></div><div class="public anchor" id="var-auto-arena"><h3>auto-arena</h3><div class="usage"><code>(auto-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a new memory arena that is managed by the garbage collector.</p>
<p>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.</p>
<p>This type of arena cannot be closed, and therefore should not be created in a <a href="null">with-open</a> clause.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L61">view source</a></div></div><div class="public anchor" id="var-big-endian"><h3>big-endian</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The big-endian <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L61">view source</a></div></div><div class="public anchor" id="var-big-endian"><h3>big-endian</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The big-endian <a href="null">ByteOrder</a>.</p>
<p>See <a href="coffi.mem.html#var-little-endian">little-endian</a>, <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L189">view source</a></div></div><div class="public anchor" id="var-byte-layout"><h3>byte-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a byte in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L207">view source</a></div></div><div class="public anchor" id="var-c-layout"><h3>c-layout</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the layout object for a given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L189">view source</a></div></div><div class="public anchor" id="var-byte-layout"><h3>byte-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a byte in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L207">view source</a></div></div><div class="public anchor" id="var-c-layout"><h3>c-layout</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the layout object for a given <code>type</code>.</p>
<p>If a type is primitive it will return the appropriate primitive layout (see <a href="null">c-prim-layout</a>).</p>
<p>Otherwise, it should return a <a href="null">GroupLayout</a> for the given type.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L731">view source</a></div></div><div class="public anchor" id="var-char-layout"><h3>char-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized char in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L223">view source</a></div></div><div class="public anchor" id="var-clone-segment"><h3>clone-segment</h3><div class="usage"><code>(clone-segment segment)</code><code>(clone-segment segment arena)</code></div><div class="doc"><div class="markdown"><p>Clones the content of <code>segment</code> into a new segment of the same size.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L176">view source</a></div></div><div class="public anchor" id="var-confined-arena"><h3>confined-arena</h3><div class="usage"><code>(confined-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a new arena for use only in this thread.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L731">view source</a></div></div><div class="public anchor" id="var-char-layout"><h3>char-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized char in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L223">view source</a></div></div><div class="public anchor" id="var-clone-segment"><h3>clone-segment</h3><div class="usage"><code>(clone-segment segment)</code><code>(clone-segment segment arena)</code></div><div class="doc"><div class="markdown"><p>Clones the content of <code>segment</code> into a new segment of the same size.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L176">view source</a></div></div><div class="public anchor" id="var-confined-arena"><h3>confined-arena</h3><div class="usage"><code>(confined-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a new arena for use only in this thread.</p>
<p>The memory allocated within this arena is cheap to allocate, like a native stack.</p>
<p>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 <a href="null">with-open</a> clause.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L42">view source</a></div></div><div class="public anchor" id="var-copy-segment"><h3>copy-segment</h3><div class="usage"><code>(copy-segment dest src)</code></div><div class="doc"><div class="markdown"><p>Copies the content to <code>dest</code> from <code>src</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L42">view source</a></div></div><div class="public anchor" id="var-copy-segment"><h3>copy-segment</h3><div class="usage"><code>(copy-segment dest src)</code></div><div class="doc"><div class="markdown"><p>Copies the content to <code>dest</code> from <code>src</code>.</p>
<p>Returns <code>dest</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L169">view source</a></div></div><div class="public anchor" id="var-defalias"><h3>defalias</h3><h4 class="type">macro</h4><div class="usage"><code>(defalias new-type aliased-type)</code></div><div class="doc"><div class="markdown"><p>Defines a type alias from <code>new-type</code> to <code>aliased-type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L169">view source</a></div></div><div class="public anchor" id="var-defalias"><h3>defalias</h3><h4 class="type">macro</h4><div class="usage"><code>(defalias new-type aliased-type)</code></div><div class="doc"><div class="markdown"><p>Defines a type alias from <code>new-type</code> to <code>aliased-type</code>.</p>
<p>This creates needed serialization and deserialization implementations for the aliased type.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L1321">view source</a></div></div><div class="public anchor" id="var-deserialize"><h3>deserialize</h3><div class="usage"><code>(deserialize obj type)</code></div><div class="doc"><div class="markdown"><p>Deserializes an arbitrary type.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L1326">view source</a></div></div><div class="public anchor" id="var-deserialize"><h3>deserialize</h3><div class="usage"><code>(deserialize obj type)</code></div><div class="doc"><div class="markdown"><p>Deserializes an arbitrary type.</p>
<p>For types which have a primitive representation, this deserializes the primitive representation. For types which do not, this deserializes out of a segment.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L1094">view source</a></div></div><div class="public anchor" id="var-deserialize*"><h3>deserialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes a primitive object into a Clojure data structure.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L1094">view source</a></div></div><div class="public anchor" id="var-deserialize*"><h3>deserialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes a primitive object into a Clojure data structure.</p>
<p>This is intended for use with types that are returned as a primitive but which need additional processing before they can be returned.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L1035">view source</a></div></div><div class="public anchor" id="var-deserialize-from"><h3>deserialize-from</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes the given segment into a Clojure data structure.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L1035">view source</a></div></div><div class="public anchor" id="var-deserialize-from"><h3>deserialize-from</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Deserializes the given segment into a Clojure data structure.</p>
<p>For types that serialize to primitives, a default implementation will deserialize the primitive before calling <a href="coffi.mem.html#var-deserialize*">deserialize*</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L972">view source</a></div></div><div class="public anchor" id="var-double-alignment"><h3>double-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized double.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L279">view source</a></div></div><div class="public anchor" id="var-double-layout"><h3>double-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized double in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L231">view source</a></div></div><div class="public anchor" id="var-double-size"><h3>double-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized double.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L255">view source</a></div></div><div class="public anchor" id="var-float-alignment"><h3>float-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized float.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L275">view source</a></div></div><div class="public anchor" id="var-float-layout"><h3>float-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized float in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L227">view source</a></div></div><div class="public anchor" id="var-float-size"><h3>float-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized float.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L251">view source</a></div></div><div class="public anchor" id="var-global-arena"><h3>global-arena</h3><div class="usage"><code>(global-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs the global arena, which will never reclaim its resources.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L972">view source</a></div></div><div class="public anchor" id="var-double-alignment"><h3>double-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized double.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L279">view source</a></div></div><div class="public anchor" id="var-double-layout"><h3>double-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized double in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L231">view source</a></div></div><div class="public anchor" id="var-double-size"><h3>double-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized double.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L255">view source</a></div></div><div class="public anchor" id="var-float-alignment"><h3>float-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized float.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L275">view source</a></div></div><div class="public anchor" id="var-float-layout"><h3>float-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized float in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L227">view source</a></div></div><div class="public anchor" id="var-float-size"><h3>float-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized float.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L251">view source</a></div></div><div class="public anchor" id="var-global-arena"><h3>global-arena</h3><div class="usage"><code>(global-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs the global arena, which will never reclaim its resources.</p>
<p>This arena may be shared across threads, but is intended mainly in cases where memory is allocated with <a href="coffi.mem.html#var-alloc">alloc</a> but is either never freed or whose management is relinquished to a native library, such as when returned from a callback.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L72">view source</a></div></div><div class="public anchor" id="var-int-alignment"><h3>int-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized int.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L267">view source</a></div></div><div class="public anchor" id="var-int-layout"><h3>int-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized int in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L215">view source</a></div></div><div class="public anchor" id="var-int-size"><h3>int-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized int.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L243">view source</a></div></div><div class="public anchor" id="var-java-layout"><h3>java-layout</h3><div class="usage"><code>(java-layout type)</code></div><div class="doc"><div class="markdown"><p>Gets the Java class to an argument of this type for a method handle.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L72">view source</a></div></div><div class="public anchor" id="var-int-alignment"><h3>int-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized int.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L267">view source</a></div></div><div class="public anchor" id="var-int-layout"><h3>int-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized int in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L215">view source</a></div></div><div class="public anchor" id="var-int-size"><h3>int-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized int.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L243">view source</a></div></div><div class="public anchor" id="var-java-layout"><h3>java-layout</h3><div class="usage"><code>(java-layout type)</code></div><div class="doc"><div class="markdown"><p>Gets the Java class to an argument of this type for a method handle.</p>
<p>If a type serializes to a primitive it returns return a Java primitive type. Otherwise, it returns <a href="null">MemorySegment</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L798">view source</a></div></div><div class="public anchor" id="var-java-prim-layout"><h3>java-prim-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>Map of primitive type names to the Java types for a method handle.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L786">view source</a></div></div><div class="public anchor" id="var-little-endian"><h3>little-endian</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The little-endian <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L798">view source</a></div></div><div class="public anchor" id="var-java-prim-layout"><h3>java-prim-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>Map of primitive type names to the Java types for a method handle.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L786">view source</a></div></div><div class="public anchor" id="var-little-endian"><h3>little-endian</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The little-endian <a href="null">ByteOrder</a>.</p>
<p>See <a href="coffi.mem.html#var-big-endian">big-endian</a>, <a href="coffi.mem.html#var-native-endian">native-endian</a></p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L195">view source</a></div></div><div class="public anchor" id="var-long-alignment"><h3>long-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized long.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L271">view source</a></div></div><div class="public anchor" id="var-long-layout"><h3>long-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized long in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L219">view source</a></div></div><div class="public anchor" id="var-long-size"><h3>long-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized long.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L247">view source</a></div></div><div class="public anchor" id="var-native-endian"><h3>native-endian</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">ByteOrder</a> for the native endianness of the current hardware.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L195">view source</a></div></div><div class="public anchor" id="var-long-alignment"><h3>long-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized long.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L271">view source</a></div></div><div class="public anchor" id="var-long-layout"><h3>long-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized long in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L219">view source</a></div></div><div class="public anchor" id="var-long-size"><h3>long-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized long.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L247">view source</a></div></div><div class="public anchor" id="var-native-endian"><h3>native-endian</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">ByteOrder</a> for the native endianness of the current hardware.</p>
<p>See <a href="coffi.mem.html#var-big-endian">big-endian</a>, <a href="coffi.mem.html#var-little-endian">little-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L201">view source</a></div></div><div class="public anchor" id="var-null"><h3>null</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The NULL pointer object.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L201">view source</a></div></div><div class="public anchor" id="var-null"><h3>null</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The NULL pointer object.</p>
<p>While this object is safe to pass to functions which serialize to a pointer, its generally encouraged to simply pass <code>nil</code>. This value primarily exists to make it easier to write custom types with a primitive pointer representation.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L113">view source</a></div></div><div class="public anchor" id="var-null.3F"><h3>null?</h3><div class="usage"><code>(null? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if a memory address is null.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L121">view source</a></div></div><div class="public anchor" id="var-pointer-alignment"><h3>pointer-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized pointer.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L283">view source</a></div></div><div class="public anchor" id="var-pointer-layout"><h3>pointer-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a native pointer in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L235">view source</a></div></div><div class="public anchor" id="var-pointer-size"><h3>pointer-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized pointer.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L259">view source</a></div></div><div class="public anchor" id="var-primitive-type"><h3>primitive-type</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the primitive type that is used to pass as an argument for the <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L113">view source</a></div></div><div class="public anchor" id="var-null.3F"><h3>null?</h3><div class="usage"><code>(null? addr)</code></div><div class="doc"><div class="markdown"><p>Checks if a memory address is null.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L121">view source</a></div></div><div class="public anchor" id="var-pointer-alignment"><h3>pointer-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized pointer.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L283">view source</a></div></div><div class="public anchor" id="var-pointer-layout"><h3>pointer-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a native pointer in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L235">view source</a></div></div><div class="public anchor" id="var-pointer-size"><h3>pointer-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized pointer.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L259">view source</a></div></div><div class="public anchor" id="var-primitive-type"><h3>primitive-type</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Gets the primitive type that is used to pass as an argument for the <code>type</code>.</p>
<p>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.</p>
<p>Implementations of this method should take into account that type arguments may not always be evaluated before passing to this function.</p>
<p>Returns nil for any type which does not have a primitive representation.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L678">view source</a></div></div><div class="public anchor" id="var-primitive-types"><h3>primitive-types</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>A set of all primitive types.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L668">view source</a></div></div><div class="public anchor" id="var-primitive.3F"><h3>primitive?</h3><div class="usage"><code>(primitive? type)</code></div><div class="doc"><div class="markdown"><p>A predicate to determine if a given type is primitive.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L673">view source</a></div></div><div class="public anchor" id="var-read-address"><h3>read-address</h3><div class="usage"><code>(read-address segment)</code><code>(read-address segment offset)</code></div><div class="doc"><div class="markdown"><p>Reads an address from the <code>segment</code>, at an optional <code>offset</code>, wrapped in a <a href="null">MemorySegment</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L444">view source</a></div></div><div class="public anchor" id="var-read-byte"><h3>read-byte</h3><div class="usage"><code>(read-byte segment)</code><code>(read-byte segment offset)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">byte</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L287">view source</a></div></div><div class="public anchor" id="var-read-char"><h3>read-char</h3><div class="usage"><code>(read-char segment)</code><code>(read-char segment offset)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">char</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L378">view source</a></div></div><div class="public anchor" id="var-read-double"><h3>read-double</h3><div class="usage"><code>(read-double segment)</code><code>(read-double segment offset)</code><code>(read-double segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">double</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L678">view source</a></div></div><div class="public anchor" id="var-primitive-types"><h3>primitive-types</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>A set of all primitive types.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L668">view source</a></div></div><div class="public anchor" id="var-primitive.3F"><h3>primitive?</h3><div class="usage"><code>(primitive? type)</code></div><div class="doc"><div class="markdown"><p>A predicate to determine if a given type is primitive.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L673">view source</a></div></div><div class="public anchor" id="var-read-address"><h3>read-address</h3><div class="usage"><code>(read-address segment)</code><code>(read-address segment offset)</code></div><div class="doc"><div class="markdown"><p>Reads an address from the <code>segment</code>, at an optional <code>offset</code>, wrapped in a <a href="null">MemorySegment</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L444">view source</a></div></div><div class="public anchor" id="var-read-byte"><h3>read-byte</h3><div class="usage"><code>(read-byte segment)</code><code>(read-byte segment offset)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">byte</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L287">view source</a></div></div><div class="public anchor" id="var-read-char"><h3>read-char</h3><div class="usage"><code>(read-char segment)</code><code>(read-char segment offset)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">char</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L378">view source</a></div></div><div class="public anchor" id="var-read-double"><h3>read-double</h3><div class="usage"><code>(read-double segment)</code><code>(read-double segment offset)</code><code>(read-double segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">double</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L419">view source</a></div></div><div class="public anchor" id="var-read-float"><h3>read-float</h3><div class="usage"><code>(read-float segment)</code><code>(read-float segment offset)</code><code>(read-float segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">float</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L419">view source</a></div></div><div class="public anchor" id="var-read-float"><h3>read-float</h3><div class="usage"><code>(read-float segment)</code><code>(read-float segment offset)</code><code>(read-float segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">float</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L394">view source</a></div></div><div class="public anchor" id="var-read-int"><h3>read-int</h3><div class="usage"><code>(read-int segment)</code><code>(read-int segment offset)</code><code>(read-int segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">int</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L394">view source</a></div></div><div class="public anchor" id="var-read-int"><h3>read-int</h3><div class="usage"><code>(read-int segment)</code><code>(read-int segment offset)</code><code>(read-int segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">int</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L328">view source</a></div></div><div class="public anchor" id="var-read-long"><h3>read-long</h3><div class="usage"><code>(read-long segment)</code><code>(read-long segment offset)</code><code>(read-long segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">long</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L328">view source</a></div></div><div class="public anchor" id="var-read-long"><h3>read-long</h3><div class="usage"><code>(read-long segment)</code><code>(read-long segment offset)</code><code>(read-long segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">long</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L353">view source</a></div></div><div class="public anchor" id="var-read-short"><h3>read-short</h3><div class="usage"><code>(read-short segment)</code><code>(read-short segment offset)</code><code>(read-short segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">short</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L353">view source</a></div></div><div class="public anchor" id="var-read-short"><h3>read-short</h3><div class="usage"><code>(read-short segment)</code><code>(read-short segment offset)</code><code>(read-short segment offset byte-order)</code></div><div class="doc"><div class="markdown"><p>Reads a <a href="null">short</a> from the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L303">view source</a></div></div><div class="public anchor" id="var-reinterpret"><h3>reinterpret</h3><div class="usage"><code>(reinterpret segment size)</code><code>(reinterpret segment size arena)</code><code>(reinterpret segment size arena cleanup)</code></div><div class="doc"><div class="markdown"><p>Reinterprets the <code>segment</code> as having the passed <code>size</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L303">view source</a></div></div><div class="public anchor" id="var-reinterpret"><h3>reinterpret</h3><div class="usage"><code>(reinterpret segment size)</code><code>(reinterpret segment size arena)</code><code>(reinterpret segment size arena cleanup)</code></div><div class="doc"><div class="markdown"><p>Reinterprets the <code>segment</code> as having the passed <code>size</code>.</p>
<p>If <code>arena</code> is passed, the scope of the <code>segment</code> is associated with the arena, as well as its access constraints. If <code>cleanup</code> 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 <code>arena</code> is closed.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L140">view source</a></div></div><div class="public anchor" id="var-seq-of"><h3>seq-of</h3><div class="usage"><code>(seq-of type segment)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy sequence of <code>type</code> elements deserialized from <code>segment</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L1106">view source</a></div></div><div class="public anchor" id="var-serialize"><h3>serialize</h3><div class="usage"><code>(serialize obj type)</code><code>(serialize obj type arena)</code></div><div class="doc"><div class="markdown"><p>Serializes an arbitrary type.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L140">view source</a></div></div><div class="public anchor" id="var-seq-of"><h3>seq-of</h3><div class="usage"><code>(seq-of type segment)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy sequence of <code>type</code> elements deserialized from <code>segment</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L1106">view source</a></div></div><div class="public anchor" id="var-serialize"><h3>serialize</h3><div class="usage"><code>(serialize obj type)</code><code>(serialize obj type arena)</code></div><div class="doc"><div class="markdown"><p>Serializes an arbitrary type.</p>
<p>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.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L956">view source</a></div></div><div class="public anchor" id="var-serialize*"><h3>serialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Constructs a serialized version of the <code>obj</code> and returns it.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L956">view source</a></div></div><div class="public anchor" id="var-serialize*"><h3>serialize*</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Constructs a serialized version of the <code>obj</code> and returns it.</p>
<p>Any new allocations made during the serialization should be tied to the given <code>arena</code>, except in extenuating circumstances.</p>
<p>This method should only be implemented for types that serialize to primitives.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L827">view source</a></div></div><div class="public anchor" id="var-serialize-into"><h3>serialize-into</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Writes a serialized version of the <code>obj</code> to the given <code>segment</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L827">view source</a></div></div><div class="public anchor" id="var-serialize-into"><h3>serialize-into</h3><h4 class="type">multimethod</h4><div class="usage"></div><div class="doc"><div class="markdown"><p>Writes a serialized version of the <code>obj</code> to the given <code>segment</code>.</p>
<p>Any new allocations made during the serialization should be tied to the given <code>arena</code>, except in extenuating circumstances.</p>
<p>This method should be implemented for any type which does not override <a href="coffi.mem.html#var-c-layout">c-layout</a>.</p>
<p>For any other type, this will serialize it as <a href="coffi.mem.html#var-serialize*">serialize*</a> before writing the result value into the <code>segment</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L887">view source</a></div></div><div class="public anchor" id="var-shared-arena"><h3>shared-arena</h3><div class="usage"><code>(shared-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a new shared memory arena.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L887">view source</a></div></div><div class="public anchor" id="var-shared-arena"><h3>shared-arena</h3><div class="usage"><code>(shared-arena)</code></div><div class="doc"><div class="markdown"><p>Constructs a new shared memory arena.</p>
<p>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.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L53">view source</a></div></div><div class="public anchor" id="var-short-alignment"><h3>short-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized short.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L263">view source</a></div></div><div class="public anchor" id="var-short-layout"><h3>short-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized short in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L211">view source</a></div></div><div class="public anchor" id="var-short-size"><h3>short-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized short.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L239">view source</a></div></div><div class="public anchor" id="var-size-of"><h3>size-of</h3><div class="usage"><code>(size-of type)</code></div><div class="doc"><div class="markdown"><p>The size in bytes of the given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L806">view source</a></div></div><div class="public anchor" id="var-slice"><h3>slice</h3><div class="usage"><code>(slice segment offset)</code><code>(slice segment offset size)</code></div><div class="doc"><div class="markdown"><p>Get a slice over the <code>segment</code> with the given <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L133">view source</a></div></div><div class="public anchor" id="var-slice-segments"><h3>slice-segments</h3><div class="usage"><code>(slice-segments segment size)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy seq of <code>size</code>-length memory segments, sliced from <code>segment</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L182">view source</a></div></div><div class="public anchor" id="var-write-address"><h3>write-address</h3><div class="usage"><code>(write-address segment value)</code><code>(write-address segment offset value)</code></div><div class="doc"><div class="markdown"><p>Writes the address of the <a href="null">MemorySegment</a> <code>value</code> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L642">view source</a></div></div><div class="public anchor" id="var-write-byte"><h3>write-byte</h3><div class="usage"><code>(write-byte segment value)</code><code>(write-byte segment offset value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">byte</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L460">view source</a></div></div><div class="public anchor" id="var-write-char"><h3>write-char</h3><div class="usage"><code>(write-char segment value)</code><code>(write-char segment offset value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">char</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L562">view source</a></div></div><div class="public anchor" id="var-write-double"><h3>write-double</h3><div class="usage"><code>(write-double segment value)</code><code>(write-double segment offset value)</code><code>(write-double segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">double</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L53">view source</a></div></div><div class="public anchor" id="var-short-alignment"><h3>short-alignment</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The alignment in bytes of a c-sized short.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L263">view source</a></div></div><div class="public anchor" id="var-short-layout"><h3>short-layout</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The <a href="null">MemoryLayout</a> for a c-sized short in <a href="coffi.mem.html#var-native-endian">native-endian</a> <a href="null">ByteOrder</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L211">view source</a></div></div><div class="public anchor" id="var-short-size"><h3>short-size</h3><div class="usage"></div><div class="doc"><div class="markdown"><p>The size in bytes of a c-sized short.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L239">view source</a></div></div><div class="public anchor" id="var-size-of"><h3>size-of</h3><div class="usage"><code>(size-of type)</code></div><div class="doc"><div class="markdown"><p>The size in bytes of the given <code>type</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L806">view source</a></div></div><div class="public anchor" id="var-slice"><h3>slice</h3><div class="usage"><code>(slice segment offset)</code><code>(slice segment offset size)</code></div><div class="doc"><div class="markdown"><p>Get a slice over the <code>segment</code> with the given <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L133">view source</a></div></div><div class="public anchor" id="var-slice-segments"><h3>slice-segments</h3><div class="usage"><code>(slice-segments segment size)</code></div><div class="doc"><div class="markdown"><p>Constructs a lazy seq of <code>size</code>-length memory segments, sliced from <code>segment</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L182">view source</a></div></div><div class="public anchor" id="var-write-address"><h3>write-address</h3><div class="usage"><code>(write-address segment value)</code><code>(write-address segment offset value)</code></div><div class="doc"><div class="markdown"><p>Writes the address of the <a href="null">MemorySegment</a> <code>value</code> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L642">view source</a></div></div><div class="public anchor" id="var-write-byte"><h3>write-byte</h3><div class="usage"><code>(write-byte segment value)</code><code>(write-byte segment offset value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">byte</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L460">view source</a></div></div><div class="public anchor" id="var-write-char"><h3>write-char</h3><div class="usage"><code>(write-char segment value)</code><code>(write-char segment offset value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">char</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L562">view source</a></div></div><div class="public anchor" id="var-write-double"><h3>write-double</h3><div class="usage"><code>(write-double segment value)</code><code>(write-double segment offset value)</code><code>(write-double segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">double</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L614">view source</a></div></div><div class="public anchor" id="var-write-float"><h3>write-float</h3><div class="usage"><code>(write-float segment value)</code><code>(write-float segment offset value)</code><code>(write-float segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">float</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L614">view source</a></div></div><div class="public anchor" id="var-write-float"><h3>write-float</h3><div class="usage"><code>(write-float segment value)</code><code>(write-float segment offset value)</code><code>(write-float segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">float</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L586">view source</a></div></div><div class="public anchor" id="var-write-int"><h3>write-int</h3><div class="usage"><code>(write-int segment value)</code><code>(write-int segment offset value)</code><code>(write-int segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">int</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L586">view source</a></div></div><div class="public anchor" id="var-write-int"><h3>write-int</h3><div class="usage"><code>(write-int segment value)</code><code>(write-int segment offset value)</code><code>(write-int segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">int</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L506">view source</a></div></div><div class="public anchor" id="var-write-long"><h3>write-long</h3><div class="usage"><code>(write-long segment value)</code><code>(write-long segment offset value)</code><code>(write-long segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">long</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L506">view source</a></div></div><div class="public anchor" id="var-write-long"><h3>write-long</h3><div class="usage"><code>(write-long segment value)</code><code>(write-long segment offset value)</code><code>(write-long segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">long</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L534">view source</a></div></div><div class="public anchor" id="var-write-short"><h3>write-short</h3><div class="usage"><code>(write-short segment value)</code><code>(write-short segment offset value)</code><code>(write-short segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">short</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L534">view source</a></div></div><div class="public anchor" id="var-write-short"><h3>write-short</h3><div class="usage"><code>(write-short segment value)</code><code>(write-short segment offset value)</code><code>(write-short segment offset byte-order value)</code></div><div class="doc"><div class="markdown"><p>Writes a <a href="null">short</a> to the <code>segment</code>, at an optional <code>offset</code>.</p>
<p>If <code>byte-order</code> is not provided, it defaults to <a href="coffi.mem.html#var-native-endian">native-endian</a>.</p>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/27d15e19c4d8447e3bedf17abaaf4d2e839a9998/src/clj/coffi/mem.clj#L478">view source</a></div></div></div></body></html>
</div></div><div class="src-link"><a href="https://github.com/IGJoshua/coffi/blob/2d708fa7724cd2055357f37cefb93a6177ddf281/src/clj/coffi/mem.clj#L478">view source</a></div></div></div></body></html>

View file

@ -606,7 +606,7 @@
(defn const
"Gets the value of a constant stored in `symbol-or-addr`."
[symbol-or-addr type]
(mem/deserialize (.address (ensure-symbol symbol-or-addr)) [::mem/pointer type]))
(mem/deserialize (ensure-symbol symbol-or-addr) [::mem/pointer type]))
(s/def ::defconst-args
(s/cat :var-name simple-symbol?

View file

@ -21,11 +21,11 @@
(recur (cond-> (+ offset size)
(pos? r) (+ (- align r)))
(cond-> aligned-fields
(pos? r) (conj [::padding [::mem/padding (- align r)]])
(pos? r) (conj [:coffi.layout/padding [:coffi.mem/padding (- align r)]])
:always (conj field))
fields))
(let [strongest-alignment (reduce max (map (comp mem/align-of second) (nth struct-spec 1)))
r (rem offset strongest-alignment)]
(cond-> aligned-fields
(pos? r) (conj [::padding [::mem/padding (- strongest-alignment r)]])))))]
(pos? r) (conj [:coffi.layout/padding [:coffi.mem/padding (- strongest-alignment r)]])))))]
(assoc struct-spec 1 aligned-fields)))

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
const int c = 42;
const char *s = "Test string";
int add_numbers(int a, int b) {
return a + b;
}
@ -31,6 +34,7 @@ int upcall_test2(int (*f)(void)) {
return f();
}
char *mut_str = NULL;
int counter = 0;
static char* responses[] = { "Hello, world!", "Goodbye friend.", "co'oi prenu" };
@ -96,3 +100,24 @@ void free_variable_length_array(float *arr) {
freed = 1;
free(arr);
}
typedef struct complextype {
Point x;
char y;
int z[4];
char *w;
} ComplexType;
ComplexType complexTypeTest(ComplexType a) {
ComplexType ret = {};
ret.x = a.x;
ret.x.x++;
ret.x.y++;
ret.y = a.y-1;
ret.z[0] = a.z[0];
ret.z[1] = a.z[1];
ret.z[2] = a.z[2];
ret.z[3] = a.z[3];
ret.w = "hello from c";
return ret;
}

View file

@ -3,13 +3,18 @@
[clojure.test :as t]
[coffi.ffi :as ffi]
[coffi.layout :as layout]
[coffi.mem :as mem]))
[coffi.mem :as mem]
[clojure.pprint]))
(ffi/load-library "target/ffi_test.so")
(t/deftest can-load-symbols
(t/is (not (nil? (ffi/find-symbol "add_numbers")))))
(t/deftest can-fetch-constant
(t/is (= 42 (ffi/const "c" ::mem/int)))
(t/is (= "Test string" (ffi/const "s" ::mem/c-string))))
(t/deftest can-call-primitive-fns
(t/is (= 5 ((ffi/cfn "add_numbers" [::mem/int ::mem/int] ::mem/int) 2 3))))
@ -56,6 +61,11 @@
:y 42.0})))
(t/deftest static-variables-are-mutable
(let [mut-str (ffi/static-variable "mut_str" ::mem/c-string)]
(ffi/freset! mut-str nil)
(t/is (nil? @mut-str))
(ffi/freset! mut-str "Hello world!")
(t/is (= "Hello world!" @mut-str)))
(ffi/freset! (ffi/static-variable "counter" ::mem/int) 1)
(t/is (= ((ffi/cfn "get_string1" [] ::mem/c-string))
"Goodbye friend.")))
@ -94,3 +104,33 @@
(free-variable-length-array* floats-addr)))))]
(t/is (not (zero? @freed?)))
(t/is (= floats (mapv #(* (float 1.5) %) (range (count floats)))))))
(mem/defstruct Point [x ::mem/float y ::mem/float])
(t/deftest can-call-with-defstruct
(t/is (= {:x 2.0 :y 2.0}
((ffi/cfn "add_points" [::Point ::Point] ::Point) (Point. 1 2) (Point. 1 0)))))
(mem/defstruct AlignmentTest [a ::mem/char x ::mem/double y ::mem/float])
(t/deftest padding-matches-defstruct
(t/is (= ((ffi/cfn "get_struct" [] ::AlignmentTest))
{:a \x
:x 3.14
:y 42.0})))
(mem/defstruct ComplexType [x ::Point y ::mem/byte z [::mem/array ::mem/int 4 :raw? true] w ::mem/c-string])
(t/deftest can-call-with-complex-defstruct
(t/are [x y] (= x (y ((ffi/cfn "complexTypeTest" [::ComplexType] ::ComplexType)
(ComplexType. (Point. 2 3) 4 (int-array [5 6 7 8]) "hello from clojure"))))
{:x {:x 3.0 :y 4.0} :y 3 :w "hello from c"} #(dissoc % :z)
[5 6 7 8] (comp vec :z)))
(mem/defstruct ComplexTypeWrapped [x ::Point y ::mem/byte z [::mem/array ::mem/int 4] w ::mem/c-string])
(t/deftest can-call-with-wrapped-complex-defstruct
(t/are [x y] (= x (y ((ffi/cfn "complexTypeTest" [::ComplexTypeWrapped] ::ComplexTypeWrapped)
(ComplexTypeWrapped. (Point. 2 3) 4 (int-array [5 6 7 8]) "hello from clojure"))))
{:x {:x 3.0 :y 4.0} :y 3 :w "hello from c"} #(dissoc % :z)
[5 6 7 8] (comp vec :z)))

View file

@ -2,7 +2,6 @@
(:require
[clojure.test :as t]
[coffi.ffi :as ffi]
[coffi.layout :as layout]
[coffi.mem :as mem])
(:import
(java.lang.foreign
@ -29,4 +28,108 @@
(t/is
(instance? MemorySegment (mem/serialize "this is a string" ::mem/c-string))))
(t/deftest can-define-struct
(t/is
(eval
`(mem/defstruct ~'TestType [~'a ::mem/int ~'b ::mem/byte]))))
(mem/defstruct TestType [a ::mem/int b ::mem/byte c ::mem/short])
(t/deftest can-initialize-struct
(t/is (TestType. 5 10 15)))
(t/deftest can-use-common-map-functions
(let [v1 (TestType. 5 10 15)
v2 (TestType. 6 11 16)]
(t/are [x y] (= x (y v1))
5 :a
10 :b
15 :c
5 (fn [v] (v :a))
10 (fn [v] (v :b))
15 (fn [v] (v :c))
5 #(get % :a)
10 #(get % :b)
15 #(get % :c)
20 #(get % :d 20)
nil #(get % :d)
[:a :b :c] keys
[5 10 15] vals
{:a 5 :c 15} #(dissoc % :b)
{:a 5 :b 10 :c 0} #(assoc % :c 0)
{:a 5 :b 10 :c 15 :d 20} #(assoc % :d 20)
[[:a 5] [:b 10] [:c 15]] seq
{:a 5 :b 10 :c 15 :d 20} #(merge % {:d 20})
{:a [5 6] :b [10 11] :c [15 16]} #(merge-with vector % {:a 6 :b 11 :c 16})
{:a [5 6] :b [10 11] :c [15 16]} #(merge-with vector % v2)
[:a 5] #(find % :a)
nil #(find % :d)
{:a 5 :b 10 :c 15} identity
v1 identity
v1 (fn [s] {:a 5 :b 10 :c 15}))))
(t/deftest can-serialize-struct-type
(t/is
(instance? MemorySegment (mem/serialize (TestType. 5 10 15) ::TestType))))
(t/deftest can-deserialize-struct-type
(t/is
(= {:a 5 :b 10 :c 15}
(mem/deserialize (mem/serialize (TestType. 5 10 15) ::TestType) ::TestType))))
(mem/defstruct NestedTestType [x ::mem/int y ::mem/byte z ::TestType])
(t/deftest can-instantiated-nested-structs
(t/is
(= {:x 5 :y 6 :z {:a 5 :b 10 :c 15}}
(NestedTestType. 5 6 (TestType. 5 10 15)))))
(t/deftest can-define-structs-with-array-members
(t/is
(eval
`(mem/defstruct ~'ArrayTestType [~'x ::mem/int ~'y ::mem/byte ~'z [::mem/array ::mem/int 4 :raw? true]]))))
(mem/defstruct ArrayTestType [x ::mem/int y ::mem/byte z [::mem/array ::mem/int 4 :raw? true]])
(t/deftest can-instantiated-array-member-structs
(t/are [x y z] (z x (y (ArrayTestType. 5 6 (int-array [1 2 3 4]))))
{:x 5 :y 6} #(dissoc % :z) =
(int-array [1 2 3 4]) :z java.util.Arrays/equals))
(t/deftest can-serialize-array-struct
(t/is
(= [5 6 1 2 3 4]
(vec (filter #(not= 0 %) (vec (.toArray (mem/serialize (ArrayTestType. 5 6 (int-array [1 2 3 4])) ::ArrayTestType) mem/byte-layout)))))))
(t/deftest can-serialize-deserialize-array-struct
(t/is
(java.util.Arrays/equals
(int-array [1 2 3 4])
(.z (mem/deserialize (mem/serialize (ArrayTestType. 5 6 (int-array [1 2 3 4])) ::ArrayTestType) ::ArrayTestType)))))
(mem/defstruct ComplexTestType [x [::mem/array ::ArrayTestType 4 :raw? true] y ::mem/byte z [::mem/array ::mem/int 4 :raw? true] w ::NestedTestType])
(t/deftest can-serialize-deserialize-complex-struct-type
(t/is
(let [x (object-array (map #(ArrayTestType. % % (int-array (range 4))) (range 4)))
y 12
z (int-array (range 4))
w (NestedTestType. 5 6 (TestType. 5 10 15))]
(->
(ComplexTestType. x y z w)
(mem/serialize ::ComplexTestType)
(mem/deserialize ::ComplexTestType)))))
(mem/defstruct ComplexTestTypeWrapped [x [::mem/array ::ArrayTestType 4] y ::mem/byte z [::mem/array ::mem/int 4] w ::NestedTestType])
(t/deftest can-serialize-deserialize-complex-wrapped-struct-type
(t/is
(let [x (vec (map #(ArrayTestType. % % (int-array (range 4))) (range 4)))
y 12
z (vec (range 4))
w (NestedTestType. 5 6 (TestType. 5 10 15))]
(->
(ComplexTestTypeWrapped. x y z w)
(mem/serialize ::ComplexTestTypeWrapped)
(mem/deserialize ::ComplexTestTypeWrapped)))))