Thanks Matthew<br><br><div class="gmail_quote">On Sun, Nov 27, 2011 at 6:59 PM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">At Sun, 27 Nov 2011 18:20:46 -0500, Harry Spier wrote:<br>
> Dear list members,<br>
> On going through the article on the FFI by Eli Barzilay and Dmitry Orlovsky<br>
> <a href="http://www.ccs.neu.edu/scheme/pubs/scheme04-bo.pdf" target="_blank">http://www.ccs.neu.edu/scheme/pubs/scheme04-bo.pdf</a><br>
><br>
> It says:<br>
> "libffi is maintained and distributed as part of the GCC project,<br>
> but its goal is to provide a portable library. We use it for all<br>
> platforms that PLT Scheme targets, including Windows (using a<br>
> slightly adapted version that works with Microsoft’s compiler, courtesy<br>
> of the Thomas Heller [13])."<br>
<br>
</div>(Racket now uses the main libffi sources for Windows, too.)<br>
<div class="im"><br>
> Does that mean that if I'm using the Windows version of Racket and I want<br>
> to use the FFI to interface to ImageMagick, that the ImageMagick Windows<br>
> executable must also be compiled with the microsoft C compiler rather than<br>
> with MingW GCC ?<br>
<br>
</div>No.<br>
<div class="im"><br>
> A few years ago when I interfaced ImageMagick to Ruby using Ruby's<br>
> ImageMagick interface "RMagick" there was a problem for a while about<br>
> RMagick being compiled with Microsoft Visual C compiler (it may have been a<br>
> particular version of the Visual C compiler?) and I think the ImageMagick<br>
> executable for windows was compiled with MingW GCC. The problem was<br>
> resolved when the RMagick interface was compiled using the same compiler as<br>
> ImageMagick.<br>
<br>
</div>That sounds like an issue with mismatched C runtime libraries.<br>
<br>
The main way a mismatch can show up with Racket's FFI is when a foreign<br>
function allocates a value, and the caller is supposed to free it with<br>
free(). In that case, calling the Racket `free' function may not work,<br>
because it may use a different memory allocator from the one linked to<br>
the foreign library --- i.e., different instances of malloc() and<br>
free() from different C libraries.<br>
<br>
Most libraries that provide allocation functions also provide<br>
corresponding deallocation functions instead of relying on free(), and<br>
that avoids the problem. Meanwhile, Racket uses "msvcrt.dll" as its C<br>
runtime library, which is consistent with most binary distributions of<br>
open-source software. I believe that MinGW binaries by default use<br>
"msvcrt.dll".<br>
<br>
For all of those reasons, you probably won't run into problems due to a<br>
compiler mismatch when using Racket's FFI.<br>
<br>
<br>
</blockquote></div><br>