<div dir="ltr">I don't care enough to fight and try to win the battle, but I just want to point out that Storable structs are far more brittle and platform dependent than borrowing the already correct platform logic for struct passing from libffi.<div>
<br></div><div>I do think the existing FFI extension made the right call under the 32 bit ABIs that were in use at the time it was defined. That said, with 64-bit ABIs saying that 2 32-bit ints should be passed in a single 64 bit register, you wind up with large chunks of third party APIs we just can't call out to directly any more, requiring many one-off manual C shims.</div>
<div><br></div><div>-Edward<br><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 15, 2014 at 12:17 AM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">indeed, its very very easy to do storable instances that correspond to the struct type you want, <div><br>
</div><div>the ``with`` function in <a href="http://hackage.haskell.org/package/base-4.6.0.1/docs/Foreign-Marshal-Utils.html" target="_blank">http://hackage.haskell.org/package/base-4.6.0.1/docs/Foreign-Marshal-Utils.html</a> foreigh.marshal.utils actually gets you most of the way there!</div>


<div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 15, 2014 at 12:00 AM, Manuel M T Chakravarty <span dir="ltr"><<a href="mailto:chak@cse.unsw.edu.au" target="_blank">chak@cse.unsw.edu.au</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Yuras,<br>
<br>
I’m not convinced that the compiler is the right place for this kind of functionality. In fact, when we designed the Haskell FFI, we explicit decided against what you propose. There are a few reasons for this.<br>
<br>
Firstly, compilers are complex beasts, and secondly, it takes a long time until a change in the compiler goes into production. Hence, as a general rule, it is advisable to move complexity from the compiler into libraries as this reduces compiler complexity. Libraries are less complex and changes can be rolled out much more quickly (it’s essentially a Hackage upload versus waiting for the next GHC and Haskell Platform release).<br>



<br>
Thirdly, we have got the Haskell standard for a reason and modifying the compiler implies a language extension.<br>
<br>
The design goal for the Haskell FFI was to provide the absolute minimum as part of the language and compiler, and to layer additional conveniences on top of that in the form of libraries and tools.<br>
<br>
Have you considered the library or tool route?<br>
<br>
Manuel<br>
<br>
Yuras Shumovich <<a href="mailto:shumovichy@gmail.com" target="_blank">shumovichy@gmail.com</a>>:<br>
<div><div>> Hi,<br>
><br>
> Right now ghc's FFI doesn't support c/c++ structures.<br>
><br>
> Whenever we have foreign function that accepts or returns struct by<br>
> value, we have to create wrapper that accepts or returns pointer to<br>
> struct. It is inconvenient, but actually not a big deal.<br>
><br>
> But there is no easy workaround when you want to export haskell function<br>
> to use it with c/c++ API that requires structures to be passed by value<br>
> (Usually it is a callback in c/c++ API. You can't change it's signature,<br>
> and if it doesn't provide some kind of "void* userdata", then you are<br>
> stuck.)<br>
><br>
> I'm interested in fixing that. I'm going to start with 'foreign import<br>
> "wrapper" ...' stuff.<br>
><br>
> Calling conventions for passing c/c++ structures by value are pretty<br>
> tricky and platform/compiler specific. So initially I'll use libffi for<br>
> that (it will work when USE_LIBFFI_FOR_ADJUSTORS is defined, see<br>
> rts/Adjustor.c). It will allow me to explore design space without<br>
> bothering about low level implementation details. Later it could be<br>
> implemented for native (non-libffi) adjustors.<br>
><br>
> Is anybody interested it that? I appreciate any comments/ideas.<br>
><br>
> Right now I don't have clear design. It would be nice to support plain<br>
> haskell data types that are 1) not recursive, 2) has one constructor and<br>
> 3) contains only c/c++ types. But it doesn't work with c/c++ unions. Any<br>
> ideas are welcome.<br>
><br>
> An example how to use libffi with structures:<br>
> <a href="http://www.atmark-techno.com/~yashi/libffi.html#Structures" target="_blank">http://www.atmark-techno.com/~yashi/libffi.html#Structures</a><br>
><br>
> Thanks,<br>
> Yuras<br>
><br>
><br>
> _______________________________________________<br>
> ghc-devs mailing list<br>
> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
> <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br>
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
</div></div></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>