On Fri, Jul 9, 2010 at 15:43, Yusuke ENDOH <mame / tsg.ne.jp> wrote:

> 2010/7/9 Nikolai Weibull <now / bitwi.se>:

>> I°«m sorry for being so slow to understand, but I still don°«t see why
>> Ruby can°«t use the char * that I°«ve malloced myself. ?I want to be
>> able to tell Ruby that °…here, take this char *, I own it, no oneelse
>> knows about it, guaranteed, and I°«m now giving it to you for youto
>> own, I don°«t want it anymore°….

> You may want to use rb_str_buf_new instead of malloc.
>
>
> /* allocate buffer whose size is s */
> VALUE str = rb_str_buf_new(s);
>
> /* 'library_call' writes to the buffer */
> library_call(RSTRING_PTR(str), &s);
>
> /* update the length of string */
> rb_str_resize(str, s);
>
> return str;

Yeah.  I would have liked for the API to be that way, but it°«s sadly not.