Haskell FFI - How to handle C functions that accept or return structs instead of pointers to structs? -


of course answer somehow pass/take contiguous block of memory, question more how that. still avoid issue writing wrapper functions on c side, that's not of permament solution.

the ffi doesn't support arbitrary pass value haskell storable types.

you may pass values of type (and of these pointers):

int#, word#, char#, float#, double#, addr#, stableptr# a, mutablebytearray#, foreignobj#, , bytearray#. 

so, pass structure must wrap call via c wrapper; takes pointer , passes value c function wish call.

a recent ghc extension allows "primop" imports -- bypass ffi mechanism , support arbitrary calling conventions , passing structures via unboxed tuples. e.g.

foreign import prim "itchv41_run"   parseitchv41# :: addr# -> word#                 -> (# int#, word#, word#, word#, word#, word# #) 

you can use these tricky low level stuff this.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -