Hi,

2010/7/9 Nikolai Weibull <now / bitwi.se>:
> I=92m sorry for being so slow to understand, but I still don=92t see why
> Ruby can=92t use the char * that I=92ve malloced myself. ?I want to be
> able to tell Ruby that =94here, take this char *, I own it, no one else
> knows about it, guaranteed, and I=92m now giving it to you for you to
> own, I don=92t want it anymore=94.


You may want to use rb_str_buf_new instead of malloc.


  /* allocate buffer whose size is s */
  VALUE str =3D 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;


Be careful not to allow GC to occur within 'library_call'.
GC may shrink the buffer.

--=20
Yusuke Endoh <mame / tsg.ne.jp>