jeremyletang / rgtk

GTK+ bindings and wrappers for Rust (DEPRECATED SEE https://github.com/rust-gnome )
GNU Lesser General Public License v3.0
120 stars 22 forks source link

Fix invalid c arrays #224

Closed GuillaumeGomez closed 9 years ago

gkoz commented 9 years ago

That code is still wrong though, it makes a vector of dangling pointers. I'm hoping to make a generic glib::translate implementation that would handle this along with other cases of passing arrays back and forth.

GuillaumeGomez commented 9 years ago

I don't follow you. In which way is it wrong ? It does need a NULL terminated array, that's what I'm providing.

gkoz commented 9 years ago

What's wrong in this picture?

    for tmp in authors.iter() {
        let c_str = CString::from_slice(tmp.as_bytes());
        tmp_vec.push(c_str.as_ptr());
    }

Every iteration makes a CString, puts a pointer into tmp_vec and the CString is then immediately destroyed.

GuillaumeGomez commented 9 years ago

Oh right ! Hum... That's annoying.

gkoz commented 9 years ago

I plan to deal with vectors after finishing singular conversions in #220

GuillaumeGomez commented 9 years ago

If you have something in mind, it's perfect then. A centralized solution is really missing for this kind of stuff.