Subject: Re: [ruby-ffi] can't explain this behavior |
From: Chuck Remes |
Date: 4/20/11 3:25 PM |
To: ruby-ffi@googlegroups.com |
On Apr 20, 2011, at 1:12 PM, Alexander Kabanov wrote:
http://pastebin.com/b15rrd6n C function signature (arguments in order): - pointer to a string (input) - string size - pointer to final result (string) - pointer to result size (int) - int (always 0 now) - pointer to a string 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)?Hi there, I'm trying to do something basic in my opinion, and get mixed results code example is here:
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?
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. cr