Previous: Lazy Alien Resolution, Up: Foreign Linkage


4.3 Callbacks

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.

These “function pointers” are called Alien Callbacks. An alien callback sequence has 4 parts / stages / bounces:

[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.