[Haskell-beginners] Fwd: FFI bindings to prodecure with an in-out parameter

Matthew Hayden mrehayden at googlemail.com
Wed Dec 19 22:49:19 CET 2012


Dear Haskell Beginners,

I've gotten stuck developing an FFI binding to libspotify. One of the
functions I'm trying to bind to, sp_session_create, uses an in-out
parameter. Luckily I have an example of its usage here (in the definition
of main):

https://developer.spotify.com/technologies/libspotify/docs/12.1.45/jukebox_8c-example.html

It looks to me like they've allocated a pointer to an sp_session and then
passed a pointer to that to sp_session_create.

My best attempt tries to do the same but comes across a missing Storable
instance of the equivalent of the sp_session data structure. Because the C
definition of this struct is not exposed in the header files I can't work
out how to do it myself. The alternative of passing in an empty pointer
with the assumption that the procedure will allocate memory for us simply
segfaults.

I've put a source distribution up here (hit "raw" to download):
https://github.com/mrehayden1/hmdfm/blob/master/dist/hmdfm-0.1.0.0.tar.gz
The project can be built automatically with cabal and GHC with hsc2hs
installed.

Also if you like libspotify can be downloaded and automatically installed
(for *nix users I think at least) from here:
https://developer.spotify.com/technologies/libspotify/#download

Please, can anyone help?

Matthew Hayden
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121219/0b9423f7/attachment.htm>


More information about the Beginners mailing list