@@ -2415,16 +2415,17 @@ impl ToValue for Vec<GString> {
2415
2415
2416
2416
impl From < Vec < GString > > for Value {
2417
2417
#[ inline]
2418
- fn from ( mut v : Vec < GString > ) -> Self {
2418
+ fn from ( v : Vec < GString > ) -> Self {
2419
2419
unsafe {
2420
+ let v_ptr =
2421
+ ffi:: g_malloc ( mem:: size_of :: < * mut c_char > ( ) * ( v. len ( ) + 1 ) ) as * mut * mut c_char ;
2422
+ v_ptr. add ( v. len ( ) ) . write ( ptr:: null_mut ( ) ) ;
2423
+ for ( i, s) in v. into_iter ( ) . enumerate ( ) {
2424
+ v_ptr. add ( i) . write ( s. into_glib_ptr ( ) ) ;
2425
+ }
2426
+
2420
2427
let mut value = Value :: for_value_type :: < Vec < GString > > ( ) ;
2421
- let container =
2422
- ToGlibContainerFromSlice :: < * mut * mut c_char > :: to_glib_container_from_slice ( & v) ;
2423
- gobject_ffi:: g_value_take_boxed (
2424
- value. to_glib_none_mut ( ) . 0 ,
2425
- container. 0 as * const c_void ,
2426
- ) ;
2427
- v. set_len ( 0 ) ;
2428
+ gobject_ffi:: g_value_take_boxed ( value. to_glib_none_mut ( ) . 0 , v_ptr as * const c_void ) ;
2428
2429
value
2429
2430
}
2430
2431
}
@@ -2598,6 +2599,21 @@ mod tests {
2598
2599
assert_eq ! ( s. as_str( ) , "foo" ) ;
2599
2600
}
2600
2601
2602
+ #[ test]
2603
+ fn test_value_from_vec_gstring ( ) {
2604
+ fn roundtrip ( s : GString ) {
2605
+ let vec = vec ! [ s. clone( ) ] ;
2606
+ let value = crate :: Value :: from ( vec) ;
2607
+ let vec: Vec < GString > = value. get ( ) . unwrap ( ) ;
2608
+ assert_eq ! ( vec. len( ) , 1 ) ;
2609
+ assert_eq ! ( s, vec[ 0 ] ) ;
2610
+ }
2611
+
2612
+ roundtrip ( GString :: from ( "foo" ) ) ;
2613
+ roundtrip ( GString :: from ( "very very very long string" . to_owned ( ) ) ) ;
2614
+ roundtrip ( GString :: from ( gstr ! ( "very very very long string" ) ) ) ;
2615
+ }
2616
+
2601
2617
#[ test]
2602
2618
fn test_as_ref_path ( ) {
2603
2619
fn foo < P : AsRef < Path > > ( _path : P ) { }
0 commit comments