▼ |  | FFI: PLT Scheme Foreign Interface

1 | Overview
2 | Loading Foreign Libraries
3 | C Types
4 | Pointer Functions
5 | Miscellaneous Support
6 | Derived Utilities
7 | Unexported Primitive Functions
8 | Macros for Unsafety
| Index

top← prev up next →

### 1`` Overview

Although using the FFI requires writing no new C code, it provides very little insulation against the issues that C programmer faces related to safety and memory management. An FFI programmer must be particularly aware of memory management issues for data that spans the Scheme–C divide. Thus, this manual relies in many ways on the information in Inside: PLT Scheme C API, which defines how PLT Scheme interacts with C APIs in general.

Since using the FFI entails many safety concerns that Scheme programmers can normally ignore, merely importing scheme/foreign with (require scheme/foreign) does not import all of the FFI functionality. Only safe functionality is immediately imported. For example, ptr-equal? can never cause memory corruption or an invalid memory access, so it is immediately available on import.

Use (unsafe!) at the top-level of a module that imports scheme/foreign to make unsafe features accessible. (For additional safety, the unsafe! is itself protected; see Code Inspectors.) Using this macro should be considered as a declaration that your code is itself unsafe, therefore can lead to serious problems in case of bugs: it is your responsibility to provide a safe interface. Bindings that become available only via unsafe! are documented in this manual in sections with titles starting “Unsafe.”

For examples of common FFI usage patterns, see the defined interfaces in the "ffi" collection.

top← prev up next →