413 lines
16 KiB
HTML
413 lines
16 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<title>foreign-c a portable foreign function interface for
|
||
R7RS - 0.10.0</title>
|
||
<style>
|
||
table { width: 250%; }
|
||
nav { float: left; width: 20%;}
|
||
main { float: right; width: 80%; }
|
||
pre { background-color: lightgrey; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<h1 id="foreign-c">foreign-c</h1>
|
||
<p>foreign-c is a C foreign function interface (FFI) library for
|
||
R7RS. It is portable in the sense that it supports multiple
|
||
implementations, as opposed to being portable by conforming to
|
||
some specification.</p>
|
||
<p><a
|
||
href="https://todo.sr.ht/~retropikzel/r7rs-pffi">Project</a></p>
|
||
<p><a href="https://sr.ht/~retropikzel/r7rs-pffi/trackers">Issue
|
||
trackers</a></p>
|
||
<p><a href="https://sr.ht/~retropikzel/r7rs-pffi/lists">Maling
|
||
lists</a></p>
|
||
<p><a
|
||
href="https://jenkins.scheme.org/job/r7rs_pffi/job/r7rs-pffi/">Jenkins</a></p>
|
||
<ul>
|
||
<li><a href="#installation">Installation</a></li>
|
||
<li><a href="#documentation">Documentation</a>
|
||
<ul>
|
||
<li><a href="#types">Types</a></li>
|
||
<li><a href="#primitives">Primitives</a></li>
|
||
<li><a href="#c-bytevector">c-bytevector</a></li>
|
||
<li><a href="#environment-variables">Environment
|
||
variables</a></li>
|
||
</ul></li>
|
||
</ul>
|
||
<h2 id="implementation-support-tables">Implementation support
|
||
tables</h2>
|
||
<h3 id="primitives-1">Primitives 1</h3>
|
||
<table>
|
||
<colgroup>
|
||
<col style="width: 13%" />
|
||
<col style="width: 10%" />
|
||
<col style="width: 16%" />
|
||
<col style="width: 15%" />
|
||
<col style="width: 16%" />
|
||
<col style="width: 11%" />
|
||
<col style="width: 16%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="header">
|
||
<th></th>
|
||
<th style="text-align: center;">c-size-of</th>
|
||
<th style="text-align: center;">c-bytevector-u8-set!</th>
|
||
<th style="text-align: center;">c-bytevector-u8-ref</th>
|
||
<th style="text-align: center;">define-c-library</th>
|
||
<th style="text-align: center;">c-bytevector?</th>
|
||
<th style="text-align: center;">define-c-procedure</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td><strong>Chibi</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Chicken</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td><strong>Gauche</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Guile</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td><strong>Kawa</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Mosh</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td><strong>Racket</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Saggittarius</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td><strong>Stklos</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Ypsilon</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h3 id="primitives-2">Primitives 2</h3>
|
||
<table>
|
||
<thead>
|
||
<tr class="header">
|
||
<th></th>
|
||
<th style="text-align: center;">define-c-callback</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td>Chibi</td>
|
||
<td style="text-align: center;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Chicken</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Gauche</td>
|
||
<td style="text-align: center;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Guile</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Kawa</td>
|
||
<td style="text-align: center;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Mosh</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td><strong>Racket</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Saggittarius</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Stklos</td>
|
||
<td style="text-align: center;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Ypsilon</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h3 id="test-files-pass">Test files pass</h3>
|
||
<table>
|
||
<thead>
|
||
<tr class="header">
|
||
<th></th>
|
||
<th style="text-align: center;">primitives.scm</th>
|
||
<th style="text-align: center;">addressof.scm</th>
|
||
<th style="text-align: right;">callback.scm</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="odd">
|
||
<td>Chibi</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Chicken</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Gauche</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Guile</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Kawa</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td>Mosh</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Racket</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;"></td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td><strong>Saggittarius</strong></td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;">X</td>
|
||
</tr>
|
||
<tr class="odd">
|
||
<td>Stklos</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
<tr class="even">
|
||
<td>Ypsilon</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: center;">X</td>
|
||
<td style="text-align: right;"></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h3 id="installation">Installation</h3>
|
||
<p>Either download the latest release from <a
|
||
href="https://git.sr.ht/~retropikzel/foreign-c/refs">https://git.sr.ht/~retropikzel/foreign-c/refs</a>
|
||
or git clone , preferably with a tag, and copy the “foreign”
|
||
directory to your library directory.</p>
|
||
<p>As an example assuming you have a project and your libraries
|
||
live in directory called snow in it:</p>
|
||
<pre><code>git clone https://git.sr.ht/~retropikzel/foreign-c --branch LATEST_VERSION
|
||
mkdir -p snow
|
||
cp -r foreign-c/foreign snow/
|
||
make -C snow/foreign/c <SCHEME_IMPLEMENTATION_NAME></code></pre>
|
||
<p>With most implementations the make command does not compile
|
||
anything. When that is the case it will say “Nothing to build on
|
||
SCHEME_IMPLEMENTATION_NAME.”</p>
|
||
<h2 id="documentation">Documentation</h2>
|
||
<h3 id="types">Types</h3>
|
||
<p>Types are given as symbols, for example ’int8 or
|
||
’pointer.</p>
|
||
<ul>
|
||
<li>int8</li>
|
||
<li>uint8</li>
|
||
<li>int16</li>
|
||
<li>uint16</li>
|
||
<li>int32</li>
|
||
<li>uint32</li>
|
||
<li>int64</li>
|
||
<li>uint64</li>
|
||
<li>char</li>
|
||
<li>unsigned-char</li>
|
||
<li>short</li>
|
||
<li>unsigned-short</li>
|
||
<li>int</li>
|
||
<li>unsigned-int</li>
|
||
<li>long</li>
|
||
<li>unsigned-long</li>
|
||
<li>float</li>
|
||
<li>double</li>
|
||
<li>pointer</li>
|
||
<li>callback
|
||
<ul>
|
||
<li>Callback function</li>
|
||
</ul></li>
|
||
</ul>
|
||
<h3 id="primitives">Primitives</h3>
|
||
<p>(<strong>c-type-size</strong> <em>type</em>)</p>
|
||
<p>Returns the size of given C type.</p>
|
||
<p>(<strong>define-c-library</strong> <em>scheme-name</em>
|
||
<em>headers</em> <em>object-name</em> <em>options</em>)</p>
|
||
<p>Takes a scheme-name to bind the library to, list of C headers
|
||
as strings, shared-object name and options.</p>
|
||
<p>The C header strings should not contain “<” or “>”,
|
||
they are added automatically.</p>
|
||
<p>The name of the shared object should not contain suffix like
|
||
.so or .dll. Nor should it contain any prefix like “lib”.</p>
|
||
<p>The options are:</p>
|
||
<ul>
|
||
<li>additional-versions
|
||
<ul>
|
||
<li>Search for additional versions of shared object, given
|
||
shared object “c” and additional versions “6” “7” on linux the
|
||
files “libc”, “libc.6”, “libc.7” are searched for.</li>
|
||
<li>Can be either numbers or strings</li>
|
||
</ul></li>
|
||
<li>additional-paths
|
||
<ul>
|
||
<li>Give additional paths to search shared objects from</li>
|
||
</ul></li>
|
||
</ul>
|
||
<p>Example:</p>
|
||
<pre><code>(cond-expand
|
||
(windows (define-c-library libc-stdlib
|
||
'("stdlib.h")
|
||
"ucrtbase"
|
||
'((additional-versions ("0" "6"))
|
||
(additiona-paths (".")))))
|
||
(else (define-c-library libc-stdlib
|
||
(list "stdlib.h")
|
||
"c"
|
||
'((additional-versions ("0" "6"))
|
||
(additiona-paths ("."))))))</code></pre>
|
||
<h4 id="notes">Notes</h4>
|
||
<ul>
|
||
<li>Do not cond-expand inside the arguments, that might lead to
|
||
problems on some implementations.</li>
|
||
<li>Do not store options in variables, that might lead to
|
||
problems on some implementations.</li>
|
||
<li>Do pass the headers using quote
|
||
<ul>
|
||
<li>As ’(… and not (list…</li>
|
||
</ul></li>
|
||
<li>Do pass the options using quote
|
||
<ul>
|
||
<li>As ’(… and not (list… define-c-procedure define-c-callback
|
||
c-bytevector? c-bytevector-u8-set! c-bytevector-u8-ref
|
||
c-bytevector-pointer-set! c-bytevector-pointer-ref</li>
|
||
</ul></li>
|
||
</ul>
|
||
<h3 id="c-bytevector">c-bytevector</h3>
|
||
<p>make-c-bytevector make-c-null c-null? c-free
|
||
native-endianness c-bytevector-s8-set! c-bytevector-s8-ref
|
||
c-bytevector-s16-set! c-bytevector-s16-ref
|
||
c-bytevector-s16-native-set! c-bytevector-s16-native-ref
|
||
c-bytevector-u16-set! c-bytevector-u16-ref
|
||
c-bytevector-u16-native-set! c-bytevector-u16-native-ref
|
||
c-bytevector-s32-set! c-bytevector-s32-ref
|
||
c-bytevector-s32-native-set! c-bytevector-s32-native-ref
|
||
c-bytevector-u32-set! c-bytevector-u32-ref
|
||
c-bytevector-u32-native-set! c-bytevector-u32-native-ref
|
||
c-bytevector-s64-set! c-bytevector-s64-ref
|
||
c-bytevector-s64-native-set! c-bytevector-s64-native-ref
|
||
c-bytevector-u64-set! c-bytevector-u64-ref
|
||
c-bytevector-u64-native-set! c-bytevector-u64-native-ref
|
||
c-bytevector-sint-set! c-bytevector-sint-ref
|
||
c-bytevector-uint-set! c-bytevector-uint-ref
|
||
c-bytevector-ieee-single-set!
|
||
c-bytevector-ieee-single-native-set!
|
||
c-bytevector-ieee-single-ref c-bytevector-ieee-single-native-ref
|
||
c-bytevector-ieee-double-set!
|
||
c-bytevector-ieee-double-native-set!
|
||
c-bytevector-ieee-double-ref c-bytevector-ieee-double-native-ref
|
||
bytevector->c-bytevector c-bytevector->bytevector
|
||
call-with-address-of</p>
|
||
<p>string->c-utf8 c-utf8->string</p>
|
||
<h3 id="environment-variables">Environment variables</h3>
|
||
<p>Setting environment variables like this on Windows works for
|
||
this library:</p>
|
||
<pre><code>set "PFFI_LOAD_PATH=C:\Program Files (x86)/foo/bar"</code></pre>
|
||
<h4 id="pffi_load_path">PFFI_LOAD_PATH</h4>
|
||
<p>To add more paths to where pffi looks for libraries set
|
||
PFFI_LOAD_PATH to paths separated by ; on windows, and : on
|
||
other operating systems.</p>
|
||
</body>
|
||
</html>
|