>You may be interested in collaborating with pcwalton, who also has some GLUT >bindings: https://github.com/pcwalton/rust-glut
Thanks! I'll take a look at it. 2012/6/19 Graydon Hoare <[email protected]>: > On 12-06-18 11:12 AM, Brian Anderson wrote: > >> It is ok, as long as you make sure that you hold the reference to my_str >> for at least as long as my_cstr (as_c_str is simply passing a pointer >> into the Rust string). > > > This is only true by accident now and is going to stop being true when we > move to slices. In particular, a slice that points into a non-terminal > substring will be copied into a temp buffer and null terminated before > passing back to such a closure for use in C. So then it's _really_ garbage > memory after the closure returns. > > Generally: copy the string out if you want it to survive after the closure. Is there any good datatype to copy out and keep the c-string? Of course str is useless in this case, and it seems [c_char] has same problem. (vec::as_buf's signature is as_buf<E, T>(v: [const E], f: fn(*E) -> T) -> T, I may not allowed to return *E from the closure) So I think I should use libc::malloc/memcpy/free and std::c_vec to make sure the c-string survive. Is this right? _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
