diff --git a/gio/src/unix_socket_address.rs b/gio/src/unix_socket_address.rs index 44f85315d260..e126d9398d23 100644 --- a/gio/src/unix_socket_address.rs +++ b/gio/src/unix_socket_address.rs @@ -47,16 +47,26 @@ impl UnixSocketAddress { let type_ = address_type.to_type(); let (path, len) = match address_type { - Path(path) => (path.to_glib_none().0, path.as_os_str().len()), - Abstract(path) | AbstractPadded(path) => { - (path.to_glib_none().0 as *mut libc::c_char, path.len()) + Path(path) => { + unsafe { + let p = std::ffi::CStr::from_ptr(path.to_glib_none().0); + panic!("{address_type:?} {p:?}"); + } + (path.to_glib_none().0, -1) } + Abstract(path) | AbstractPadded(path) => ( + path.to_glib_none().0 as *mut libc::c_char, + path.len() as i32, + ), Anonymous => (ptr::null_mut(), 0), }; unsafe { + let p = std::ffi::CStr::from_ptr(path); + panic!("{address_type:?} {p:?} {len}"); + SocketAddress::from_glib_full(ffi::g_unix_socket_address_new_with_type( path, - len as i32, + len, type_.into_glib(), )) .unsafe_cast() @@ -97,3 +107,24 @@ pub trait UnixSocketAddressExtManual: sealed::Sealed + IsA + } impl> UnixSocketAddressExtManual for O {} + +#[cfg(test)] +mod test { + use super::*; + + // Check the actual path and len are correct and are not the underlying OsString + #[test] + fn check_path() { + let mut os_string = std::ffi::OsString::with_capacity(100); + os_string.push("/tmp/foo"); + let path = os_string.as_ref(); + + let addr = UnixSocketAddress::new(path); + assert_eq!(addr.path_len(), 8); + assert_eq!(addr.path_as_array().unwrap().as_ref(), b"/tmp/foo"); + + let addr = UnixSocketAddress::with_type(UnixSocketAddressPath::Path(path)); + assert_eq!(addr.path_len(), 8); + assert_eq!(addr.path_as_array().unwrap().as_ref(), b"/tmp/foo"); + } +} diff --git a/gir b/gir index 133ee1d93c85..2fd6d4c4162c 160000 --- a/gir +++ b/gir @@ -1 +1 @@ -Subproject commit 133ee1d93c859065c44af77223b4bcfea3137738 +Subproject commit 2fd6d4c4162c22488a3f7023027bb6581e906bfb diff --git a/gir-files b/gir-files index 326eb5f2d5d8..318e14efee40 160000 --- a/gir-files +++ b/gir-files @@ -1 +1 @@ -Subproject commit 326eb5f2d5d852bb5b1eb436a2b856e338ef910d +Subproject commit 318e14efee40a863b13e4dda983a41f179d9daf3