On Fri, Jul 9, 2010 at 15:12, Urabe Shyouhei <shyouhei / ruby-lang.org> wrote:

> No, sorry Ruby can't trust you. Not even myself. When a machine can trust a
> human, there is absolutely zero reason for a GC to exist. Ruby GC'sbase line
> is that C Strings are owned by Ruby Strings, and that line should not be
> broken just because you are sure by a heuristic approach.

So basically there is no way to wrap, for example,

http://library.gnome.org/devel/gio/stable/GFile.html#g-file-load-contents

efficiently.  I¡Çll always have to copy the loaded contents into a new
Ruby String and then free the returned char * contents.

(Unless I write a utility method like

VALUE
cstr_to_rval_own(char *string, gsize length)
{
        NEWOBJ(str, struct RString);
        OBJSETUP(str, rb_cString, T_STRING);

        str->ptr = string;
        str->len = length;
        str->aux.capa = length;

        return (VALUE)str;
}

(which needs a separate 1.9.* implementation, as aux doesn¡Çt exist as
such anymore.))