@@ -87,6 +87,16 @@ impl ListStore {
87
87
}
88
88
89
89
unsafe {
90
+ // GIO requires a non-NULL item to be passed in so we're constructing a fake item here.
91
+ // See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3284
92
+ let item = glib:: gobject_ffi:: GObject {
93
+ g_type_instance : glib:: gobject_ffi:: GTypeInstance {
94
+ g_class : glib:: gobject_ffi:: g_type_class_peek ( self . item_type ( ) . into_glib ( ) )
95
+ as * mut _ ,
96
+ } ,
97
+ ref_count : 1 ,
98
+ qdata : std:: ptr:: null_mut ( ) ,
99
+ } ;
90
100
let mut func = equal_func;
91
101
let func_obj: & mut ( dyn FnMut ( & Object ) -> bool ) = & mut func;
92
102
let func_ptr =
@@ -96,7 +106,7 @@ impl ListStore {
96
106
97
107
let found = bool:: from_glib ( ffi:: g_list_store_find_with_equal_func_full (
98
108
self . to_glib_none ( ) . 0 ,
99
- std :: ptr :: null_mut ( ) ,
109
+ mut_override ( & item as * const _ ) ,
100
110
Some ( equal_func_trampoline) ,
101
111
func_ptr,
102
112
position. as_mut_ptr ( ) ,
@@ -190,4 +200,17 @@ mod tests {
190
200
assert_eq ! ( list. item( 1 ) . as_ref( ) , Some ( item1. upcast_ref( ) ) ) ;
191
201
assert_eq ! ( list. item( 2 ) . as_ref( ) , None ) ;
192
202
}
203
+
204
+ #[ cfg( feature = "v2_74" ) ]
205
+ #[ test]
206
+ fn find ( ) {
207
+ let item0 = ListStore :: new ( ListStore :: static_type ( ) ) ;
208
+ let item1 = ListStore :: new ( ListStore :: static_type ( ) ) ;
209
+ let list = ListStore :: new ( ListStore :: static_type ( ) ) ;
210
+ list. append ( & item0) ;
211
+ list. append ( & item1) ;
212
+
213
+ let res = list. find_with_equal_func ( |item| item == & item1) ;
214
+ assert_eq ! ( res, Some ( 1 ) ) ;
215
+ }
193
216
}
0 commit comments