I've pushed another update to libffidemo, adding the class DemoFFITypeMappedThing and tests. With Pharo v50647 image's UFFI enhancements, all DemoFFI tests pass.
DemoFFITypeMappedThing allows using the C typedef demo_thing in #ffiCall: function signatures:
DemoFFILibrary>>apiAllocByMappedPointerPointer: handle
"int alloc_by_pointer_pointer(demo_thing**)"
^ self ffiCall: #(int alloc_by_pointer_pointer (demo_thing **handle))
The C and Smalltalk signatures match. The ability to specify #ffiCall: function signatures very much like the actual C function signatures should make it easier to create bindings for UFFI.
The magic of DemoFFITypeMappedThing lies in FFIOpaqueObject, and,
DemoFFILibrary class>>initializeTypeMap
TypeMap := Dictionary newFromPairs: #(
demo_thing FFIOpaqueObject
)
With the above, UFFI maps (a pointer to) demo_thing in #ffiCall: signature to FFIOpaqueObject.
Compare and contrast with the earlier versions of DemoFFI:
DemoFFILibrary>>apiAllocByPointerPointer: handle
"int alloc_by_pointer_pointer(demo_thing**)"
^ self ffiCall: #(int alloc_by_pointer_pointer (DemoFFIExternalObject *handle))
Tags: FFI