d-unsed / ruru

Native Ruby extensions written in Rust
MIT License
832 stars 40 forks source link

Refactor &str to CString conversions #7

Closed d-unsed closed 8 years ago

d-unsed commented 8 years ago

@steveklabnik, a small clean up for the hacking session #4 😄

Trying to DRY up the CString handling. Similar approach worked fine for Vec -> ptr conversions (1b9932904646741229a683d86a0e7761ab02a41f)

steveklabnik commented 8 years ago

So, I have some concerns this still won't work. I am about to step out, but I will try it on my machine to check.

str_to_cstring(name).as_ptr(),

So, because this ends up being a temporary, I'm not sure if it gets destroyed before the call is over. I can see that it might not, but I can see that it might, as well.

steveklabnik commented 8 years ago

Seems to work fine. :+1:

d-unsed commented 8 years ago

Should work fine, just tested with dummy CString implementation + Drop trait

In this case pointer does not outlive the string unlike the first implementation 😄

steveklabnik commented 8 years ago

Yeah, I just always get a bit suspicious with temporaries :)