Main thread panics in the end of while loop

I'm trying to find all words that matching pattern of glib::Regex:

    let re = Regex::new(&regex_key,
        glib::RegexCompileFlags::MULTILINE, glib::RegexMatchFlags::DEFAULT)
        .expect("Can't create Regex").expect("Can't create Regex");
    let g_dict_body = glib::GString::from_string_unchecked(dict_body.into());
    let words = re.match_(g_dict_body.as_gstr(),
        glib::RegexMatchFlags::DEFAULT).expect("Can't get MatchInfo");
    while words.matches(){
        let word = words.fetch(0).expect("Can't get word");
        let (word_start, word_end) = 
            words.fetch_pos(0).expect("Can't get word start and end.");
        println!("word: {}, word start: {}, word end: {}",
            word, word_start, word_end);
        let _ = words.next();
    }

But in the end of the loop it panics:

thread 'main' panicked at /.cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.19.6/src/match_info.rs:335:13:
assertion left == right failed
left: true
right: false
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

How to fix that?

run with RUST_BACKTRACE=1 environment variable to display a backtrace

The line: match_info.rs - source

pub fn next(&self) -> Result<(), crate::Error> {
    unsafe {
        let mut error = std::ptr::null_mut();
        let is_ok = ffi::g_match_info_next(self.to_glib_none().0, &mut error);
        debug_assert_eq!(is_ok == crate::ffi::GFALSE, !error.is_null());
        if error.is_null() {
            Ok(())
        } else {
            Err(from_glib_full(error))
        }
    }
}

So is_ok is GFALSE and error is null.

I would guess this means that glib has done something that the author of the rust bindings didn't know could happen. You should probably make a reproduction and post an issue to their repository.

1 Like

I've created bug report at their page gtk4 Github issue report

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.