Backport official GLib iterator safety fix for Linux desktop

This commit is contained in:
karl committed 2026-10-13 10:35:50 +02:00
1 parent 43c43ebdc9
commit 8ef874c609
133 files changed
+55342 -2

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
use std::ops::Deref;
use glib::*;
// FIXME all .get::<i32>() should be replaced with .get(); the compiler is totally able to infer the type itself.
// But somehow without some tests are failing on Windows because the type inference doesn't work or something.
// Test that `ToValue` (and conversely, `FromValue`) uphold the promised invariants
#[test]
pub fn to_value_invariants() {
// Inverse
assert_eq!(0i32, 0i32.to_value().get::<i32>().unwrap());
assert_eq!(0i32, 0i32.to_value().get::<i32>().unwrap());
// Idempotence
assert_eq!(
&0i32.to_value().type_(),
&0i32.to_value().to_value().type_()
);
assert_eq!(0i32, 0i32.to_value().to_value().get::<i32>().unwrap());
assert_eq!(
0i32,
0i32.to_value()
.get::<Value>()
.unwrap()
.get::<i32>()
.unwrap()
);
assert_eq!(
0i32,
0i32.to_value()
.get::<Value>()
.unwrap()
.get::<i32>()
.unwrap()
);
}
// Test that `ToValue` and `FromValue` handle nexted boxed values correctly (as per the documentation)
#[test]
pub fn to_value_boxed() {
let x = 0i32.to_value();
let boxed = BoxedValue(x);
assert_eq!(
0i32,
boxed
.to_value()
.to_value()
.get::<BoxedValue>()
.unwrap()
.deref()
.get::<i32>()
.unwrap()
);
assert_eq!(
0i32,
boxed
.to_value()
.get::<Value>()
.unwrap()
.get::<BoxedValue>()
.unwrap()
.deref()
.get::<i32>()
.unwrap()
);
}