9.2.0.3

1 Overview🔗ℹ

The ffi2 library supports directly calling C functions from Racket. To set up those calls, the C function must be described on the Racket side, including the types for it’s arguments and results that imply conversions between Racket and C values. In principle, descriptions of C functions could be extracted from header files, but most C bindings for Racket are written independent of header files. This section steps you through the process with an extended example.

The running tutorial in this section is based on the original FFI tutorial series written by Asumu Takikawa.

    1.1 Unsafety of Foreign Functions

    1.2 Foreign-Function Basics

      1.2.1 Loading C Libraries

      1.2.2 Finding C Functions

      1.2.3 Increasing Safety with Tagged Pointers

      1.2.4 Reducing Boilerplate for Function Definitions

      1.2.5 Defining a Type Conversion

      1.2.6 Putting it All Together

    1.3 Composite Foreign Data

      1.3.1 Array Arguments

      1.3.2 C Structs

      1.3.3 Callbacks from C to Racket

    1.4 Memory Management

      1.4.1 Reliable Release of Resources

      1.4.2 Pointers and GC-Managed Allocation

    1.5 Foreign Unions and Pointer Arithmetic

      1.5.1 Declaring Union Types

      1.5.2 Hiding Pointers through Conversion