cl: cffi - type translation
Table of Contents
2025-12-19 here are some note I took while trying to understand how to tell cffi to automatically translates some type. I did not review these notes, but they will be a good starting point next time I want to do something similar.
1. translate, expand and functions
- the
translate-*methods are called at run-time, theexpand-*methods are called at macro-expansion-time (à la compiler macros).- usually!
expand-*"bail-out" totranslate-*methods- again, very similar to compiler-macros
defcfunandforeign-funcalluses the internal functiontranslate-objects, which in turns usesexpand-from-foreign,expand-to-foreign-dyn-indirectandexpand-to-foreign-dyn
2. TODO
- ~(namespace-table :default)
parse-typedefine-parse-methodfind-type-parser
3. defcstruct
defcstruct- always define a clos class
- the default name of the class is
<name>-tclass - it has the superclasses
foreign-struct-typeandtranslatable-foreign-type - it has no slot!
- the default name of the class is
- calls
notice-foreign-struct-definition- it does a lot: validation, compute offsets, padding, alignment, etc
- it creates an instance of the class 🤔
with-tentative-type-definitionnotice-foreign-type+unwind-protect(setf (find-type-parser name namespace) (lambda () type))namespacedefaults to…:defaulttypeis actually the instance created at the start ofnotice-foreign-type
- in the body:
make-struct-slot- either an instance of
aggregate-struct-slotorsimple-struct-slot
- either an instance of
- calls ~generate-struct-accessors-
- only if the option
:conc-nameis not nil - defines a function and a setf function for each slots
- named <conc-name>-<slot>
- only if the option
- also
define-parse-method
- always define a clos class
4. TODO define-foreign-type
- declass
- the slots are NOT the slots of the instance, they are part of the TYPE.
- define-parse-method
maybe I need to add a define-parse-method??