haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
199 stars 50 forks source link

Preserving existing result with + #236

Open georgefst opened 5 years ago

georgefst commented 5 years ago

The + notation in fun hooks (for converting a function that manipulates a fresh pointer, to one that does the allocation itself and returns the pointer) is to my mind one of the nicest features of c2hs. Unfortunately, it discards the original return value, making it useless in the case where the C function returns something useful eg. an error code, and we want to return that result along with the pointer.

It would be amazing (and presumably not that difficult to implement, I may even look at submitting a PR) if we could specify that we would like a tuple returned, and have c2hs do the obvious conversions.

eg. {#fun cfunc as ^ {+} -> `(aPtr, b)' #} for b cfunc (x *a)