diff --git a/glib/src/gstring_builder.rs b/glib/src/gstring_builder.rs index 40f6a15d0476..f6a44f9bc4d7 100644 --- a/glib/src/gstring_builder.rs +++ b/glib/src/gstring_builder.rs @@ -29,7 +29,7 @@ wrapper! { let allocated_len = (*src).allocated_len; let inner = ffi::GString { str: ffi::g_malloc(allocated_len) as *mut _, - len: 0, + len: (*src).len, allocated_len, }; // +1 to also copy the NUL-terminator @@ -364,4 +364,17 @@ mod tests { write!(&mut s, "bla bla {} bla", 123).unwrap(); assert_eq!(&*s, "bla bla 123 bla"); } + + #[test] + fn ptr() { + use crate::{ + ffi, + translate::{FromGlibPtrFull, IntoGlibPtr}, + }; + + let s: crate::GStringBuilder = crate::GStringBuilder::new("This is a string."); + let s: *const ffi::GString = s.into_glib_ptr(); + let s = unsafe { crate::GStringBuilder::from_glib_full(s) }; + assert_eq!(&*s, "This is a string."); + } }