Subject: [ruby-ffi] Ruby FFI to C to Ruby FFI to C |
From: avalanche123 |
Date: 4/5/12 4:50 PM |
To: ruby-ffi |
Hello, I'm working on libuv ffi bindings for Ruby and have an issue I can't understand Libuv needs an allocated buffer it can write to, here is a gist of code https://gist.github.com/2313277 that has my ruby module and usage examples both in C and Ruby The C example works fine, while ruby makes Libuv raise EINVAL. I've used some basic debugging and figured out that the buffer len than comes from Ruby is 140735085305696 instead of 128, as can be seen from shell outputs examples I've added to the gist. I've also added relevant pieces of Libuv to the gist, specifically uv_buf_init that is responsible for creating uv_buf_t and part of libuv's uv__read that is responsible for using it. From my debugging it looks like a corrupted uv_buf_t memory comes back from Ruby, making libuv believe beffer's len attribute is 140735085305696 bytes long. I will appreciate any feedback as I've been struggling with this for a while. Best, Bulat