Subject: Re: [ruby-ffi] Is there any way we can use string type as return parameter? |
From: Evan Phoenix |
Date: 3/29/10 2:20 PM |
To: ruby-ffi@googlegroups.com |
On Mar 29, 2010, at 12:07 PM, Wayne Meissner wrote:
<blaxter@gmail.com>:2010/3/30 Jesús García SáezHi, when is it posible to define a "string" type safely? I think, the only situation is for const char * input parameter. Because otherwise we are gonna have memory leaks. For example, for a function like: char *foo(); if we attach it with: attach_function :foo, :foo, [], :string We are gonna have a nice memory leak because nobody is gonna release that string. When we call "foo" method in ruby, we get a String object, we cannot (or I don't know how) get the actual char pointer to release it (either from ruby or with another attached function where we pass the pointer and that function calls free, delete o whatever is necessary).The only way to do this currently is to declare the return type as :pointer, read the string yourself, and explicitly free the pointer using the appropriate native method.
Does ruby-ffi not support the :strptr type? It's in the original FFI spec. - Evan
To unsubscribe from this group, send email to ruby-ffi+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
To unsubscribe from this group, send email to ruby-ffi+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.