Skip to content

Commit b674907

Browse files
committed
glib: Manually implement Source::context()
This conditionally uses the safe `dup_context()` with GLib 2.86 and otherwise the racy `get_context()` as before.
1 parent ca905bf commit b674907

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

glib/Gir.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,17 @@ concurrency = "send+sync"
837837
# parameter type
838838
ignore = true
839839

840+
[[object.function]]
841+
name = "dup_context"
842+
# implemented as the normal getter
843+
manual = true
844+
845+
[[object.function]]
846+
name = "get_context"
847+
# implemented conditionally around this or
848+
# dup_context() (see above)
849+
manual = true
850+
840851
[[object]]
841852
name = "GLib.ThreadPool"
842853
status = "manual"

glib/src/source.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,4 +1270,18 @@ impl Source {
12701270
))
12711271
}
12721272
}
1273+
1274+
#[doc(alias = "g_source_get_context")]
1275+
#[doc(alias = "get_context")]
1276+
#[doc(alias = "g_source_dup_context")]
1277+
pub fn context(&self) -> Option<MainContext> {
1278+
#[cfg(feature = "v2_86")]
1279+
unsafe {
1280+
from_glib_full(ffi::g_source_dup_context(self.to_glib_none().0))
1281+
}
1282+
#[cfg(not(feature = "v2_86"))]
1283+
unsafe {
1284+
from_glib_none(ffi::g_source_get_context(self.to_glib_none().0))
1285+
}
1286+
}
12731287
}

0 commit comments

Comments
 (0)