<html><head><metacharset="UTF-8"/><title>coffi.ffi documentation</title><linkrel="stylesheet"type="text/css"href="css/default.css"/><linkrel="stylesheet"type="text/css"href="css/highlight.css"/><scripttype="text/javascript"src="js/highlight.min.js"></script><scripttype="text/javascript"src="js/jquery.min.js"></script><scripttype="text/javascript"src="js/page_effects.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><divid="header"><h2>Generated by <ahref="https://github.com/weavejester/codox">Codox</a></h2><h1><ahref="index.html"><spanclass="project-title"><spanclass="project-name">coffi</span><spanclass="project-version">v0.5.357</span></span></a></h1></div><divclass="sidebar primary"><h3class="no-link"><spanclass="inner">Project</span></h3><ulclass="index-link"><liclass="depth-1 "><ahref="index.html"><divclass="inner">Index</div></a></li></ul><h3class="no-link"><spanclass="inner">Namespaces</span></h3><ul><liclass="depth-1"><divclass="no-link"><divclass="inner"><spanclass="tree"><spanclass="top"></span><spanclass="bottom"></span></span><span>coffi</span></div></div></li><liclass="depth-2 branch current"><ahref="coffi.ffi.html"><divclass="inner"><spanclass="tree"><spanclass="top"></span><spanclass="bottom"></span></span><span>ffi</span></div></a></li><liclass="depth-2 branch"><ahref="coffi.layout.html"><divclass="inner"><spanclass="tree"><spanclass="top"></span><spanclass="bottom"></span></span><span>layout</span></div></a></li><liclass="depth-2"><ahref="coffi.mem.html"><divclass="inner"><spanclass="tree"><spanclass="top"></span><spanclass="bottom"></span></span><span>mem</span></div></a></li></ul></div><divclass="sidebar secondary"><h3><ahref="#top"><spanclass="inner">Public Vars</span></a></h3><ul><liclass="depth-1"><ahref="coffi.ffi.html#var-cfn"><divclass="inner"><span>cfn</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-const"><divclass="inner"><span>const</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-defcfn"><divclass="inner"><span>defcfn</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-find-symbol"><divclass="inner"><span>find-symbol</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-freset.21"><divclass="inner"><span>freset!</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-fswap.21"><divclass="inner"><span>fswap!</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-load-library"><divclass="inner"><span>load-library</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-load-system-library"><divclass="inner"><span>load-system-library</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-make-downcall"><divclass="inner"><span>make-downcall</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-make-serde-varargs-wrapper"><divclass="inner"><span>make-serde-varargs-wrapper</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-make-serde-wrapper"><divclass="inner"><span>make-serde-wrapper</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-make-varargs-factory"><divclass="inner"><span>make-varargs-factory</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-reify-libspec"><divclass="inner"><span>reify-libspec</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-reify-symbolspec"><divclass="inner"><span>reify-symbolspec</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-static-variable"><divclass="inner"><span>static-variable</span></div></a></li><liclass="depth-1"><ahref="coffi.ffi.html#var-vacfn-factory"><divclass="inner"><span>vacfn-factory</span></div></a></li></ul></div><divclass="namespace-docs"id="content"><h1class="anchor"id="top">coffi.ffi</h1><divclass="doc"><divclass="markdown"><p>Functions for creating handles to native functions and loading native libraries.</p></div></div><divclass="public anchor"id="var-cfn"><h3>cfn</h3><divclass="usage"><code>(cfn symbol
<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 <ahref="coffi.ffi.html#var-make-downcall">make-downcall</a> followed by <ahref="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><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L421">view source</a></div></div><divclass="public anchor"id="var-const"><h3>const</h3><divclass="usage"><code>(const symbol-or-addr type)</code></div><divclass="doc"><divclass="markdown"><p>Gets the value of a constant stored in <code>symbol-or-addr</code>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L565">view source</a></div></div><divclass="public anchor"id="var-defcfn"><h3>defcfn</h3><h4class="type">macro</h4><divclass="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 & fn-tail)</code></div><divclass="doc"><divclass="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 <ahref="coffi.mem.html#var-serialize">serialize</a>, <ahref="coffi.mem.html#var-deserialize">deserialize</a>, <ahref="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L701">view source</a></div></div><divclass="public anchor"id="var-find-symbol"><h3>find-symbol</h3><divclass="usage"><code>(find-symbol sym)</code></div><divclass="doc"><divclass="markdown"><p>Gets the <ahref="null">NativeSymbol</a> of a symbol from the loaded libraries.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L37">view source</a></div></div><divclass="public anchor"id="var-freset.21"><h3>freset!</h3><divclass="usage"><code>(freset! static-var newval)</code></div><divclass="doc"><divclass="markdown"><p>Sets the value of <code>static-var</code> to <code>newval</code>, running it through <ahref="coffi.mem.html#var-serialize">serialize</a>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L587">view source</a></div></div><divclass="public anchor"id="var-fswap.21"><h3>fswap!</h3><divclass="usage"><code>(fswap! static-var f & args)</code></div><divclass="doc"><divclass="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><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L596">view source</a></div></div><divclass="public anchor"id="var-load-library"><h3>load-library</h3><divclass="usage"><code>(load-library path)</code></div><divclass="doc"><divclass="markdown"><p>Loads the library at <code>path</code>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L32">view source</a></div></div><divclass="public anchor"id="var-load-system-library"><h3>load-system-library</h3><divclass="usage"><code>(load-system-library libname)</code></div><divclass="doc"><divclass="markdown"><p>Loads the library named <code>libname</code> from the system’s load path.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L27">view source</a></div></div><divclass="public anchor"id="var-make-downcall"><h3>make-downcall</h3><divclass="usage"><code>(make-downcall symbol-or-addr args ret)</code></div><divclass="doc"><divclass="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 <ahref="coffi.mem.html#var-java-layout">java-layout</a> for that type, and returns an argument with exactly the <ahref="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 <ahref="null">SegmentAllocator</a>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L198">view source</a></div></div><divclass="public anchor"id="var-make-serde-varargs-wrapper"><h3>make-serde-varargs-wrapper</h3><divclass="usage"><code>(make-serde-varargs-wrapper varargs-factory required-args ret-type)</code></div><divclass="doc"><divclass="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><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L409">view source</a></div></div><divclass="public anchor"id="var-make-serde-wrapper"><h3>make-serde-wrapper</h3><divclass="usage"><code>(make-serde-wrapper downcall arg-types ret-type)</code></div><divclass="doc"><divclass="markdown"><p>Constructs a wrapper function for the <code>downcall</code> which serializes the arguments and deserializes the return value.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L390">view source</a></div></div><divclass="public anchor"id="var-make-varargs-factory"><h3>make-varargs-factory</h3><divclass="usage"><code>(make-varargs-factory symbol required-args ret)</code></div><divclass="doc"><divclass="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 <ahref="coffi.ffi.html#var-make-downcall">make-downcall</a>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L214">view source</a></div></div><divclass="public anchor"id="var-reify-libspec"><h3>reify-libspec</h3><divclass="usage"><code>(reify-libspec libspec)</code></div><divclass="doc"><divclass="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 <ahref="coffi.ffi.html#var-reify-symbolspec">reify-symbolspec</a>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L663">view source</a></div></div><divclass="public anchor"id="var-reify-symbolspec"><h3>reify-symbolspec</h3><h4class="type">multimethod</h4><divclass="usage"></div><divclass="doc"><divclass="markdown"><p>Takes a spec for a symbol reference and returns a live value for that type.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L622">view source</a></div></div><divclass="public anchor"id="var-static-variable"><h3>static-variable</h3><divclass="usage"><code>(static-variable symbol-or-addr type)</code></div><divclass="doc"><divclass="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, and the address of the value can be queried with <ahref="coffi.mem.html#var-address-of">address-of</a>.</p>
<p>See <ahref="coffi.ffi.html#var-freset.21">freset!</a>, <ahref="coffi.ffi.html#var-fswap.21">fswap!</a>.</p></div></div><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L604">view source</a></div></div><divclass="public anchor"id="var-vacfn-factory"><h3>vacfn-factory</h3><divclass="usage"><code>(vacfn-factory symbol required-args ret)</code></div><divclass="doc"><divclass="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><divclass="src-link"><ahref="https://github.com/IGJoshua/coffi/blob/e98c5a56bb4699035ebf3b3b49a8e89f8edbe087/src/clj/coffi/ffi.clj#L435">view source</a></div></div></div></body></html>