/usr/share/doc/cl-cffi/spec/cffi-sys-spec.html is in cl-cffi 20100219-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | <html lang="en">
<head>
<title>CFFI-SYS Interface Specification</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="CFFI-SYS Interface Specification">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="top" href="#Top">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 2005-2006, James Bielman <jamesjb at jamesjb.com>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
body {font-family: century schoolbook, serif;
line-height: 1.3;
padding-left: 5em; padding-right: 1em;
padding-bottom: 1em; max-width: 60em;}
table {border-collapse: collapse}
span.roman { font-family: century schoolbook, serif; font-weight: normal; }
h1, h2, h3, h4, h5, h6 {font-family: Helvetica, sans-serif}
h4 { margin-top: 2.5em; }
dfn {font-family: inherit; font-variant: italic; font-weight: bolder }
kbd {font-family: monospace; text-decoration: underline}
/*var {font-family: Helvetica, sans-serif; font-variant: slanted}*/
var {font-variant: slanted;}
td {padding-right: 1em; padding-left: 1em}
sub {font-size: smaller}
.node {padding: 0; margin: 0}
.lisp { font-family: monospace;
background-color: #F4F4F4; border: 1px solid #AAA;
padding-top: 0.5em; padding-bottom: 0.5em; }
/* coloring */
.lisp-bg { background-color: #F4F4F4 ; color: black; }
.lisp-bg:hover { background-color: #F4F4F4 ; color: black; }
.symbol { font-weight: bold; color: #770055; background-color : transparent; border: 0px; margin: 0px;}
a.symbol:link { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
a.symbol:active { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
a.symbol:visited { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
a.symbol:hover { font-weight: bold; color : #229955; background-color : transparent; text-decoration: none; border: 0px; margin: 0px; }
.special { font-weight: bold; color: #FF5000; background-color: inherit; }
.keyword { font-weight: bold; color: #770000; background-color: inherit; }
.comment { font-weight: normal; color: #007777; background-color: inherit; }
.string { font-weight: bold; color: #777777; background-color: inherit; }
.character { font-weight: bold; color: #0055AA; background-color: inherit; }
.syntaxerror { font-weight: bold; color: #FF0000; background-color: inherit; }
span.paren1 { font-weight: bold; color: #777777; }
span.paren1:hover { color: #777777; background-color: #BAFFFF; }
span.paren2 { color: #777777; }
span.paren2:hover { color: #777777; background-color: #FFCACA; }
span.paren3 { color: #777777; }
span.paren3:hover { color: #777777; background-color: #FFFFBA; }
span.paren4 { color: #777777; }
span.paren4:hover { color: #777777; background-color: #CACAFF; }
span.paren5 { color: #777777; }
span.paren5:hover { color: #777777; background-color: #CAFFCA; }
span.paren6 { color: #777777; }
span.paren6:hover { color: #777777; background-color: #FFBAFF; }
--></style>
</head>
<body>
<h1 class="settitle">CFFI-SYS Interface Specification</h1>
<div class="contents">
<h2>Table of Contents</h2>
<ul>
<li><a name="toc_Top" href="#Top">cffi-sys</a>
<li><a name="toc_Introduction" href="#Introduction">1 Introduction</a>
<li><a name="toc_Built_002dIn-Foreign-Types" href="#Built_002dIn-Foreign-Types">2 Built-In Foreign Types</a>
<li><a name="toc_Operations-on-Foreign-Types" href="#Operations-on-Foreign-Types">3 Operations on Built-in Foreign Types</a>
<li><a name="toc_Basic-Pointer-Operations" href="#Basic-Pointer-Operations">4 Basic Pointer Operations</a>
<li><a name="toc_Foreign-Memory-Allocation" href="#Foreign-Memory-Allocation">5 Foreign Memory Allocation</a>
<li><a name="toc_Memory-Access" href="#Memory-Access">6 Memory Access</a>
<li><a name="toc_Foreign-Function-Calling" href="#Foreign-Function-Calling">7 Foreign Function Calling</a>
<li><a name="toc_Loading-Foreign-Libraries" href="#Loading-Foreign-Libraries">8 Loading Foreign Libraries</a>
<li><a name="toc_Foreign-Globals" href="#Foreign-Globals">9 Foreign Globals</a>
<li><a name="toc_Symbol-Index" href="#Symbol-Index">Symbol Index</a>
</li></ul>
</div>
<div class="node">
<a name="Top"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Introduction">Introduction</a>,
Up: <a rel="up" accesskey="u" href="#dir">(dir)</a>
</div>
<h2 class="unnumbered">cffi-sys</h2>
<p>Copyright © 2005-2006, James Bielman <jamesjb at jamesjb.com>
<blockquote>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
<p>The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
<p><span class="sc">The software is provided “as is”, without warranty of any kind,
express or implied, including but not limited to the warranties of
merchantability, fitness for a particular purpose and
noninfringement. In no event shall the authors or copyright
holders be liable for any claim, damages or other liability,
whether in an action of contract, tort or otherwise, arising from,
out of or in connection with the software or the use or other
dealings in the software.</span>
</blockquote>
<ul class="menu">
<li><a accesskey="1" href="#Introduction">Introduction</a>
<li><a accesskey="2" href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a>
<li><a accesskey="3" href="#Operations-on-Foreign-Types">Operations on Foreign Types</a>
<li><a accesskey="4" href="#Basic-Pointer-Operations">Basic Pointer Operations</a>
<li><a accesskey="5" href="#Foreign-Memory-Allocation">Foreign Memory Allocation</a>
<li><a accesskey="6" href="#Memory-Access">Memory Access</a>
<li><a accesskey="7" href="#Foreign-Function-Calling">Foreign Function Calling</a>
<li><a accesskey="8" href="#Loading-Foreign-Libraries">Loading Foreign Libraries</a>
<li><a accesskey="9" href="#Foreign-Globals">Foreign Globals</a>
<li><a href="#Symbol-Index">Symbol Index</a>
</ul>
<div class="node">
<a name="Introduction"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a>,
Previous: <a rel="previous" accesskey="p" href="#Top">Top</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">1 Introduction</h2>
<p><acronym>CFFI</acronym>, the Common Foreign Function Interface, purports to be
a portable foreign function interface for Common Lisp.
<p>This specification defines a set of low-level primitives that must be
defined for each Lisp implementation supported by <acronym>CFFI</acronym>.
These operators are defined in the <code>CFFI-SYS</code> package.
<p>The <code>CFFI</code> package uses the <code>CFFI-SYS</code> interface
to implement an extensible foreign type system with support for
typedefs, structures, and unions, a declarative interface for
defining foreign function calls, and automatic conversion of
foreign function arguments to/from Lisp types.
<p>Please note the following conventions that apply to everything in
<code>CFFI-SYS</code>:
<ul>
<li>Functions in <code>CFFI-SYS</code> that are low-level versions of functions
exported from the <code>CFFI</code> package begin with a leading
percent-sign (eg. <code>%mem-ref</code>).
<li>Where “foreign type” is mentioned as the kind of an argument, the
meaning is restricted to that subset of all foreign types defined in
<a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a>. Support for higher-level types is
always defined in terms of those lower-level types in <code>CFFI</code>
proper.
</ul>
<div class="node">
<a name="Built-In-Foreign-Types"></a>
<a name="Built_002dIn-Foreign-Types"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Operations-on-Foreign-Types">Operations on Foreign Types</a>,
Previous: <a rel="previous" accesskey="p" href="#Introduction">Introduction</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">2 Built-In Foreign Types</h2>
<div class="defun">
— Foreign Type: <b>:char</b><var><a name="index-g_t_003achar-1"></a></var><br>
— Foreign Type: <b>:unsigned-char</b><var><a name="index-g_t_003aunsigned_002dchar-2"></a></var><br>
— Foreign Type: <b>:short</b><var><a name="index-g_t_003ashort-3"></a></var><br>
— Foreign Type: <b>:unsigned-short</b><var><a name="index-g_t_003aunsigned_002dshort-4"></a></var><br>
— Foreign Type: <b>:int</b><var><a name="index-g_t_003aint-5"></a></var><br>
— Foreign Type: <b>:unsigned-int</b><var><a name="index-g_t_003aunsigned_002dint-6"></a></var><br>
— Foreign Type: <b>:long</b><var><a name="index-g_t_003along-7"></a></var><br>
— Foreign Type: <b>:unsigned-long</b><var><a name="index-g_t_003aunsigned_002dlong-8"></a></var><br>
— Foreign Type: <b>:long-long</b><var><a name="index-g_t_003along_002dlong-9"></a></var><br>
— Foreign Type: <b>:unsigned-long-long</b><var><a name="index-g_t_003aunsigned_002dlong_002dlong-10"></a></var><br>
<blockquote><p>These types correspond to the native C integer types according to the
ABI of the system the Lisp implementation is compiled against.
</p></blockquote></div>
<div class="defun">
— Foreign Type: <b>:int8</b><var><a name="index-g_t_003aint8-11"></a></var><br>
— Foreign Type: <b>:uint8</b><var><a name="index-g_t_003auint8-12"></a></var><br>
— Foreign Type: <b>:int16</b><var><a name="index-g_t_003aint16-13"></a></var><br>
— Foreign Type: <b>:uint16</b><var><a name="index-g_t_003auint16-14"></a></var><br>
— Foreign Type: <b>:int32</b><var><a name="index-g_t_003aint32-15"></a></var><br>
— Foreign Type: <b>:uint32</b><var><a name="index-g_t_003auint32-16"></a></var><br>
— Foreign Type: <b>:int64</b><var><a name="index-g_t_003aint64-17"></a></var><br>
— Foreign Type: <b>:uint64</b><var><a name="index-g_t_003auint64-18"></a></var><br>
<blockquote><p>Foreign integer types of specific sizes, corresponding to the C types
defined in <code>stdint.h</code>.
</p></blockquote></div>
<div class="defun">
— Foreign Type: <b>:size</b><var><a name="index-g_t_003asize-19"></a></var><br>
— Foreign Type: <b>:ssize</b><var><a name="index-g_t_003assize-20"></a></var><br>
— Foreign Type: <b>:ptrdiff</b><var><a name="index-g_t_003aptrdiff-21"></a></var><br>
— Foreign Type: <b>:time</b><var><a name="index-g_t_003atime-22"></a></var><br>
<blockquote><p>Foreign integer types corresponding to the standard C types (without
the <code>_t</code> suffix).
</p></blockquote></div>
<p><em>Implementor's note: I'm sure there are more of these that could be useful, let's
add any types that can't be defined portably to this list as
necessary.</em>
<div class="defun">
— Foreign Type: <b>:float</b><var><a name="index-g_t_003afloat-23"></a></var><br>
— Foreign Type: <b>:double</b><var><a name="index-g_t_003adouble-24"></a></var><br>
<blockquote><p>The <code>:float</code> type represents a C <code>float</code> and a Lisp
<code>single-float</code>. <code>:double</code> represents a C <code>double</code> and a
Lisp <code>double-float</code>.
</p></blockquote></div>
<div class="defun">
— Foreign Type: <b>:pointer</b><var><a name="index-g_t_003apointer-25"></a></var><br>
<blockquote><p>A foreign pointer to an object of any type, corresponding to
<code>void *</code>.
</p></blockquote></div>
<div class="defun">
— Foreign Type: <b>:void</b><var><a name="index-g_t_003avoid-26"></a></var><br>
<blockquote><p>No type at all. Only valid as the return type of a function.
</p></blockquote></div>
<div class="node">
<a name="Operations-on-Foreign-Types"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Basic-Pointer-Operations">Basic Pointer Operations</a>,
Previous: <a rel="previous" accesskey="p" href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">3 Operations on Built-in Foreign Types</h2>
<div class="defun">
— Function: <b>%foreign-type-size</b><var> type ⇒ size<a name="index-g_t_0025foreign_002dtype_002dsize-27"></a></var><br>
<blockquote><p>Return the <var>size</var>, in bytes, of objects having foreign type
<var>type</var>. An error is signalled if <var>type</var> is not a known
built-in foreign type.
</p></blockquote></div>
<div class="defun">
— Function: <b>%foreign-type-alignment</b><var> type ⇒ alignment<a name="index-g_t_0025foreign_002dtype_002dalignment-28"></a></var><br>
<blockquote><p>Return the default alignment in bytes for structure members of foreign
type <var>type</var>. An error is signalled if <var>type</var> is not a known
built-in foreign type.
<p><em>Implementor's note: Maybe this should take an optional keyword argument specifying an
alternate alignment system, eg. :mac68k for 68000-compatible alignment
on Darwin.</em>
</p></blockquote></div>
<div class="node">
<a name="Basic-Pointer-Operations"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Foreign-Memory-Allocation">Foreign Memory Allocation</a>,
Previous: <a rel="previous" accesskey="p" href="#Operations-on-Foreign-Types">Operations on Foreign Types</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">4 Basic Pointer Operations</h2>
<div class="defun">
— Function: <b>pointerp</b><var> ptr ⇒ boolean<a name="index-pointerp-29"></a></var><br>
<blockquote><p>Return true if <var>ptr</var> is a foreign pointer.
</p></blockquote></div>
<div class="defun">
— Function: <b>null-pointer</b><var> ⇒ pointer<a name="index-null_002dpointer-30"></a></var><br>
<blockquote><p>Return a null foreign pointer.
</p></blockquote></div>
<div class="defun">
— Function: <b>null-pointer-p</b><var> ptr ⇒ boolean<a name="index-null_002dpointer_002dp-31"></a></var><br>
<blockquote><p>Return true if <var>ptr</var> is a null foreign pointer.
</p></blockquote></div>
<div class="defun">
— Function: <b>make-pointer</b><var> address ⇒ pointer<a name="index-make_002dpointer-32"></a></var><br>
<blockquote><p>Return a pointer corresponding to the numeric integer <var>address</var>.
</p></blockquote></div>
<div class="defun">
— Function: <b>inc-pointer</b><var> ptr offset ⇒ pointer<a name="index-inc_002dpointer-33"></a></var><br>
<blockquote><p>Return the result of numerically incrementing <var>ptr</var> by <var>offset</var>.
</p></blockquote></div>
<div class="node">
<a name="Foreign-Memory-Allocation"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Memory-Access">Memory Access</a>,
Previous: <a rel="previous" accesskey="p" href="#Basic-Pointer-Operations">Basic Pointer Operations</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">5 Foreign Memory Allocation</h2>
<div class="defun">
— Function: <b>foreign-alloc</b><var> size ⇒ pointer<a name="index-foreign_002dalloc-34"></a></var><br>
<blockquote><p>Allocate <var>size</var> bytes of foreign-addressable memory and return
a <var>pointer</var> to the allocated block. An implementation-specific
error is signalled if the memory cannot be allocated.
</p></blockquote></div>
<div class="defun">
— Function: <b>foreign-free</b><var> ptr ⇒ unspecified<a name="index-foreign_002dfree-35"></a></var><br>
<blockquote><p>Free a pointer <var>ptr</var> allocated by <code>foreign-alloc</code>. The
results are undefined if <var>ptr</var> is used after being freed.
</p></blockquote></div>
<div class="defun">
— Macro: <b>with-foreign-pointer</b> (<var>var size &optional size-var</var>)<var> &body body<a name="index-with_002dforeign_002dpointer-36"></a></var><br>
<blockquote><p>Bind <var>var</var> to a pointer to <var>size</var> bytes of
foreign-accessible memory during <var>body</var>. Both <var>ptr</var> and the
memory block it points to have dynamic extent and may be stack
allocated if supported by the implementation. If <var>size-var</var> is
supplied, it will be bound to <var>size</var> during <var>body</var>.
</p></blockquote></div>
<div class="node">
<a name="Memory-Access"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Foreign-Function-Calling">Foreign Function Calling</a>,
Previous: <a rel="previous" accesskey="p" href="#Foreign-Memory-Allocation">Foreign Memory Allocation</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">6 Memory Access</h2>
<div class="defun">
— Accessor: <b>%mem-ref</b><var> ptr type &optional offset<a name="index-g_t_0025mem_002dref-37"></a></var><br>
<blockquote><p>Dereference a pointer <var>offset</var> bytes from <var>ptr</var> to an object
for reading (or writing when used with <code>setf</code>) of built-in type
<var>type</var>.
</p></blockquote></div>
<h3 class="heading">Example</h3>
<pre class="lisp"> ;; An impractical example, since time returns the time as well,
;; but it demonstrates %MEM-REF. Better <span class="paren1">(<span class="lisp-bg">simple</span>)</span> examples wanted!
<span class="paren1">(<span class="lisp-bg"><i><span class="symbol">with-foreign-pointer</span></i> <span class="paren2">(<span class="lisp-bg">p <span class="paren3">(<span class="lisp-bg">foreign-type-size <span class="keyword">:time</span></span>)</span></span>)</span>
<span class="paren2">(<span class="lisp-bg">foreign-funcall <span class="string">"time"</span> <span class="keyword">:pointer</span> p <span class="keyword">:time</span></span>)</span>
<span class="paren2">(<span class="lisp-bg">%mem-ref p <span class="keyword">:time</span></span>)</span></span>)</span>
</pre>
<div class="node">
<a name="Foreign-Function-Calling"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Loading-Foreign-Libraries">Loading Foreign Libraries</a>,
Previous: <a rel="previous" accesskey="p" href="#Memory-Access">Memory Access</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">7 Foreign Function Calling</h2>
<div class="defun">
— Macro: <b>%foreign-funcall</b><var> name {arg-type arg}* &optional result-type ⇒ object<a name="index-g_t_0025foreign_002dfuncall-38"></a></var><br>
— Macro: <b>%foreign-funcall-pointer</b><var> ptr {arg-type arg}* &optional result-type ⇒ object<a name="index-g_t_0025foreign_002dfuncall_002dpointer-39"></a></var><br>
<blockquote><p>Invoke a foreign function called <var>name</var> in the foreign source code.
<p>Each <var>arg-type</var> is a foreign type specifier, followed by
<var>arg</var>, Lisp data to be converted to foreign data of type
<var>arg-type</var>. <var>result-type</var> is the foreign type of the
function's return value, and is assumed to be <code>:void</code> if not
supplied.
<p><code>%foreign-funcall-pointer</code> takes a pointer <var>ptr</var> to the
function, as returned by <code>foreign-symbol-pointer</code>, rather than a
string <var>name</var>.
</p></blockquote></div>
<h3 class="heading">Examples</h3>
<pre class="lisp"> ;; Calling a standard C library function:
<span class="paren1">(<span class="lisp-bg">%foreign-funcall <span class="string">"sqrtf"</span> <span class="keyword">:float</span> 16.0 <span class="keyword">:float</span></span>)</span> &rArr; 4.0
</pre>
<pre class="lisp"> ;; Dynamic allocation of a buffer and passing to a function:
<span class="paren1">(<span class="lisp-bg"><i><span class="symbol">with-foreign-ptr</span></i> <span class="paren2">(<span class="lisp-bg">buf 255 buf-size</span>)</span>
<span class="paren2">(<span class="lisp-bg">%foreign-funcall <span class="string">"gethostname"</span> <span class="keyword">:pointer</span> buf <span class="keyword">:size</span> buf-size <span class="keyword">:int</span></span>)</span>
<span class="comment">;; Convert buf to a Lisp string using MAKE-STRING and %MEM-REF or
</span> <span class="comment">;; a portable CFFI function such as CFFI:FOREIGN-STRING-TO-LISP.
</span> </span>)</span>
</pre>
<div class="node">
<a name="Loading-Foreign-Libraries"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Foreign-Globals">Foreign Globals</a>,
Previous: <a rel="previous" accesskey="p" href="#Foreign-Function-Calling">Foreign Function Calling</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">8 Loading Foreign Libraries</h2>
<div class="defun">
— Function: <b>%load-foreign-library</b><var> name ⇒ unspecified<a name="index-g_t_0025load_002dforeign_002dlibrary-40"></a></var><br>
<blockquote><p>Load the foreign shared library <var>name</var>.
<p><em>Implementor's note: There is a lot of behavior to decide here. Currently I lean
toward not requiring NAME to be a full path to the library so
we can search the system library directories (maybe even get
LD_LIBRARY_PATH from the environment) as necessary.</em>
</p></blockquote></div>
<div class="node">
<a name="Foreign-Globals"></a>
<p><hr>
Next: <a rel="next" accesskey="n" href="#Symbol-Index">Symbol Index</a>,
Previous: <a rel="previous" accesskey="p" href="#Loading-Foreign-Libraries">Loading Foreign Libraries</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="chapter">9 Foreign Globals</h2>
<div class="defun">
— Function: <b>foreign-symbol-pointer</b><var> name ⇒ pointer<a name="index-foreign_002dsymbol_002dpointer-41"></a></var><br>
<blockquote><p>Return a pointer to a foreign symbol <var>name</var>.
</p></blockquote></div>
<div class="node">
<a name="Symbol-Index"></a>
<p><hr>
Previous: <a rel="previous" accesskey="p" href="#Foreign-Globals">Foreign Globals</a>,
Up: <a rel="up" accesskey="u" href="#Top">Top</a>
</div>
<h2 class="unnumbered">Symbol Index</h2>
<ul class="index-fn" compact>
<li><a href="#index-g_t_0025foreign_002dfuncall-38"><code>%foreign-funcall</code></a>: <a href="#Foreign-Function-Calling">Foreign Function Calling</a></li>
<li><a href="#index-g_t_0025foreign_002dfuncall_002dpointer-39"><code>%foreign-funcall-pointer</code></a>: <a href="#Foreign-Function-Calling">Foreign Function Calling</a></li>
<li><a href="#index-g_t_0025foreign_002dtype_002dalignment-28"><code>%foreign-type-alignment</code></a>: <a href="#Operations-on-Foreign-Types">Operations on Foreign Types</a></li>
<li><a href="#index-g_t_0025foreign_002dtype_002dsize-27"><code>%foreign-type-size</code></a>: <a href="#Operations-on-Foreign-Types">Operations on Foreign Types</a></li>
<li><a href="#index-g_t_0025load_002dforeign_002dlibrary-40"><code>%load-foreign-library</code></a>: <a href="#Loading-Foreign-Libraries">Loading Foreign Libraries</a></li>
<li><a href="#index-g_t_0025mem_002dref-37"><code>%mem-ref</code></a>: <a href="#Memory-Access">Memory Access</a></li>
<li><a href="#index-g_t_003achar-1"><code>:char</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003adouble-24"><code>:double</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003afloat-23"><code>:float</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aint-5"><code>:int</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aint16-13"><code>:int16</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aint32-15"><code>:int32</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aint64-17"><code>:int64</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aint8-11"><code>:int8</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003along-7"><code>:long</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003along_002dlong-9"><code>:long-long</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003apointer-25"><code>:pointer</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aptrdiff-21"><code>:ptrdiff</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003ashort-3"><code>:short</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003asize-19"><code>:size</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003assize-20"><code>:ssize</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003atime-22"><code>:time</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003auint16-14"><code>:uint16</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003auint32-16"><code>:uint32</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003auint64-18"><code>:uint64</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003auint8-12"><code>:uint8</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aunsigned_002dchar-2"><code>:unsigned-char</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aunsigned_002dint-6"><code>:unsigned-int</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aunsigned_002dlong-8"><code>:unsigned-long</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aunsigned_002dlong_002dlong-10"><code>:unsigned-long-long</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003aunsigned_002dshort-4"><code>:unsigned-short</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-g_t_003avoid-26"><code>:void</code></a>: <a href="#Built_002dIn-Foreign-Types">Built-In Foreign Types</a></li>
<li><a href="#index-foreign_002dalloc-34"><code>foreign-alloc</code></a>: <a href="#Foreign-Memory-Allocation">Foreign Memory Allocation</a></li>
<li><a href="#index-foreign_002dfree-35"><code>foreign-free</code></a>: <a href="#Foreign-Memory-Allocation">Foreign Memory Allocation</a></li>
<li><a href="#index-foreign_002dsymbol_002dpointer-41"><code>foreign-symbol-pointer</code></a>: <a href="#Foreign-Globals">Foreign Globals</a></li>
<li><a href="#index-inc_002dpointer-33"><code>inc-pointer</code></a>: <a href="#Basic-Pointer-Operations">Basic Pointer Operations</a></li>
<li><a href="#index-make_002dpointer-32"><code>make-pointer</code></a>: <a href="#Basic-Pointer-Operations">Basic Pointer Operations</a></li>
<li><a href="#index-null_002dpointer-30"><code>null-pointer</code></a>: <a href="#Basic-Pointer-Operations">Basic Pointer Operations</a></li>
<li><a href="#index-null_002dpointer_002dp-31"><code>null-pointer-p</code></a>: <a href="#Basic-Pointer-Operations">Basic Pointer Operations</a></li>
<li><a href="#index-pointerp-29"><code>pointerp</code></a>: <a href="#Basic-Pointer-Operations">Basic Pointer Operations</a></li>
<li><a href="#index-with_002dforeign_002dpointer-36"><code>with-foreign-pointer</code></a>: <a href="#Foreign-Memory-Allocation">Foreign Memory Allocation</a></li>
</ul></body></html>
|