We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db614bb commit a6d1cdfCopy full SHA for a6d1cdf
glib/src/gstring.rs
@@ -249,7 +249,16 @@ impl ToOwned for GStr {
249
250
#[inline]
251
fn to_owned(&self) -> Self::Owned {
252
- GString(Inner::Native(Some(self.as_c_str().to_owned())))
+ let b = self.to_bytes_with_nul();
253
+ let inner = unsafe {
254
+ let copy = ffi::g_malloc(b.len()) as *mut c_char;
255
+ ptr::copy_nonoverlapping(b.as_ptr() as *const c_char, copy, b.len());
256
+ Inner::Foreign {
257
+ ptr: ptr::NonNull::new_unchecked(copy),
258
+ len: b.len() - 1,
259
+ }
260
+ };
261
+ GString(inner)
262
}
263
264
0 commit comments