Subject:
Re: [ruby-ffi] can't explain this behavior
From:
Alexander Kabanov
Date:
4/20/11 5:30 PM
To:
ruby-ffi@googlegroups.com

Hi,

On Wed, Apr 20, 2011 at 1:25 PM, Chuck Remes <cremes.devlist@mac.com> wrote:
[skip]
>> sometimes function call works as expected, sometimes it doesn't, I
>> can't explain why. adding removing few lines of code (random "puts"
>> calls etc.) will change the function call behavior (will work 20% or
>> 100% of times). am I supposed to maintain memory pointers somehow
>> (i.e. malloc/free) or my .so lib has bad implementation (i know it's
>> used in other places without any issues)?
>
> Please pastie the errors you are getting particularly if MRI is crashing. You say it doesn't work up to 80% of the time, but what does "does not work" mean in this case?

it's not crushing, there is no errors, function call might not return
anything or might work as expected and return expected result. minor
changes to the script, like few more comments or "puts" to debug
something will change the script behavior, feels like some kind of
memory allocation issue but I'm not sure.

>> I tried to use LibC approach described on wiki page using malloc, same
>> deal.
>>
>> ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-linux] RHEL 5.4
>> ffi (1.0.7)

> This might be your issue. I think that 1.8.x support is "best effort" and no longer a target. Try your code again with 1.9.2 and see if it functions more reliably. Alternately, try your code with some other ruby runtimes (JRuby, Rubinius) that have FFI support and see if they provide additional details in their errors. Those other runtimes could greatly aid in debugging.

Let me try with 1.9.2. Is there a way I can debug this to provide more
info (i.e. with gdb or something else)?

Thanks

--Alex