Subject: Re: [ruby-ffi] Is there any way we can use string type as return parameter? |
From: Wayne Meissner |
Date: 3/29/10 2:07 PM |
To: ruby-ffi@googlegroups.com |
2010/3/30 Jesús García Sáez <blaxter@gmail.com>:
Hi, 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. 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.