FFI and when to convert the stack pointer (an Alien) into an ExternalAddress
I am toying with Ben's bindings to clang-c (C interface to the Clang C-indexer API). One of the main features of the C API is a way to visit the translation unit. This is implemented as a callback into Smalltalk with with "cursors" providing indirect access and simplified access to the node of the AST. The return result indicates how to continue the traversal (continue, stop, recurse).
signature: #( CXChildVisitResult (
block: [ :cursor :parent :clientData |
cursor spelling. <- booom but no crash
aCXChildVisitResult value "@1" ].
"cursor" will be an Instance of CXCursor and is passed by value and the C struct size is >16 bytes (on Unix this is passed on the stack). The resulting CXCursor has a handle that is invalid to perform any call-out with.
handle: an Alien (isPointer = true, the stack ptr
ExternalStructure defines valid types as ByteArray (the data) or ExternalAddress (the pointer). FFIExternalStructureReferenceHandle is missing there and I will create a separate thread/ticket about it.
ee will need to convert the handle + offset (one based) to an ExternalAddress. Now the protocol of >>#handle:at: and >>#integerAt:, >>#pointerAt: indicate that we want to carry address+offset into late of the conversion. And I can't point my finger into where it should be done.