Subject: [ruby-ffi] Passing a String Pointer to Callback Procs -- How to append? |
From: Scott Gonyea |
Date: 11/8/10 6:30 PM |
To: ruby-ffi |
I'm having a really painful time figuring this out. I jumped onto what NoKarma had already begun, with his curl-ffi library, and started running with it. I'm trying to emulate the ruby extension layers used in some different Curl gems (Streamly and Patron, atm). Curl wants you to pass a method reference, which it will then callback. You can see examples used in Streamly and Patron: Streamly, lines 29-83: https://github.com/aitrus/streamly/blob/master/ext/streamly.c#L29 Patron, lines 59-75 (Much simpler): https://github.com/aitrus/patron/blob/master/ext/patron/session_ext.c#L59 Basically, they're allocating a buffer and providing a callback + that buffer, which is sent to the callback. I've added this callback to CurlFFI and I have the Proc working, etc... But I cannot seem to get it to append to the string. Callback Additions to CurlFFI: https://github.com/aitrus/curl_ffi/blob/master/lib/bindings.rb#L923 https://github.com/aitrus/curl_ffi/blob/master/lib/bindings.rb#L926 I'll delete 926, as it's not necessary (I think). Procs that get called: https://github.com/aitrus/streamly/blob/master/lib/streamly/request.rb#L11 I suppose the last resort can be to call C libraries, allocating / freeing a string. But that makes me think I'm doing it wrong. I can't imagine that I'm doing anything overly interesting with my code. Scott