Subject:
Re: [ruby-ffi] segfault on windows MRI but not windows JRuby
From:
Wayne Meissner
Date:
11/27/09 2:06 PM
To:
ruby-ffi@googlegroups.com

2009/11/28 Jon <jon.forums@gmail.com>:
> In the Novice section of http://wiki.github.com/ffi/ffi/windows-examples I'm trying to finish the Enumerate Top Level Windows example and am getting segfaults under MRI 1.8.6 and 1.9.1 but not JRuby 1.4.0 in either 1.8 or 1.9 modes.
>
> I'm ramping up to speed on FFI and not yet sure whether it's my code or the MRI FFI impl or a Ruby impl issue or something else.
>
> Details below, but in the segfault cases the top-level windows are enumerated and then the segfault occurs.  I've futzed with the signatures (e.g. changed EnumDesktopWindows return type from :bool to :int as windows "typedef int BOOL"), kept the Ruby script alive with "STDIN.gets" at script end, and futzed with param types to EnumDesktopWindows all to no avail.
>
> What have I missed?

It could be the calling convention.  On JRuby, that isn't wired up
yet, so it creates callbacks with C calling convention always, but on
MRI, it is wired up, so it creates a callback with the convention as
set by ffi_convention.

Try setting ffi_convention to :default before declaring the callback,
and then to :stdcall when declaring the functions exported by the
library.