Closed cblp closed 5 years ago
@cblp I like the idea! Feel free to submit a PR.
Hm, TH seems to be unable to emit do-statements, so we can't introduce variables in a do-block.
I usually use withPtrs
for this, it's a bit more boilerplate but it works: http://hackage.haskell.org/package/inline-c-0.7.0.1/docs/Language-C-Inline.html#t:WithPtrs
( x, y, ptr, len ) <- withPtrs_ $ \(xPtr, yPtr, ptrPtr, lenPtr) ->
[Cpp.block| void {
Status & status = * $fptr-ptr:(Status * statusFP);
*$(uint64_t* xPtr) = uint64_t(status.code().value());
*$(uint64_t* yPtr) = uint64_t(status.code().origin());
*$(const char** ptrPtr) = uintptr_t(status.comment().data());
*$(size_t* lenPtr) = status.comment().length();
} |]
It's a bit more boilerplate but it's not too bad.
@chpatrick, great! thanks!
I found myself writing such code:
It would be nice to write instead
with all boilerplate generated automagically.
I want to implement it. What do you think?
Alternatives:
http://www.chiark.greenend.org.uk/doc/libffi-dev/html/Structures.html#Structures
https://gitlab.haskell.org/ghc/ghc/issues/9700