Subject: [ruby-ffi] can't explain this behavior |
From: Alexander Kabanov |
Date: 4/20/11 1:12 PM |
To: ruby-ffi |
Hi there, I'm trying to do something basic in my opinion, and get mixed results code example is here: 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)? 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) best, --Alex