95 lines
3.7 KiB
HTML
95 lines
3.7 KiB
HTML
<html lang="en">
|
|
<head>
|
|
<title>Callbacks - SBCL Internals</title>
|
|
<meta http-equiv="Content-Type" content="text/html">
|
|
<meta name="description" content="SBCL Internals">
|
|
<meta name="generator" content="makeinfo 4.11">
|
|
<link title="Top" rel="start" href="index.html#Top">
|
|
<link rel="up" href="Foreign-Linkage.html#Foreign-Linkage" title="Foreign Linkage">
|
|
<link rel="prev" href="Lazy-Alien-Resolution.html#Lazy-Alien-Resolution" title="Lazy Alien Resolution">
|
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
|
<!--
|
|
|
|
This manual is part of the SBCL software system. See the `README'
|
|
file for more information.
|
|
|
|
This manual is in the public domain and is provided with
|
|
absolutely no warranty. See the `COPYING' and `CREDITS' files for
|
|
more information.
|
|
-->
|
|
<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; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
<div class="node">
|
|
<p>
|
|
<a name="Callbacks"></a>
|
|
Previous: <a rel="previous" accesskey="p" href="Lazy-Alien-Resolution.html#Lazy-Alien-Resolution">Lazy Alien Resolution</a>,
|
|
Up: <a rel="up" accesskey="u" href="Foreign-Linkage.html#Foreign-Linkage">Foreign Linkage</a>
|
|
<hr>
|
|
</div>
|
|
|
|
<!-- node-name, next, previous, up -->
|
|
<h3 class="section">4.3 Callbacks</h3>
|
|
|
|
<p>SBCL is capable of providing C with linkage to Lisp – the upshot of which is that
|
|
C-functions can call Lisp functions thru what look like function pointers to C.
|
|
|
|
<p>These “function pointers” are called Alien Callbacks. An alien
|
|
callback sequence has 4 parts / stages / bounces:
|
|
|
|
<ul>
|
|
<li>Assembler Wrapper
|
|
|
|
<p>saves the arguments from the C-call according to the alien-fun-type of
|
|
the callback, and calls #'ENTER-ALIEN-CALLBACK with the index
|
|
indentifying the callback, a pointer to the arguments copied on the
|
|
stack and a pointer to return value storage. When control returns to
|
|
the wrapper it returns the value to C. There is one assembler wrapper
|
|
per callback.[1] The SAP to the wrapper code vector is what is passed
|
|
to foreign code as a callback.
|
|
|
|
<p>The Assembler Wrapper is generated by
|
|
<code>ALIEN-CALLBACK-ASSEMBLER-WRAPPER</code>.
|
|
|
|
<li>#'ENTER-ALIEN-CALLBACK
|
|
|
|
<p>pulls the Lisp Trampoline for the given index, and calls it with the
|
|
argument and result pointers.
|
|
|
|
<li>Lisp Trampoline
|
|
|
|
<p>calls the Lisp Wrapper with the argument and result pointers, and the
|
|
function designator for the callback. There is one lisp trampoline per
|
|
callback.
|
|
|
|
<li>Lisp Wrapper
|
|
|
|
<p>parses the arguments from stack, calls the actual callback with the
|
|
arguments, and saves the return value at the result pointer. The lisp
|
|
wrapper is shared between all the callbacks having the same same
|
|
alien-fun-type.
|
|
|
|
</ul>
|
|
|
|
<p>[1] As assembler wrappers need to be allocated in static addresses and
|
|
are (in the current scheme of things) never released it might be worth
|
|
it to split it into two parts: per-callback trampoline that pushes the
|
|
index of the lisp trampoline on the stack, and jumps to the
|
|
appropriate assembler wrapper. The assembler wrapper could then be
|
|
shared between all the callbacks with the same alien-fun-type. This
|
|
would amortize most of the static allocation costs between multiple
|
|
callbacks.
|
|
|
|
</body></html>
|
|
|