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

Kyle Murphy orclev at gmail.com
Thu Dec 20 04:11:30 CET 2012


It's been a while since I've done anything with C, but if I'm reading
that right it's expecting a pointer pointer as the second argument. In
other words, it wants the address of a pointer that it will update
with a pointer to the instantiated instance of the session structure.
See if this helps:
http://www.haskell.org/haskellwiki/FFICookBook#Passing_pointer-to-pointer-to-thing

-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.


On Wed, Dec 19, 2012 at 4:49 PM, Matthew Hayden
<mrehayden at googlemail.com> wrote:
> 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
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list