Closed steveklabnik closed 8 years ago
Hey @steveklabnik! Yeah that was a cool hacking session 😄
I think one way to improve the solution is to move CString::new(name).unwrap()
(without as_ptr()
call) back to util
module, for example
pub fn str_to_cstring(str: &str) -> CString {
// moves an ownership of CString to the caller
CString::new(name).unwrap()
}
// ... caller of str_as_cstring()
unsafe {
rb_define_class(
// CString must be still alive here
str_to_cstring(class_name).as_ptr(),
superclass
)
}
This may help to keep the code DRY and to avoid duplications of manual CString
handling across the project. I will continue investigating it 🔍
Thanks for contribution!
It was fun hacking on this with you in Vilnius!