@@ -46,20 +46,21 @@ impl UnixSocketAddress {
46
46
use self :: UnixSocketAddressPath :: * ;
47
47
48
48
let type_ = address_type. to_type ( ) ;
49
- let ( path, len) = match address_type {
50
- Path ( path) => ( path. to_glib_none ( ) . 0 , path. as_os_str ( ) . len ( ) ) ,
51
- Abstract ( path) | AbstractPadded ( path) => {
52
- ( path. to_glib_none ( ) . 0 as * mut libc:: c_char , path. len ( ) )
53
- }
54
- Anonymous => ( ptr:: null_mut ( ) , 0 ) ,
55
- } ;
56
- unsafe {
49
+ let new = |ptr, len| unsafe {
57
50
SocketAddress :: from_glib_full ( ffi:: g_unix_socket_address_new_with_type (
58
- path ,
59
- len as i32 ,
51
+ ptr ,
52
+ len,
60
53
type_. into_glib ( ) ,
61
54
) )
62
55
. unsafe_cast ( )
56
+ } ;
57
+ match address_type {
58
+ Path ( path) => new ( path. to_glib_none ( ) . 0 , -1 ) ,
59
+ Abstract ( path) | AbstractPadded ( path) => new (
60
+ path. to_glib_none ( ) . 0 as * mut libc:: c_char ,
61
+ path. len ( ) as i32 ,
62
+ ) ,
63
+ Anonymous => new ( ptr:: null_mut ( ) , 0 ) ,
63
64
}
64
65
}
65
66
}
@@ -97,3 +98,24 @@ pub trait UnixSocketAddressExtManual: sealed::Sealed + IsA<UnixSocketAddress> +
97
98
}
98
99
99
100
impl < O : IsA < UnixSocketAddress > > UnixSocketAddressExtManual for O { }
101
+
102
+ #[ cfg( test) ]
103
+ mod test {
104
+ use super :: * ;
105
+
106
+ // Check the actual path and len are correct and are not the underlying OsString
107
+ #[ test]
108
+ fn check_path ( ) {
109
+ let mut os_string = std:: ffi:: OsString :: with_capacity ( 100 ) ;
110
+ os_string. push ( "/tmp/foo" ) ;
111
+ let path = os_string. as_ref ( ) ;
112
+
113
+ let addr = UnixSocketAddress :: new ( path) ;
114
+ assert_eq ! ( addr. path_len( ) , 8 ) ;
115
+ assert_eq ! ( addr. path_as_array( ) . unwrap( ) . as_ref( ) , b"/tmp/foo" ) ;
116
+
117
+ let addr = UnixSocketAddress :: with_type ( UnixSocketAddressPath :: Path ( path) ) ;
118
+ assert_eq ! ( addr. path_len( ) , 8 ) ;
119
+ assert_eq ! ( addr. path_as_array( ) . unwrap( ) . as_ref( ) , b"/tmp/foo" ) ;
120
+ }
121
+ }
0 commit comments